Index: oup/current/Tools/Preview.pas
===================================================================
--- oup/current/Tools/Preview.pas	(revision 180)
+++ oup/current/Tools/Preview.pas	(revision 192)
@@ -30,5 +30,5 @@
     procedure LoadImage(fileid, index: Integer);
   private
-    bitmaps:   array of TBitmap;
+    bitmaps:   array of TOniImage;
     actualimg: Byte;
     _fileid:   Integer;
@@ -41,4 +41,5 @@
 implementation
 {$R *.dfm}
+uses Imaging, ImagingComponents, ImagingTypes;
 
 
@@ -83,15 +84,6 @@
 
 procedure TForm_Preview.LoadImage(fileid, index: Integer);
-var
-  memstream: TMemoryStream;
-  OniImage:  TOniImage;
-begin
-  OniImage := TOniImage.Create;
-  OniImage.Load(ConnectionID, fileid);
-  memstream := TMemoryStream.Create;
-  OniImage.GetAsBMP(TStream(memstream));
-  OniImage.Free;
-  bitmaps[index].LoadFromStream(memstream);
-  memstream.Free;
+begin
+  bitmaps[index].Load(ConnectionID, fileid);
 end;
 
@@ -99,9 +91,5 @@
 procedure TForm_Preview.DrawImage(index: Integer);
 begin
-  BitBlt(img.Canvas.Handle, 0, 0, img.Width, img.Height,
-    bitmaps[index].Canvas.Handle, 0, 0, WHITENESS);
-  BitBlt(img.Canvas.Handle, 0, 0, bitmaps[index].Width, bitmaps[index].Height,
-    bitmaps[index].Canvas.Handle, 0, 0, SRCCOPY);
-  img.Invalidate;
+  bitmaps[index].DrawOnCanvas(img.Canvas, 0);
 end;
 
@@ -122,5 +110,5 @@
     SetLength(bitmaps, Count);
     for i := i to High(bitmaps) do
-      bitmaps[i] := TBitmap.Create;
+      bitmaps[i] := TOniImage.Create;
   end;
 end;
Index: oup/current/Tools/TxmpReplace.dfm
===================================================================
--- oup/current/Tools/TxmpReplace.dfm	(revision 180)
+++ oup/current/Tools/TxmpReplace.dfm	(revision 192)
@@ -147,5 +147,4 @@
   end
   object opend: TOpenDialog [4]
-    Filter = '24bit Bitmap (*.bmp)|*.bmp'
     Options = [ofPathMustExist, ofFileMustExist, ofEnableSizing]
     Left = 352
@@ -154,5 +153,8 @@
   object saved: TSaveDialog [5]
     DefaultExt = 'bmp'
-    Filter = 'Windows Bitmap (*.bmp)|*.bmp'
+    Filter = 
+      'All supported files (*.bmp, *.dds)|*.bmp;*.dds|Windows Bitmap (*' +
+      '.bmp)|*.bmp|DirectDraw Surface (*.dds)|*.dds|Targa (*.tga)|*.tga' +
+      '|JPEG (*.jpg, *.jpeg)|*.jpg;*.jpeg|All files (*.*)|*'
     Options = [ofOverwritePrompt, ofHideReadOnly, ofPathMustExist, ofEnableSizing]
     Left = 104
Index: oup/current/Tools/TxmpReplace.pas
===================================================================
--- oup/current/Tools/TxmpReplace.pas	(revision 180)
+++ oup/current/Tools/TxmpReplace.pas	(revision 192)
@@ -41,5 +41,5 @@
 implementation
 {$R *.dfm}
-uses Main, ConnectionManager;
+uses Main, ConnectionManager, ImagingTypes;
 
 
@@ -54,14 +54,12 @@
   ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
   ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
-  check_fading.Checked := (fadingbyte and $01) > 0;
-  check_transparency.Checked := (depthbyte and $04) > 0;
 
   OniImage_Old.LoadFromTXMP(ConnectionID, fileid);
-  old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0);
-  mem  := TMemoryStream.Create;
-  OniImage_Old.GetAsBMP(TStream(mem));
-  mem.Seek(0, soFromBeginning);
-  image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
-  mem.Free;
+  old_size := OniImage_Old.GetImageSize(True);
+  OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 0);
+
+  check_fading.Checked := OniImage_Old.HasMipMaps;
+//  check_transparency.Checked := (depthbyte and $04) > 0;
+  check_transparency.Checked := storebyte in [0, 2, 7];
 
   group_bmpselect.Enabled := True;
@@ -75,10 +73,6 @@
   if opend.Execute then
   begin
-    OniImage_New.LoadFromBMP(opend.FileName);
-    mem   := TMemoryStream.Create;
-    OniImage_New.GetAsBMP(TStream(mem));
-    mem.Seek(0, soFromBeginning);
-    image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
-    mem.Free;
+    OniImage_New.LoadFromFile(opend.FileName);
+    OniImage_New.DrawOnCanvas(image_bmppreview.Canvas, 0);
     group_options.Enabled := True;
   end;
@@ -104,13 +98,14 @@
       ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
 
-    if (OniImage_Old.Width <> OniImage_New.Width) or
-      (OniImage_Old.Height <> OniImage_New.Height) then
+    if (OniImage_Old.Width[1] <> OniImage_New.Width[1]) or
+      (OniImage_Old.Height[1] <> OniImage_New.Height[1]) then
     begin
       if MessageBox(Self.Handle,
             PChar(
               'Current image and new image have different size' + CrLf +
-              '(Current: ' + IntToStr(OniImage_Old.Width) + 'x' +
-              IntToStr(OniImage_Old.Height) + ' - New: ' +
-              IntToStr(OniImage_New.Width) + 'x' + IntToStr(OniImage_New.Height) +
+              '(Current: ' + IntToStr(OniImage_Old.Width[1]) + 'x' +
+              IntToStr(OniImage_Old.Height[1]) + ' - New: ' +
+              IntToStr(OniImage_New.Width[1]) + 'x' +
+              IntToStr(OniImage_New.Height[1]) +
               ')' + CrLf + 'Replace anyway?'),
             PChar(filelist.Items.Strings[filelist.ItemIndex]), MB_YESNO) = idNo then
@@ -120,25 +115,13 @@
     mem := TMemoryStream.Create;
 
-    if check_fading.Checked then
-      if not OniImage_New.GetMipMappedImage(TStream(mem)) then
-        if MessageBox(Self.Handle,
-              PChar('Can not create a MipMapped-image (probably because of a wrong dimension).' +
-                #13 + #10 + 'Do you want to continue without MipMapping?'), PChar('Warning'),
-                MB_YESNO) = ID_YES then
-          check_fading.Checked := False
-        else
-          Exit;
-
-    if not check_fading.Checked then
-    begin
-      mem.Clear;
-      OniImage_New.GetAsData(TStream(mem));
-    end;
-
-    newsize := OniImage_New.GetImageDataSize(check_fading.Checked);
+    OniImage_New.SaveDataToStream(check_fading.Checked, TStream(mem));
+
+    newsize := mem.Size;
+    mem.Seek(0, soFromBeginning);
 
     if (newsize > old_size) and (ConManager.Connection[ConnectionID].Backend = DB_ONI) then
       new_rawaddr := ConManager.Connection[ConnectionID].AppendRawFile(
-        not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN), mem.Size, mem)
+        not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN),
+        mem.Size, mem)
     else
     begin
@@ -152,10 +135,25 @@
     ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte);
     datbyte := $10;
-    if check_transparency.Checked then
-      datbyte := datbyte or $04;
+//    if check_transparency.Checked then
+//      datbyte := datbyte or $04;
     ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $89, 1, @datbyte);
-    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width);
-    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height);
-    datbyte := $08;
+    datbyte := OniImage_New.Width[1];
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @datbyte);
+    datbyte := OniImage_New.Height[1];
+    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @datbyte);
+    case OniImage_New.Format of
+      ifA1R5G5B5: datbyte := 2;
+      ifA4R4G4B4: datbyte := 0;
+      ifA8R8G8B8:
+        begin
+          datbyte := 8;
+          OniImage_New.Format := ifX8R8G8B8;
+        end;
+      ifX8R8G8B8: datbyte := 8;
+      ifDXT1: datbyte := 9;
+    else
+      OniImage_New.Format := ifX8R8G8B8;
+      datbyte := 8;
+    end;
     ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @datbyte);
     if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
@@ -188,4 +186,5 @@
   Self.AllowedExts := 'TXMP';
   Self.OnNewFileSelected := SelectFile;
+  opend.Filter := saved.Filter;
 end;
 
@@ -196,5 +195,5 @@
 begin
   if saved.Execute then
-    OniImage_Old.WriteToBMP(saved.FileName);
+    OniImage_Old.WriteToFile(saved.FileName);
 end;
 
