[21] | 1 | UNIT Unit7_txmpreplace;
|
---|
| 2 | INTERFACE
|
---|
| 3 | USES
|
---|
| 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
| 5 | Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data;
|
---|
| 6 |
|
---|
| 7 | TYPE
|
---|
| 8 | TForm7 = Class(TForm)
|
---|
| 9 | panel_12: TPanel;
|
---|
| 10 | group_txmpselect: TGroupBox;
|
---|
| 11 | splitter_txmp: TSplitter;
|
---|
| 12 | image_txmppreview: TImage;
|
---|
| 13 | list_txmp: TListBox;
|
---|
| 14 | Splitter1: TSplitter;
|
---|
| 15 | group_bmpselect: TGroupBox;
|
---|
| 16 | panel_load: TPanel;
|
---|
| 17 | btn_load: TButton;
|
---|
| 18 | image_bmppreview: TImage;
|
---|
| 19 | opend: TOpenDialog;
|
---|
| 20 | group_options: TGroupBox;
|
---|
| 21 | btn_replace: TButton;
|
---|
| 22 | check_transparency: TCheckBox;
|
---|
| 23 | check_fading: TCheckBox;
|
---|
| 24 | check_32bit: TCheckBox;
|
---|
| 25 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 26 | PROCEDURE btn_replaceClick(Sender: TObject);
|
---|
| 27 | PROCEDURE btn_loadClick(Sender: TObject);
|
---|
| 28 | PROCEDURE list_txmpClick(Sender: TObject);
|
---|
| 29 | PROCEDURE FormResize(Sender: TObject);
|
---|
| 30 | PROCEDURE Recreatelist;
|
---|
| 31 | PRIVATE
|
---|
| 32 | PUBLIC
|
---|
| 33 | END;
|
---|
| 34 |
|
---|
| 35 | VAR
|
---|
| 36 | Form7: TForm7;
|
---|
| 37 |
|
---|
| 38 | IMPLEMENTATION
|
---|
| 39 | USES Unit1_main, Unit6_imgfuncs;
|
---|
| 40 | {$R *.dfm}
|
---|
| 41 | VAR
|
---|
| 42 | actual_bmpdata:Tdata;
|
---|
| 43 |
|
---|
| 44 | PROCEDURE TForm7.Recreatelist;
|
---|
| 45 | VAR
|
---|
| 46 | i:LongWord;
|
---|
| 47 | BEGIN
|
---|
| 48 | list_txmp.Items.Clear;
|
---|
| 49 | FOR i:=0 TO dat_header.Files-1 DO BEGIN
|
---|
| 50 | IF (dat_files[i].Extension='TXMP') AND ((dat_files[i].FileType AND $02)=0) THEN
|
---|
| 51 | list_txmp.Items.Add(dat_files[i].FileName);
|
---|
| 52 | END;
|
---|
| 53 | group_bmpselect.Enabled:=False;
|
---|
| 54 | check_transparency.Checked:=False;
|
---|
| 55 | check_fading.Checked:=False;
|
---|
| 56 | END;
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | PROCEDURE TForm7.FormResize(Sender: TObject);
|
---|
| 60 | BEGIN
|
---|
| 61 | IF Self.Width>=400 THEN BEGIN
|
---|
| 62 | END ELSE Self.Width:=400;
|
---|
| 63 | IF Self.Height>=350 THEN BEGIN
|
---|
| 64 | END ELSE Self.Height:=350;
|
---|
| 65 | END;
|
---|
| 66 |
|
---|
| 67 | PROCEDURE TForm7.list_txmpClick(Sender: TObject);
|
---|
| 68 | VAR
|
---|
| 69 | id:LongWord;
|
---|
| 70 | data:Tdata;
|
---|
| 71 | img:TImgPackage;
|
---|
| 72 | mem:TMemoryStream;
|
---|
| 73 | fadingbyte,depthbyte,storebyte:Byte;
|
---|
| 74 | BEGIN
|
---|
| 75 | id:=StrToInt(MidStr(list_txmp.Items.Strings[list_txmp.ItemIndex],1,5));
|
---|
| 76 |
|
---|
| 77 | LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
|
---|
| 78 | LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
|
---|
| 79 | LoadDatFilePart(id,$90,SizeOf(storebyte),@storebyte);
|
---|
| 80 | check_fading.Checked:=(fadingbyte AND $01)>0;
|
---|
| 81 | check_transparency.Checked:=(depthbyte AND $04)>0;
|
---|
| 82 | check_32bit.Checked:=(storebyte=8);
|
---|
| 83 |
|
---|
| 84 | img:=LoadImgData(id);
|
---|
| 85 | data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
|
---|
| 86 |
|
---|
| 87 | mem:=TMemoryStream.Create;
|
---|
| 88 | mem.Write(data[0],Length(data));
|
---|
| 89 | mem.Seek(0,soFromBeginning);
|
---|
| 90 | image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
|
---|
| 91 | mem.Free;
|
---|
| 92 |
|
---|
| 93 | group_bmpselect.Enabled:=True;
|
---|
| 94 | END;
|
---|
| 95 |
|
---|
| 96 | PROCEDURE TForm7.btn_loadClick(Sender: TObject);
|
---|
| 97 | VAR
|
---|
| 98 | bmpfile:TFileStream;
|
---|
| 99 | mem:TMemoryStream;
|
---|
| 100 | BEGIN
|
---|
| 101 | IF opend.Execute THEN BEGIN
|
---|
| 102 | bmpfile:=TFileStream.Create(opend.FileName, fmOpenRead);
|
---|
| 103 | SetLength(actual_bmpdata,bmpfile.Size);
|
---|
| 104 | bmpfile.Read(actual_bmpdata[0],bmpfile.Size);
|
---|
| 105 | bmpfile.Free;
|
---|
| 106 |
|
---|
| 107 | mem:=TMemoryStream.Create;
|
---|
| 108 | mem.Write(actual_bmpdata[0],Length(actual_bmpdata));
|
---|
| 109 | mem.Seek(0,soFromBeginning);
|
---|
| 110 | image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
|
---|
| 111 | mem.Free;
|
---|
| 112 |
|
---|
| 113 | group_options.Enabled:=True;
|
---|
| 114 | END;
|
---|
| 115 | END;
|
---|
| 116 |
|
---|
| 117 | PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
|
---|
| 118 | VAR
|
---|
| 119 | id:LongWord;
|
---|
| 120 | imgpkg:TImgPackage;
|
---|
| 121 | rawfile:TFileStream;
|
---|
| 122 | datfile:TFileStream;
|
---|
| 123 | dataddr:LongWord;
|
---|
| 124 | old_rawaddr,new_rawaddr:LongWord;
|
---|
| 125 | oldwidth,oldheight:Word;
|
---|
| 126 | oldstore,olddepth,oldfading:Byte;
|
---|
| 127 | oldsize:LongWord;
|
---|
| 128 | newsize:LongWord;
|
---|
| 129 | datbyte:Word;
|
---|
| 130 | BEGIN
|
---|
| 131 | IF list_txmp.ItemIndex>=0 THEN BEGIN
|
---|
| 132 | imgpkg:=BmpToImgdata(actual_bmpdata,check_32bit.Checked);
|
---|
| 133 | datfile:=TFileStream.Create(dat_filename,fmOpenReadWrite);
|
---|
| 134 |
|
---|
| 135 | id:=StrToInt(MidStr(list_txmp.Items.Strings[list_txmp.ItemIndex],1,5));
|
---|
| 136 | dataddr:=dat_files[id].dataddr;
|
---|
| 137 | datfile.Seek(dataddr+$8C,soFromBeginning);
|
---|
| 138 | datfile.Read(oldwidth,2);
|
---|
| 139 | datfile.Seek(dataddr+$8E,soFromBeginning);
|
---|
| 140 | datfile.Read(oldheight,2);
|
---|
| 141 | datfile.Seek(dataddr+$88,soFromBeginning);
|
---|
| 142 | datfile.Read(oldfading,1);
|
---|
| 143 | datfile.Seek(dataddr+$89,soFromBeginning);
|
---|
| 144 | datfile.Read(olddepth,1);
|
---|
| 145 | datfile.Seek(dataddr+$90,soFromBeginning);
|
---|
| 146 | datfile.Read(oldstore,1);
|
---|
| 147 | datfile.Seek(dataddr+$9C,soFromBeginning);
|
---|
| 148 | datfile.Read(old_rawaddr,4);
|
---|
| 149 | IF (oldwidth<>imgpkg.imgx) OR (oldheight<>imgpkg.imgy) THEN BEGIN
|
---|
| 150 | IF MessageBox(Self.Handle,
|
---|
| 151 | PChar('Current image and new image have different size'+CrLf+
|
---|
| 152 | '(Current: '+IntToStr(oldwidth)+'x'+IntToStr(oldheight)+
|
---|
| 153 | ' - New: '+IntToStr(imgpkg.imgx)+'x'+IntToStr(imgpkg.imgy)+')'+CrLf+
|
---|
| 154 | 'Replace anyways?'),
|
---|
| 155 | PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
|
---|
| 156 | MB_YESNO)=IDNO THEN Exit;
|
---|
| 157 | END;
|
---|
| 158 |
|
---|
| 159 | rawfile:=TFileStream.Create(raw_filename,fmOpenReadWrite);
|
---|
| 160 |
|
---|
| 161 | CASE oldstore OF
|
---|
| 162 | 9: oldsize:=GetImageDataSize(oldwidth,oldheight,8,(oldfading AND $01)>0);
|
---|
| 163 | 0,1,2: oldsize:=GetImageDataSize(oldwidth,oldheight,16,(oldfading AND $01)>0);
|
---|
| 164 | 8: oldsize:=GetImageDataSize(oldwidth,oldheight,32,(oldfading AND $01)>0);
|
---|
| 165 | ELSE
|
---|
| 166 | oldsize:=0;
|
---|
| 167 | END;
|
---|
| 168 | IF check_32bit.Checked THEN
|
---|
| 169 | newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,32,check_fading.Checked)
|
---|
| 170 | ELSE
|
---|
| 171 | newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,16,check_fading.Checked);
|
---|
| 172 |
|
---|
| 173 | IF newsize<=oldsize THEN
|
---|
| 174 | new_rawaddr:=old_rawaddr
|
---|
| 175 | ELSE
|
---|
| 176 | new_rawaddr:=rawfile.Size;
|
---|
| 177 |
|
---|
| 178 | datbyte:=$00;
|
---|
| 179 | IF check_fading.Checked THEN datbyte:=datbyte OR $01;
|
---|
| 180 | datfile.Seek(dataddr+$88,soFromBeginning);
|
---|
| 181 | datfile.Write(datbyte,1);
|
---|
| 182 | datbyte:=$10;
|
---|
| 183 | IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
|
---|
| 184 | datfile.Seek(dataddr+$89,soFromBeginning);
|
---|
| 185 | datfile.Write(datbyte,1);
|
---|
| 186 | datfile.Seek(dataddr+$8C,soFromBeginning);
|
---|
| 187 | datfile.Write(imgpkg.imgx,2);
|
---|
| 188 | datfile.Seek(dataddr+$8E,soFromBeginning);
|
---|
| 189 | datfile.Write(imgpkg.imgy,2);
|
---|
| 190 | IF check_32bit.Checked THEN
|
---|
| 191 | datbyte:=$08
|
---|
| 192 | ELSE
|
---|
| 193 | datbyte:=$01;
|
---|
| 194 | datfile.Seek(dataddr+$90,soFromBeginning);
|
---|
| 195 | datfile.Write(datbyte,1);
|
---|
| 196 | datfile.Seek(dataddr+$9C,soFromBeginning);
|
---|
| 197 | datfile.Write(new_rawaddr,4);
|
---|
| 198 | datfile.Free;
|
---|
| 199 |
|
---|
| 200 | IF check_fading.Checked THEN BEGIN
|
---|
| 201 | imgpkg.imgdata:=CreateFadedImage(imgpkg);
|
---|
| 202 | END;
|
---|
| 203 |
|
---|
| 204 | rawfile.Seek(new_rawaddr,soFromBeginning);
|
---|
| 205 | rawfile.Write(imgpkg.imgdata[0],Length(imgpkg.imgdata));
|
---|
| 206 | rawfile.Free;
|
---|
| 207 |
|
---|
| 208 | ShowMessage('TXMP-image replaced');
|
---|
| 209 | END;
|
---|
| 210 | END;
|
---|
| 211 |
|
---|
| 212 | PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 213 | VAR
|
---|
| 214 | i:Byte;
|
---|
| 215 | BEGIN
|
---|
| 216 | FOR i:=0 TO Form1.menu_windows.Count-1 DO BEGIN
|
---|
| 217 | IF Form1.menu_windows.Items[i].Name='menu_window_'+Self.Name THEN BEGIN
|
---|
| 218 | Form1.menu_windows.Items[i].Free;
|
---|
| 219 | Break;
|
---|
| 220 | END;
|
---|
| 221 | END;
|
---|
| 222 | Form1.menu_tools.Enabled:=True;
|
---|
| 223 | Action:=caFree;
|
---|
| 224 | END;
|
---|
| 225 |
|
---|
| 226 | END.
|
---|