1 | UNIT Unit7_txmpreplace;
|
---|
2 | INTERFACE
|
---|
3 | USES
|
---|
4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
5 | Dialogs, ExtCtrls, StdCtrls, StrUtils, Unit2_functions, Unit3_data;
|
---|
6 |
|
---|
7 | TYPE
|
---|
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 |
|
---|
40 | VAR
|
---|
41 | Form7: TForm7;
|
---|
42 |
|
---|
43 | IMPLEMENTATION
|
---|
44 | USES Unit1_main, Unit6_imgfuncs, Unit15_Classes;
|
---|
45 | {$R *.dfm}
|
---|
46 | VAR
|
---|
47 | actual_bmpdata:Tdata;
|
---|
48 |
|
---|
49 | PROCEDURE TForm7.Recreatelist;
|
---|
50 | VAR
|
---|
51 | files:TStringArray;
|
---|
52 | i:LongWord;
|
---|
53 | BEGIN
|
---|
54 | list_txmp.Items.Clear;
|
---|
55 | files:=OniDataConnection.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 |
|
---|
65 | PROCEDURE 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 |
|
---|
73 | PROCEDURE 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:=OniDataConnection.GetFileIDByName(list_txmp.Items.Strings[list_txmp.ItemIndex]);
|
---|
82 |
|
---|
83 | OniDataConnection.LoadDatFilePart(id,$88,SizeOf(fadingbyte),@fadingbyte);
|
---|
84 | OniDataConnection.LoadDatFilePart(id,$89,SizeOf(depthbyte),@depthbyte);
|
---|
85 | OniDataConnection.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 |
|
---|
102 | PROCEDURE 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 |
|
---|
123 | PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
|
---|
124 | VAR
|
---|
125 | id:LongWord;
|
---|
126 | imgpkg:TImgPackage;
|
---|
127 | old_rawaddr,new_rawaddr:LongWord;
|
---|
128 | oldwidth,oldheight:Word;
|
---|
129 | oldstore,olddepth,oldfading:Byte;
|
---|
130 | oldsize:LongWord;
|
---|
131 | newsize:LongWord;
|
---|
132 | datbyte:Word;
|
---|
133 | BEGIN
|
---|
134 | IF list_txmp.ItemIndex>=0 THEN BEGIN
|
---|
135 | imgpkg:=BmpToImgdata(actual_bmpdata,check_32bit.Checked);
|
---|
136 |
|
---|
137 | id:=OniDataConnection.GetFileIDByName(list_txmp.Items.Strings[list_txmp.ItemIndex]);
|
---|
138 | OniDataConnection.LoadDatFilePart(id,$8C,2,@oldwidth);
|
---|
139 | OniDataConnection.LoadDatFilePart(id,$8E,2,@oldheight);
|
---|
140 | OniDataConnection.LoadDatFilePart(id,$88,1,@oldfading);
|
---|
141 | OniDataConnection.LoadDatFilePart(id,$89,1,@olddepth);
|
---|
142 | OniDataConnection.LoadDatFilePart(id,$90,1,@oldstore);
|
---|
143 | OniDataConnection.LoadDatFilePart(id,$9C,4,@old_rawaddr);
|
---|
144 | IF (oldwidth<>imgpkg.imgx) OR (oldheight<>imgpkg.imgy) THEN BEGIN
|
---|
145 | IF MessageBox(Self.Handle,
|
---|
146 | PChar('Current image and new image have different size'+CrLf+
|
---|
147 | '(Current: '+IntToStr(oldwidth)+'x'+IntToStr(oldheight)+
|
---|
148 | ' - New: '+IntToStr(imgpkg.imgx)+'x'+IntToStr(imgpkg.imgy)+')'+CrLf+
|
---|
149 | 'Replace anyways?'),
|
---|
150 | PChar(list_txmp.Items.Strings[list_txmp.ItemIndex]),
|
---|
151 | MB_YESNO)=IDNO THEN Exit;
|
---|
152 | END;
|
---|
153 |
|
---|
154 | CASE oldstore OF
|
---|
155 | 9: oldsize:=GetImageDataSize(oldwidth,oldheight,8,(oldfading AND $01)>0);
|
---|
156 | 0,1,2: oldsize:=GetImageDataSize(oldwidth,oldheight,16,(oldfading AND $01)>0);
|
---|
157 | 8: oldsize:=GetImageDataSize(oldwidth,oldheight,32,(oldfading AND $01)>0);
|
---|
158 | ELSE
|
---|
159 | oldsize:=0;
|
---|
160 | END;
|
---|
161 |
|
---|
162 | IF check_fading.Checked THEN
|
---|
163 | IF Not CreateFadedImage(imgpkg,imgpkg.imgdata) THEN
|
---|
164 | 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
|
---|
165 | check_fading.Checked:=False
|
---|
166 | ELSE
|
---|
167 | Exit;
|
---|
168 |
|
---|
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) AND (OniDataConnection.Backend=ODB_Dat) THEN
|
---|
175 | new_rawaddr:=OniDataConnection.AppendRawFile(False,Length(imgpkg.imgdata),imgpkg.imgdata)
|
---|
176 | ELSE BEGIN
|
---|
177 | new_rawaddr:=old_rawaddr;
|
---|
178 | OniDataConnection.UpdateRawFile(id,$9C,Length(imgpkg.imgdata),imgpkg.imgdata);
|
---|
179 | END;
|
---|
180 |
|
---|
181 | datbyte:=$00;
|
---|
182 | IF check_fading.Checked THEN datbyte:=datbyte OR $01;
|
---|
183 | OniDataConnection.UpdateDatFilePart(id,$88,1,@datbyte);
|
---|
184 | datbyte:=$10;
|
---|
185 | IF check_transparency.Checked THEN datbyte:=datbyte OR $04;
|
---|
186 | OniDataConnection.UpdateDatFilePart(id,$89,1,@datbyte);
|
---|
187 | OniDataConnection.UpdateDatFilePart(id,$8C,2,@imgpkg.imgx);
|
---|
188 | OniDataConnection.UpdateDatFilePart(id,$8E,2,@imgpkg.imgy);
|
---|
189 | IF check_32bit.Checked THEN
|
---|
190 | datbyte:=$08
|
---|
191 | ELSE
|
---|
192 | datbyte:=$01;
|
---|
193 | OniDataConnection.UpdateDatFilePart(id,$90,1,@datbyte);
|
---|
194 | OniDataConnection.UpdateDatFilePart(id,$9C,4,@new_rawaddr);
|
---|
195 |
|
---|
196 | ShowMessage('TXMP-image replaced');
|
---|
197 | END;
|
---|
198 | END;
|
---|
199 |
|
---|
200 | PROCEDURE TForm7.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
201 | BEGIN
|
---|
202 | Action:=caFree;
|
---|
203 | Form1.close_window(Self.Name);
|
---|
204 | END;
|
---|
205 |
|
---|
206 | PROCEDURE TForm7.FormActivate(Sender: TObject);
|
---|
207 | BEGIN
|
---|
208 | Form1.SetActiveWindow(Self.Name);
|
---|
209 | END;
|
---|
210 |
|
---|
211 | PROCEDURE TForm7.btn_saveClick(Sender: TObject);
|
---|
212 | VAR
|
---|
213 | filestream:TFileStream;
|
---|
214 | img:TImgPackage;
|
---|
215 | BEGIN
|
---|
216 | IF saved.Execute THEN BEGIN
|
---|
217 | img:=LoadImgData(OniDataConnection.GetFileIDByName(list_txmp.Items.Strings[list_txmp.ItemIndex]));
|
---|
218 | img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
|
---|
219 | filestream:=TFileStream.Create(saved.FileName,fmCreate);
|
---|
220 | filestream.Write(img.imgdata[0],Length(img.imgdata));
|
---|
221 | filestream.Free;
|
---|
222 | END;
|
---|
223 | END;
|
---|
224 |
|
---|
225 | END.
|
---|