Index: /oup/current/Global/OniImgClass.pas
===================================================================
--- /oup/current/Global/OniImgClass.pas	(revision 198)
+++ /oup/current/Global/OniImgClass.pas	(revision 199)
@@ -184,5 +184,5 @@
 const
   PartMatch: array[0..8] of Byte = (0, 3, 6, 1, 4, 7, 2, 5, 8);
-  stretch_x: Integer = 50;
+  stretch_x: Integer = 1;
   stretch_y: Integer = 1;
 var
@@ -228,6 +228,6 @@
       if (p2[i].X > 0) or (p2[i].Y > 0) then
       begin
-        parts[part].x_txmp := p1[i].X - 1;
-        parts[part].y_txmp := p1[i].Y - 1;
+        parts[part].x_txmp := p1[i].X;// - 1;
+        parts[part].y_txmp := p1[i].Y;// - 1;
         parts[part].x_pspc := 0;
         if col > 0 then
@@ -238,6 +238,6 @@
           for y := 0 to row - 1 do
             Inc(parts[part].y_pspc, rows[y]);
-        parts[part].w := p2[i].X - p1[i].X + 1;
-        parts[part].h := p2[i].Y - p1[i].Y + 1;
+        parts[part].w := Max(p2[i].X - p1[i].X, 1);// + 1;
+        parts[part].h := Max(p2[i].Y - p1[i].Y, 1);// + 1;
         parts[part].used := True;
         cols[col] := parts[part].w;
@@ -279,27 +279,33 @@
     begin
       part := row*3 + col;
-      if (row = 1) and (col = 1) then
-        StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
-            FImages[0], x, y, parts[part].w * stretch_x, parts[part].h * stretch_y, rfNearest)
+      if parts[part].used then
+      begin
+        if (row = 1) and (col = 1) then
+          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
+              FImages[0], x, y, parts[part].w * stretch_x, parts[part].h * stretch_y, rfNearest)
+        else
+        if (row = 1) then
+          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
+              FImages[0], x, y, parts[part].w, parts[part].h * stretch_y, rfNearest)
+        else
+        if (col = 1) then
+          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
+              FImages[0], x, y, parts[part].w * stretch_x, parts[part].h, rfNearest)
+        else
+          CopyRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
+              FImages[0], x, y );
+        if row = 1 then
+          y := y + parts[part].h * stretch_y
+        else
+          y := y + parts[part].h;
+      end;
+    end;
+    if cols[col] > 0 then
+    begin
+      if (col = 1) then
+        x := x + parts[part].w * stretch_x
       else
-      if (row = 1) then
-        StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
-            FImages[0], x, y, parts[part].w, parts[part].h * stretch_y, rfNearest)
-      else
-      if (col = 1) then
-        StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
-            FImages[0], x, y, parts[part].w * stretch_x, parts[part].h, rfNearest)
-      else
-        CopyRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
-            FImages[0], x, y );
-      if row = 1 then
-        y := y + parts[part].h * stretch_y
-      else
-        y := y + parts[part].h;
-    end;
-    if (part mod 3) = 1 then
-      x := x + parts[part].w * stretch_x
-    else
-      x := x + parts[part].w;
+        x := x + parts[part].w;
+    end;
   end;
 
Index: /oup/current/Tools/TxmpReplace.pas
===================================================================
--- /oup/current/Tools/TxmpReplace.pas	(revision 198)
+++ /oup/current/Tools/TxmpReplace.pas	(revision 199)
@@ -130,4 +130,5 @@
 
     case OniImage_New.Format of
+      ifX1R5G5B5: new_storetype := 1;
       ifA1R5G5B5: new_storetype := 2;
       ifA4R4G4B4: new_storetype := 0;
