source: oup/releases/0.13a/Unit7_txmpreplace.pas@ 1080

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