source: oup/releases/0.16a/Unit7_txmpreplace.pas@ 26

Last change on this file since 26 was 21, checked in by alloc, 18 years ago
File size: 6.9 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.check_transparency.Checked:=False;
55 Form7.check_fading.Checked:=False;
56 END;
57
58PROCEDURE TForm7.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
59 BEGIN
60 CanClose:=False;
61 Form7.Visible:=False;
62 END;
63
64PROCEDURE TForm7.FormResize(Sender: TObject);
65 BEGIN
66 IF Form7.Width>=400 THEN BEGIN
67 END ELSE Form7.Width:=400;
68 IF Form7.Height>=350 THEN BEGIN
69 END ELSE Form7.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 Form7.check_fading.Checked:=(fadingbyte AND $01)>0;
86 Form7.check_transparency.Checked:=(depthbyte AND $04)>0;
87 Form7.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 Form7.image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
96 mem.Free;
97
98 Form7.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 Form7.image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
116 mem.Free;
117
118 Form7.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 Form7.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(Form7.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,Form7.check_fading.Checked)
175 ELSE
176 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,16,Form7.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 Form7.check_fading.Checked THEN datbyte:=datbyte OR $01;
185 datfile.Seek(dataddr+$88,soFromBeginning);
186 datfile.Write(datbyte,1);
187 datbyte:=$10;
188 IF Form7.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 Form7.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
217END.
Note: See TracBrowser for help on using the repository browser.