source: oup/releases/0.18a2/Unit7_txmpreplace.pas@ 168

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