source: oup/releases/0.15a/Unit7_txmpreplace.pas@ 455

Last change on this file since 455 was 21, checked in by alloc, 18 years ago
File size: 7.0 KB
Line 
1UNIT Unit7_txmpreplace;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data;
6
7TYPE
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 btn_replaceClick(Sender: TObject);
26 PROCEDURE btn_loadClick(Sender: TObject);
27 PROCEDURE list_txmpClick(Sender: TObject);
28 PROCEDURE FormResize(Sender: TObject);
29 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
30 PROCEDURE RecreateTXMPlist;
31 PRIVATE
32 PUBLIC
33 END;
34
35VAR
36 Form7: TForm7;
37
38IMPLEMENTATION
39USES Unit1_main, Unit6_imgfuncs;
40{$R *.dfm}
41VAR
42 actual_bmpdata:Tdata;
43
44PROCEDURE TForm7.RecreateTXMPlist;
45 VAR
46 i:LongWord;
47 BEGIN
48 Form7.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 Form7.list_txmp.Items.Add(dat_files[i].FileName);
52 END;
53 Form7.group_bmpselect.Enabled:=False;
54 //Form7.image_txmppreview.Picture.Free;
55 //Form7.image_txmppreview.Picture.Create;
56 Form7.check_transparency.Checked:=False;
57 Form7.check_fading.Checked:=False;
58 END;
59
60PROCEDURE TForm7.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
61 BEGIN
62 CanClose:=False;
63 Form7.Visible:=False;
64 END;
65
66PROCEDURE TForm7.FormResize(Sender: TObject);
67 BEGIN
68 IF Form7.Width>=400 THEN BEGIN
69 END ELSE Form7.Width:=400;
70 IF Form7.Height>=350 THEN BEGIN
71 END ELSE Form7.Height:=350;
72 END;
73
74PROCEDURE TForm7.list_txmpClick(Sender: TObject);
75 VAR
76 id:LongWord;
77 data:Tdata;
78 img:TImgPackage;
79 mem:TMemoryStream;
80 fadingbyte,depthbyte,storebyte:Byte;
81 BEGIN
82 id:=StrToInt(MidStr(list_txmp.Items.Strings[list_txmp.ItemIndex],1,5));
83
84 LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
85 LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
86 LoadDatFilePart(id,$90,SizeOf(storebyte),@storebyte);
87 Form7.check_fading.Checked:=(fadingbyte AND $01)>0;
88 Form7.check_transparency.Checked:=(depthbyte AND $04)>0;
89 Form7.check_32bit.Checked:=(storebyte=8);
90
91 img:=LoadImgData(id);
92 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
93
94 mem:=TMemoryStream.Create;
95 mem.Write(data[0],Length(data));
96 mem.Seek(0,soFromBeginning);
97 Form7.image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
98 mem.Free;
99
100 Form7.group_bmpselect.Enabled:=True;
101 END;
102
103PROCEDURE TForm7.btn_loadClick(Sender: TObject);
104 VAR
105 bmpfile:TFileStream;
106 mem:TMemoryStream;
107 BEGIN
108 IF opend.Execute THEN BEGIN
109 bmpfile:=TFileStream.Create(opend.FileName, fmOpenRead);
110 SetLength(actual_bmpdata,bmpfile.Size);
111 bmpfile.Read(actual_bmpdata[0],bmpfile.Size);
112 bmpfile.Free;
113
114 mem:=TMemoryStream.Create;
115 mem.Write(actual_bmpdata[0],Length(actual_bmpdata));
116 mem.Seek(0,soFromBeginning);
117 Form7.image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
118 mem.Free;
119
120 Form7.group_options.Enabled:=True;
121 END;
122 END;
123
124PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
125 VAR
126 id:LongWord;
127 imgpkg:TImgPackage;
128 rawfile:TFileStream;
129 datfile:TFileStream;
130 dataddr:LongWord;
131 old_rawaddr,new_rawaddr:LongWord;
132 oldwidth,oldheight:Word;
133 oldstore,olddepth,oldfading:Byte;
134 oldsize:LongWord;
135 newsize:LongWord;
136 datword,datbyte:Word;
137 BEGIN
138 IF Form7.list_txmp.ItemIndex>=0 THEN BEGIN
139 imgpkg:=BmpToImgdata(actual_bmpdata,check_32bit.Checked);
140 datfile:=TFileStream.Create(dat_filename,fmOpenReadWrite);
141
142 id:=StrToInt(MidStr(list_txmp.Items.Strings[list_txmp.ItemIndex],1,5));
143 dataddr:=dat_files[id].dataddr;
144 datfile.Seek(dataddr+$8C,soFromBeginning);
145 datfile.Read(oldwidth,2);
146 datfile.Seek(dataddr+$8E,soFromBeginning);
147 datfile.Read(oldheight,2);
148 datfile.Seek(dataddr+$88,soFromBeginning);
149 datfile.Read(oldfading,1);
150 datfile.Seek(dataddr+$89,soFromBeginning);
151 datfile.Read(olddepth,1);
152 datfile.Seek(dataddr+$90,soFromBeginning);
153 datfile.Read(oldstore,1);
154 datfile.Seek(dataddr+$9C,soFromBeginning);
155 datfile.Read(old_rawaddr,4);
156 IF (oldwidth<>imgpkg.imgx) OR (oldheight<>imgpkg.imgy) THEN BEGIN
157 IF MessageBox(Form7.Handle,
158 PChar('Current image and new image have different size'+CrLf+
159 '(Current: '+IntToStr(oldwidth)+'x'+IntToStr(oldheight)+
160 ' - New: '+IntToStr(imgpkg.imgx)+'x'+IntToStr(imgpkg.imgy)+')'+CrLf+
161 'Replace anyways?'),
162 PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
163 MB_YESNO)=IDNO THEN Exit;
164 END;
165
166 rawfile:=TFileStream.Create(raw_filename,fmOpenReadWrite);
167
168 CASE oldstore OF
169 9: oldsize:=GetImageDataSize(oldwidth,oldheight,8,(oldfading AND $01)>0);
170 0,1,2: oldsize:=GetImageDataSize(oldwidth,oldheight,16,(oldfading AND $01)>0);
171 8: oldsize:=GetImageDataSize(oldwidth,oldheight,32,(oldfading AND $01)>0);
172 ELSE
173 oldsize:=0;
174 END;
175 IF check_32bit.Checked THEN
176 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,32,Form7.check_fading.Checked)
177 ELSE
178 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,16,Form7.check_fading.Checked);
179
180 IF newsize<=oldsize THEN
181 new_rawaddr:=old_rawaddr
182 ELSE
183 new_rawaddr:=rawfile.Size;
184
185 datbyte:=$00;
186 IF Form7.check_fading.Checked THEN datbyte:=datbyte OR $01;
187 datfile.Seek(dataddr+$88,soFromBeginning);
188 datfile.Write(datbyte,2);
189 datbyte:=$10;
190 IF Form7.check_transparency.Checked THEN datbyte:=datbyte OR $04;
191 datfile.Seek(dataddr+$89,soFromBeginning);
192 datfile.Write(datbyte,2);
193 datfile.Seek(dataddr+$8C,soFromBeginning);
194 datfile.Write(imgpkg.imgx,2);
195 datfile.Seek(dataddr+$8E,soFromBeginning);
196 datfile.Write(imgpkg.imgy,2);
197 IF check_32bit.Checked THEN
198 datbyte:=$08
199 ELSE
200 datbyte:=$01;
201 datfile.Seek(dataddr+$90,soFromBeginning);
202 datfile.Write(datbyte,2);
203 datfile.Seek(dataddr+$9C,soFromBeginning);
204 datfile.Write(new_rawaddr,4);
205 datfile.Free;
206
207 IF Form7.check_fading.Checked THEN BEGIN
208 imgpkg.imgdata:=CreateFadedImage(imgpkg);
209 END;
210
211 rawfile.Seek(new_rawaddr,soFromBeginning);
212 rawfile.Write(imgpkg.imgdata[0],Length(imgpkg.imgdata));
213 rawfile.Free;
214
215 ShowMessage('TXMP-image replaced');
216 END;
217 END;
218
219END.
Note: See TracBrowser for help on using the repository browser.