[93] | 1 | unit TxmpReplace;
|
---|
| 2 | interface
|
---|
| 3 | uses
|
---|
| 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 5 | Dialogs, Template, StdCtrls, ExtCtrls,
|
---|
[97] | 6 | Functions, Data, OniImgClass, Menus, Buttons, TypeDefs;
|
---|
[93] | 7 |
|
---|
| 8 | type
|
---|
| 9 | TForm_TxmpReplace = class(TForm_ToolTemplate)
|
---|
| 10 | group_options: TGroupBox;
|
---|
| 11 | btn_replace: TButton;
|
---|
| 12 | check_transparency: TCheckBox;
|
---|
| 13 | check_fading: TCheckBox;
|
---|
| 14 | panel_txmppreview: TPanel;
|
---|
| 15 | btn_save: TButton;
|
---|
| 16 | image_txmppreview: TImage;
|
---|
| 17 | splitter_txmp: TSplitter;
|
---|
| 18 | group_bmpselect: TGroupBox;
|
---|
| 19 | image_bmppreview: TImage;
|
---|
| 20 | panel_load: TPanel;
|
---|
| 21 | btn_load: TButton;
|
---|
| 22 | opend: TOpenDialog;
|
---|
| 23 | saved: TSaveDialog;
|
---|
| 24 | procedure SelectFile(fileinfo: TFileInfo);
|
---|
| 25 | procedure FormCreate(Sender: TObject);
|
---|
| 26 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 27 | procedure btn_saveClick(Sender: TObject);
|
---|
| 28 | procedure btn_loadClick(Sender: TObject);
|
---|
| 29 | procedure btn_replaceClick(Sender: TObject);
|
---|
| 30 | private
|
---|
| 31 | OniImage_Old: TOniImage;
|
---|
| 32 | OniImage_New: TOniImage;
|
---|
| 33 | old_size: Integer;
|
---|
| 34 | fileid: Integer;
|
---|
| 35 | public
|
---|
| 36 | end;
|
---|
| 37 |
|
---|
| 38 | var
|
---|
| 39 | Form_TxmpReplace: TForm_TxmpReplace;
|
---|
| 40 |
|
---|
| 41 | implementation
|
---|
| 42 | {$R *.dfm}
|
---|
[192] | 43 | uses Main, ConnectionManager, ImagingTypes;
|
---|
[93] | 44 |
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | procedure TForm_TxmpReplace.SelectFile(fileinfo: TFileInfo);
|
---|
| 48 | var
|
---|
| 49 | mem: TMemoryStream;
|
---|
| 50 | fadingbyte, depthbyte, storebyte: Byte;
|
---|
| 51 | begin
|
---|
| 52 | fileid := fileinfo.ID;
|
---|
[105] | 53 | ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(fadingbyte), @fadingbyte);
|
---|
| 54 | ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $89, SizeOf(depthbyte), @depthbyte);
|
---|
| 55 | ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(storebyte), @storebyte);
|
---|
[93] | 56 |
|
---|
[105] | 57 | OniImage_Old.LoadFromTXMP(ConnectionID, fileid);
|
---|
[192] | 58 | old_size := OniImage_Old.GetImageSize(True);
|
---|
[193] | 59 | OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 2);
|
---|
[93] | 60 |
|
---|
[192] | 61 | check_fading.Checked := OniImage_Old.HasMipMaps;
|
---|
| 62 | // check_transparency.Checked := (depthbyte and $04) > 0;
|
---|
| 63 | check_transparency.Checked := storebyte in [0, 2, 7];
|
---|
| 64 |
|
---|
[93] | 65 | group_bmpselect.Enabled := True;
|
---|
| 66 | end;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject);
|
---|
| 70 | var
|
---|
| 71 | mem: TMemoryStream;
|
---|
| 72 | begin
|
---|
| 73 | if opend.Execute then
|
---|
| 74 | begin
|
---|
[192] | 75 | OniImage_New.LoadFromFile(opend.FileName);
|
---|
[193] | 76 | OniImage_New.DrawOnCanvas(image_bmppreview.Canvas, 1);
|
---|
[93] | 77 | group_options.Enabled := True;
|
---|
| 78 | end;
|
---|
| 79 | end;
|
---|
| 80 |
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | procedure TForm_TxmpReplace.btn_replaceClick(Sender: TObject);
|
---|
| 85 | var
|
---|
[111] | 86 | newsize: Integer;
|
---|
| 87 | old_rawaddr, new_rawaddr: Integer;
|
---|
[93] | 88 | oldfading: Byte;
|
---|
| 89 | datbyte: Word;
|
---|
[105] | 90 | mem: TMemoryStream;
|
---|
[193] | 91 | new_storetype: Byte;
|
---|
[93] | 92 | begin
|
---|
| 93 | if filelist.ItemIndex >= 0 then
|
---|
| 94 | begin
|
---|
[105] | 95 | ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, 1, @oldfading);
|
---|
| 96 | if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
|
---|
| 97 | ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, 4, @old_rawaddr)
|
---|
[93] | 98 | else
|
---|
[105] | 99 | ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, 4, @old_rawaddr);
|
---|
[93] | 100 |
|
---|
[192] | 101 | if (OniImage_Old.Width[1] <> OniImage_New.Width[1]) or
|
---|
| 102 | (OniImage_Old.Height[1] <> OniImage_New.Height[1]) then
|
---|
[93] | 103 | begin
|
---|
[105] | 104 | if MessageBox(Self.Handle,
|
---|
| 105 | PChar(
|
---|
| 106 | 'Current image and new image have different size' + CrLf +
|
---|
[192] | 107 | '(Current: ' + IntToStr(OniImage_Old.Width[1]) + 'x' +
|
---|
| 108 | IntToStr(OniImage_Old.Height[1]) + ' - New: ' +
|
---|
| 109 | IntToStr(OniImage_New.Width[1]) + 'x' +
|
---|
| 110 | IntToStr(OniImage_New.Height[1]) +
|
---|
[105] | 111 | ')' + CrLf + 'Replace anyway?'),
|
---|
| 112 | PChar(filelist.Items.Strings[filelist.ItemIndex]), MB_YESNO) = idNo then
|
---|
[93] | 113 | Exit;
|
---|
| 114 | end;
|
---|
| 115 |
|
---|
[105] | 116 | mem := TMemoryStream.Create;
|
---|
| 117 |
|
---|
[193] | 118 | case OniImage_New.Format of
|
---|
| 119 | ifA1R5G5B5: new_storetype := 2;
|
---|
| 120 | ifA4R4G4B4: new_storetype := 0;
|
---|
| 121 | ifA8R8G8B8:
|
---|
| 122 | begin
|
---|
| 123 | new_storetype := 8;
|
---|
| 124 | OniImage_New.Format := ifX8R8G8B8;
|
---|
| 125 | end;
|
---|
| 126 | ifX8R8G8B8: new_storetype := 8;
|
---|
| 127 | ifDXT1: new_storetype := 9;
|
---|
| 128 | else
|
---|
| 129 | OniImage_New.Format := ifX8R8G8B8;
|
---|
| 130 | new_storetype := 8;
|
---|
| 131 | end;
|
---|
| 132 |
|
---|
[192] | 133 | OniImage_New.SaveDataToStream(check_fading.Checked, TStream(mem));
|
---|
[93] | 134 |
|
---|
[192] | 135 | newsize := mem.Size;
|
---|
| 136 | mem.Seek(0, soFromBeginning);
|
---|
[93] | 137 |
|
---|
[105] | 138 | if (newsize > old_size) and (ConManager.Connection[ConnectionID].Backend = DB_ONI) then
|
---|
| 139 | new_rawaddr := ConManager.Connection[ConnectionID].AppendRawFile(
|
---|
[193] | 140 | not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN), mem)
|
---|
[93] | 141 | else
|
---|
| 142 | begin
|
---|
| 143 | new_rawaddr := old_rawaddr;
|
---|
[105] | 144 | ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem);
|
---|
[93] | 145 | end;
|
---|
| 146 |
|
---|
| 147 | datbyte := $00;
|
---|
| 148 | if check_fading.Checked then
|
---|
| 149 | datbyte := datbyte or $01;
|
---|
[105] | 150 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte);
|
---|
[93] | 151 | datbyte := $10;
|
---|
[192] | 152 | // if check_transparency.Checked then
|
---|
| 153 | // datbyte := datbyte or $04;
|
---|
[105] | 154 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $89, 1, @datbyte);
|
---|
[192] | 155 | datbyte := OniImage_New.Width[1];
|
---|
| 156 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @datbyte);
|
---|
| 157 | datbyte := OniImage_New.Height[1];
|
---|
| 158 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @datbyte);
|
---|
[193] | 159 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @new_storetype);
|
---|
[105] | 160 | if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
|
---|
| 161 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
|
---|
[93] | 162 | else
|
---|
[105] | 163 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
|
---|
[93] | 164 |
|
---|
| 165 | ShowMessage('TXMP-image replaced');
|
---|
| 166 | end;
|
---|
| 167 | end;
|
---|
| 168 |
|
---|
| 169 |
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | procedure TForm_TxmpReplace.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 173 | begin
|
---|
| 174 | OniImage_Old.Free;
|
---|
| 175 | OniImage_New.Free;
|
---|
| 176 | inherited;
|
---|
| 177 | end;
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 |
|
---|
| 181 |
|
---|
| 182 | procedure TForm_TxmpReplace.FormCreate(Sender: TObject);
|
---|
| 183 | begin
|
---|
| 184 | inherited;
|
---|
| 185 | OniImage_Old := TOniImage.Create;
|
---|
| 186 | OniImage_New := TOniImage.Create;
|
---|
| 187 | Self.AllowedExts := 'TXMP';
|
---|
| 188 | Self.OnNewFileSelected := SelectFile;
|
---|
[192] | 189 | opend.Filter := saved.Filter;
|
---|
[93] | 190 | end;
|
---|
| 191 |
|
---|
| 192 |
|
---|
| 193 |
|
---|
| 194 |
|
---|
| 195 | procedure TForm_TxmpReplace.btn_saveClick(Sender: TObject);
|
---|
| 196 | begin
|
---|
| 197 | if saved.Execute then
|
---|
[192] | 198 | OniImage_Old.WriteToFile(saved.FileName);
|
---|
[93] | 199 | end;
|
---|
| 200 |
|
---|
| 201 | begin
|
---|
| 202 | AddToolListEntry('txmpreplace', 'TXMP Replacer', 'TXMP');
|
---|
| 203 | end.
|
---|