source: oup/releases/0.29a2/Unit7_txmpreplace.pas@ 1063

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