source: oup/releases/0.29a3/Unit7_txmpreplace.pas@ 1009

Last change on this file since 1009 was 31, checked in by alloc, 18 years ago
File size: 7.2 KB
RevLine 
[31]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 CASE oldstore OF
157 9: oldsize:=GetImageDataSize(oldwidth,oldheight,8,(oldfading AND $01)>0);
158 0,1,2: oldsize:=GetImageDataSize(oldwidth,oldheight,16,(oldfading AND $01)>0);
159 8: oldsize:=GetImageDataSize(oldwidth,oldheight,32,(oldfading AND $01)>0);
160 ELSE
161 oldsize:=0;
162 END;
163
164 IF check_fading.Checked THEN
165 IF Not CreateFadedImage(imgpkg,imgpkg.imgdata) THEN
166 IF MessageBox(Self.Handle, PChar('Can not create a MipMapped-image (probably because of a wrong dimension).'+#13+#10+'Do you want to continue without MipMapping?'), PChar('Warning'), MB_YESNO)=ID_YES THEN
167 check_fading.Checked:=False
168 ELSE
169 Exit;
170
171 IF check_32bit.Checked THEN
172 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,32,check_fading.Checked)
173 ELSE
174 newsize:=GetImageDataSize(imgpkg.imgx,imgpkg.imgy,16,check_fading.Checked);
175
176 rawfile:=TFileStream.Create(raw_filename,fmOpenReadWrite);
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 UpdateDatFilePart(id,$88,1,@datbyte);
186 datbyte:=$10;
187 IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
188 UpdateDatFilePart(id,$89,1,@datbyte);
189 UpdateDatFilePart(id,$8C,2,@imgpkg.imgx);
190 UpdateDatFilePart(id,$8E,2,@imgpkg.imgy);
191 IF check_32bit.Checked THEN
192 datbyte:=$08
193 ELSE
194 datbyte:=$01;
195 UpdateDatFilePart(id,$90,1,@datbyte);
196 UpdateDatFilePart(id,$9C,4,@new_rawaddr);
197
198 rawfile.Seek(new_rawaddr,soFromBeginning);
199 rawfile.Write(imgpkg.imgdata[0],Length(imgpkg.imgdata));
200 rawfile.Free;
201
202 ShowMessage('TXMP-image replaced');
203 END;
204 END;
205
206PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
207 BEGIN
208 Action:=caFree;
209 Form1.close_window(Self.Name);
210 END;
211
212PROCEDURE TForm7.FormActivate(Sender: TObject);
213 BEGIN
214 Form1.SetActiveWindow(Self.Name);
215 END;
216
217PROCEDURE TForm7.btn_saveClick(Sender: TObject);
218 VAR
219 filestream:TFileStream;
220 img:TImgPackage;
221 BEGIN
222 IF saved.Execute THEN BEGIN
223 img:=LoadImgData(GetFileIDByName(list_txmp.Items.Strings[list_txmp.ItemIndex]));
224 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
225 filestream:=TFileStream.Create(saved.FileName,fmCreate);
226 filestream.Write(img.imgdata[0],Length(img.imgdata));
227 filestream.Free;
228 END;
229 END;
230
231END.
Note: See TracBrowser for help on using the repository browser.