source: oup/releases/0.19a/Unit7_txmpreplace.pas@ 119

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