--- oup/current/Tools/TxmpReplace.pas 2007/05/26 14:24:55 193 +++ oup/current/Tools/TxmpReplace.pas 2007/05/27 20:03:41 204 @@ -27,6 +27,7 @@ type procedure btn_saveClick(Sender: TObject); procedure btn_loadClick(Sender: TObject); procedure btn_replaceClick(Sender: TObject); + procedure Splitter1Moved(Sender: TObject); private OniImage_Old: TOniImage; OniImage_New: TOniImage; @@ -46,7 +47,6 @@ uses Main, ConnectionManager, ImagingTyp procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo); var - mem: TMemoryStream; fadingbyte, depthbyte, storebyte: Byte; begin fileid := fileinfo.ID; @@ -56,7 +56,7 @@ begin OniImage_Old.LoadFromTXMP(ConnectionID, fileid); old_size := OniImage_Old.GetImageSize(True); - OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 2); + OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 1); check_fading.Checked := OniImage_Old.HasMipMaps; // check_transparency.Checked := (depthbyte and $04) > 0; @@ -66,9 +66,18 @@ begin end; +procedure TForm_TxmpReplace.Splitter1Moved(Sender: TObject); +begin + inherited; + image_txmppreview.Picture.Assign(nil); + image_bmppreview.Picture.Assign(nil); + if Length(OniImage_Old.Images) > 0 then + OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 1); + if Length(OniImage_New.Images) > 0 then + OniImage_New.DrawOnCanvas(image_bmppreview.Canvas, 1); +end; + procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject); -var - mem: TMemoryStream; begin if opend.Execute then begin @@ -89,6 +98,9 @@ var datbyte: Word; mem: TMemoryStream; new_storetype: Byte; + i: Integer; +const + powers: array[0..8] of Integer = (1, 2, 4, 8, 16, 32, 64, 128, 256); begin if filelist.ItemIndex >= 0 then begin @@ -98,6 +110,28 @@ begin else ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @old_rawaddr); + if (OniImage_New.Width[1] > 256) or (OniImage_New.Height[1] > 256) then + begin + ShowMessage('Widht and height have to be smaller than or equal to 256.'); + Exit; + end; + for i := 0 to High(powers) do + if OniImage_New.Width[1] = powers[i] then + Break; + if i = Length(powers) then + begin + ShowMessage('Width has to be a power of 2 (1, 2, 4, 8, 16 ...)'); + Exit; + end; + for i := 0 to High(powers) do + if OniImage_New.Height[1] = powers[i] then + Break; + if i = Length(powers) then + begin + ShowMessage('Height has to be a power of 2 (1, 2, 4, 8, 16 ...)'); + Exit; + end; + if (OniImage_Old.Width[1] <> OniImage_New.Width[1]) or (OniImage_Old.Height[1] <> OniImage_New.Height[1]) then begin @@ -116,6 +150,7 @@ begin mem := TMemoryStream.Create; case OniImage_New.Format of + ifX1R5G5B5: new_storetype := 1; ifA1R5G5B5: new_storetype := 2; ifA4R4G4B4: new_storetype := 0; ifA8R8G8B8: @@ -126,6 +161,13 @@ begin ifX8R8G8B8: new_storetype := 8; ifDXT1: new_storetype := 9; else + if OniImage_New.FormatInfo.HasAlphaChannel then + ShowMessage('Loaded image has an alpha-channel.' + #13#10 + + 'Because the format is neither ARGB1555' +#13#10 + + 'nor ARGB4444 it can not be imported without conversion.' + #13#10 + + 'It is converted to RGB888, so alpha gets dropped.' + #13#10 + + 'If you need alpha you have to save your image in' + #13#10 + + 'one of the previously named formats.'); OniImage_New.Format := ifX8R8G8B8; new_storetype := 8; end; @@ -144,9 +186,10 @@ begin ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem); end; - datbyte := $00; if check_fading.Checked then - datbyte := datbyte or $01; + oldfading := oldfading or $01 + else + oldfading := oldfading and (not Byte($01)); ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte); datbyte := $10; // if check_transparency.Checked then @@ -163,6 +206,7 @@ begin ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr); ShowMessage('TXMP-image replaced'); + Self.listClick(Self); end; end;