Index: oup/current/Global/OniImgClass.pas
===================================================================
--- oup/current/Global/OniImgClass.pas	(revision 127)
+++ oup/current/Global/OniImgClass.pas	(revision 128)
@@ -589,41 +589,30 @@
   size: Integer;
   x, y: Word;
-  bpp:  Byte;
-  minside: Byte;
-begin
-  minside := 1;
-  case Self.FStoreType of
-    9:
-    begin
-      bpp := 4;
-      minside := 4;
-    end;
-    0, 1, 2:
-      bpp := 16;
-    8:
-      bpp := 32;
+
+  function GetImgSize(w,h, storetype: Integer): Integer;
+  begin
+    case storetype of
+      0, 1, 2:
+        Result := w*h*2;
+      8:
+        Result := w*h*4;
+      9:
+        Result :=  Max(1, w div 4) * Max(1, h div 4) * 8;
     else
-      Result := 0;
-      Exit;
-  end;
-
+      Result := -1;
+    end;
+  end;
+
+begin
   x    := Self.FWidth;
   y    := Self.FHeight;
-  size := (x * y * bpp) div 8;
+  size := GetImgSize(x, y, FStoreType);
   if fading then
   begin
     repeat
-      x    := x div 2;
-      y    := y div 2;
-      size := size + (x * y * bpp) div 8;
-    until (x = minside) or (y = minside);
-    if FStoreType = 9 then
-    begin
-      repeat
-        x    := x div 2;
-        y    := y div 2;
-        size := size + (x * y * 16) div 8;
-      until (x = 1) or (y = 1);
-    end;
+      x    := Max(x div 2, 1);
+      y    := Max(y div 2, 1);
+      size := size + GetImgSize(x, y, FStoreType);
+    until (x = 1) and (y = 1);
   end;
   Result := size;
Index: oup/current/Global/RawList.pas
===================================================================
--- oup/current/Global/RawList.pas	(revision 127)
+++ oup/current/Global/RawList.pas	(revision 128)
@@ -30,5 +30,5 @@
 
 uses
-  Template, ConnectionManager, Access_OniArchive, Classes, SysUtils;
+  Template, ConnectionManager, Access_OniArchive, Classes, SysUtils, Math;
 
 
@@ -313,6 +313,19 @@
   datasize:  Integer;
   mipmap:    Byte;
-  bpp:       Byte;
-  minside:   Byte;
+
+  function GetImgSize(w,h, storetype: Integer): Integer;
+  begin
+    case storetype of
+      0, 1, 2:
+        Result := w*h*2;
+      8:
+        Result := w*h*4;
+      9:
+        Result :=  Max(1, w div 4) * Max(1, h div 4) * 8;
+    else
+      Result := -1;
+    end;
+  end;
+
 begin
   ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(mipmap), @mipmap);
@@ -324,33 +337,12 @@
 
 
-  minside := 1;
-  case storetype of
-    0, 1, 2:
-      bpp := 16;
-    8:
-      bpp := 32;
-    9:
-    begin
-      bpp := 4;
-      minside := 4;
-    end;
-  end;
-
-  datasize := (x * y * bpp) div 8;
+  datasize := GetImgSize(x, y, storetype);
   if (mipmap and $01) > 0 then
   begin
     repeat
-      x    := x div 2;
-      y    := y div 2;
-      datasize := datasize + (x * y * bpp) div 8;
-    until (x = minside) or (y = minside);
-    if storetype = 9 then
-    begin
-      repeat
-        x    := x div 2;
-        y    := y div 2;
-        datasize := datasize + (x * y * 16) div 8;
-      until (x = 1) or (y = 1);
-    end;
+      x    := Max(x div 2, 1);
+      y    := Max(y div 2, 1);
+      datasize := datasize + GetImgSize(x, y, storetype);
+    until (x = 1) and (y = 1);
   end;
 
