--- oup/rewrite/Tools/TxmpReplace.pas 2007/01/22 23:05:45 97 +++ oup/current/Tools/TxmpReplace.pas 2007/02/21 03:12:33 109 @@ -46,22 +46,20 @@ uses Main, ConnectionManager; procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo); var - Data: TByteData; mem: TMemoryStream; fadingbyte, depthbyte, storebyte: Byte; begin fileid := fileinfo.ID; - Connection.LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte); - Connection.LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte); - Connection.LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte); + ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte); + 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(connection, fileid); + OniImage_Old.LoadFromTXMP(ConnectionID, fileid); old_size := OniImage_Old.GetImageDataSize((fadingbyte and $01) > 0); - Data := OniImage_Old.GetAsBMP; mem := TMemoryStream.Create; - mem.Write(Data[0], Length(Data)); + OniImage_Old.GetAsBMP(TStream(mem)); mem.Seek(0, soFromBeginning); image_txmppreview.Picture.Bitmap.LoadFromStream(mem); mem.Free; @@ -73,14 +71,12 @@ end; procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject); var mem: TMemoryStream; - tempd: Tdata; begin if opend.Execute then begin OniImage_New.LoadFromBMP(opend.FileName); - tempd := OniImage_New.GetAsBMP; mem := TMemoryStream.Create; - mem.Write(tempd[0], Length(tempd)); + OniImage_New.GetAsBMP(TStream(mem)); mem.Seek(0, soFromBeginning); image_bmppreview.Picture.Bitmap.LoadFromStream(mem); mem.Free; @@ -96,72 +92,76 @@ var newsize: LongWord; old_rawaddr, new_rawaddr: LongWord; oldfading: Byte; - tempd: Tdata; - datbyte: Word; + mem: TMemoryStream; begin if filelist.ItemIndex >= 0 then begin - Connection.LoadDatFilePart(fileid, $88, 1, @oldfading); - if Connection.OSisMac then - Connection.UpdateDatFilePart(fileid, $A0, 4, @old_rawaddr) + ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, 1, @oldfading); + if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then + ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, 4, @old_rawaddr) else - Connection.LoadDatFilePart(fileid, $9C, 4, @old_rawaddr); + ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @old_rawaddr); if (OniImage_Old.Width <> OniImage_New.Width) or (OniImage_Old.Height <> OniImage_New.Height) 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) + ')' + CrLf + - 'Replace anyways?'), - PChar(filelist.Items.Strings[filelist.ItemIndex]), - MB_YESNO) = idNo then + 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) + + ')' + CrLf + 'Replace anyway?'), + PChar(filelist.Items.Strings[filelist.ItemIndex]), MB_YESNO) = idNo then Exit; end; + mem := TMemoryStream.Create; + if check_fading.Checked then - if not OniImage_New.GetMipMappedImage(tempd) 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 + 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 - tempd := OniImage_New.GetAsData; + begin + mem.Clear; + OniImage_New.GetAsData(TStream(mem)); + end; newsize := OniImage_New.GetImageDataSize(check_fading.Checked); - if (newsize > old_size) and (Connection.Backend = ODB_Dat) then - new_rawaddr := Connection.AppendRawFile( - Connection.OSisMac, Length(tempd), tempd) + 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) else begin new_rawaddr := old_rawaddr; - Connection.UpdateRawFile(fileid, $9C, Length(tempd), tempd); + ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem); end; datbyte := $00; if check_fading.Checked then datbyte := datbyte or $01; - Connection.UpdateDatFilePart(fileid, $88, 1, @datbyte); + ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte); datbyte := $10; if check_transparency.Checked then datbyte := datbyte or $04; - Connection.UpdateDatFilePart(fileid, $89, 1, @datbyte); - Connection.UpdateDatFilePart(fileid, $8C, 2, @OniImage_New.Width); - Connection.UpdateDatFilePart(fileid, $8E, 2, @OniImage_New.Height); + 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; - Connection.UpdateDatFilePart(fileid, $90, 1, @datbyte); - if Connection.OSisMac then - Connection.UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr) + ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @datbyte); + if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then + ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr) else - Connection.UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr); + ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr); ShowMessage('TXMP-image replaced'); end;