source: oup/releases/0.12a/src/Unit7_txmpreplace.pas@ 20

Last change on this file since 20 was 8, checked in by alloc, 18 years ago

Uploaded old revs and structdefs.

File size: 4.8 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_main: TPanel;
17 btn_replace: TButton;
18 panel_load: TPanel;
19 btn_load: TButton;
20 image_bmppreview: TImage;
21 opend: TOpenDialog;
22 PROCEDURE btn_replaceClick(Sender: TObject);
23 PROCEDURE btn_loadClick(Sender: TObject);
24 PROCEDURE list_txmpClick(Sender: TObject);
25 PROCEDURE FormResize(Sender: TObject);
26 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
27 PROCEDURE RecreateTXMPlist;
28 PRIVATE
29 PUBLIC
30 END;
31
32VAR
33 Form7: TForm7;
34
35IMPLEMENTATION
36USES Unit1_main, Unit6_imgfuncs;
37{$R *.dfm}
38VAR
39 actual_bmpdata:Tdata;
40
41PROCEDURE TForm7.RecreateTXMPlist;
42 VAR
43 i:LongWord;
44 BEGIN
45 Form7.list_txmp.Items.Clear;
46 FOR i:=0 TO dat_header.Files-1 DO BEGIN
47 IF (dat_files[i].Extension='TXMP') AND ((dat_files[i].FileType AND $02)=0) THEN
48 Form7.list_txmp.Items.Add(dat_files[i].FileName);
49 END;
50 Form7.group_bmpselect.Enabled:=False;
51 END;
52
53PROCEDURE TForm7.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
54 BEGIN
55 CanClose:=False;
56 Form7.Visible:=False;
57 END;
58
59PROCEDURE TForm7.FormResize(Sender: TObject);
60 BEGIN
61 IF Form7.Width>=400 THEN BEGIN
62 END ELSE Form7.Width:=400;
63 IF Form7.Height>=350 THEN BEGIN
64 END ELSE Form7.Height:=350;
65 END;
66
67PROCEDURE TForm7.list_txmpClick(Sender: TObject);
68 VAR
69 id:LongWord;
70 data:Tdata;
71 img:TImgPackage;
72 mem:TMemoryStream;
73 BEGIN
74 id:=StrToInt(MidStr(list_txmp.Items.Strings[list_txmp.ItemIndex],1,5));
75
76 img:=LoadImgData(id);
77 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
78
79 mem:=TMemoryStream.Create;
80 mem.Write(data[0],Length(data));
81 mem.Seek(0,soFromBeginning);
82 Form7.image_txmppreview.Picture.Bitmap.LoadFromStream(mem);
83 mem.Free;
84
85 Form7.group_bmpselect.Enabled:=True;
86 END;
87
88PROCEDURE TForm7.btn_loadClick(Sender: TObject);
89 VAR
90 bmpfile:TFileStream;
91 mem:TMemoryStream;
92 BEGIN
93 IF opend.Execute THEN BEGIN
94 bmpfile:=TFileStream.Create(opend.FileName, fmOpenRead);
95 SetLength(actual_bmpdata,bmpfile.Size);
96 bmpfile.Read(actual_bmpdata[0],bmpfile.Size);
97 bmpfile.Free;
98
99 mem:=TMemoryStream.Create;
100 mem.Write(actual_bmpdata[0],Length(actual_bmpdata));
101 mem.Seek(0,soFromBeginning);
102 Form7.image_bmppreview.Picture.Bitmap.LoadFromStream(mem);
103 mem.Free;
104
105 Form7.panel_main.Enabled:=True;
106 END;
107 END;
108
109PROCEDURE TForm7.btn_replaceClick(Sender: TObject);
110 VAR
111 id:LongWord;
112 imgpkg:TImgPackage;
113 rawfile:TFileStream;
114 datfile:TFileStream;
115 dataddr:LongWord;
116 new_rawaddr:LongWord;
117 oldwidth,oldheight:Word;
118 datword:Word;
119 BEGIN
120 IF Form7.list_txmp.ItemIndex>=0 THEN BEGIN
121 imgpkg:=BmpToImgdata(actual_bmpdata);
122 rawfile:=TFileStream.Create(raw_filename,fmOpenReadWrite);
123 datfile:=TFileStream.Create(dat_filename,fmOpenReadWrite);
124
125 id:=StrToInt(MidStr(list_txmp.Items.Strings[list_txmp.ItemIndex],1,5));
126 dataddr:=dat_files[id].dataddr;
127 datfile.Seek(dataddr+$8C,soFromBeginning);
128 datfile.Read(oldwidth,2);
129 datfile.Seek(dataddr+$8E,soFromBeginning);
130 datfile.Read(oldheight,2);
131 IF (oldwidth<>imgpkg.imgx) OR (oldheight<>imgpkg.imgy) THEN BEGIN
132 IF MessageBox(Form7.Handle,
133 PChar('Current image and new image have different size'+CrLf+
134 '(Current: '+IntToStr(oldwidth)+'x'+IntToStr(oldheight)+
135 ' - New: '+IntToStr(imgpkg.imgx)+'x'+IntToStr(imgpkg.imgy)+')'+CrLf+
136 'Replace anyways?'),
137 PChar('Really replace?'),
138 MB_YESNO)=IDNO THEN Exit;
139 END;
140 new_rawaddr:=rawfile.Size;
141
142 datword:=$1000;
143 datfile.Seek(dataddr+$88,soFromBeginning);
144 datfile.Write(datword,2);
145 datfile.Seek(dataddr+$8C,soFromBeginning);
146 datfile.Write(imgpkg.imgx,2);
147 datfile.Seek(dataddr+$8E,soFromBeginning);
148 datfile.Write(imgpkg.imgy,2);
149 datword:=$0001;
150 datfile.Seek(dataddr+$90,soFromBeginning);
151 datfile.Write(datword,2);
152 datfile.Seek(dataddr+$9C,soFromBeginning);
153 datfile.Write(new_rawaddr,4);
154 datfile.Free;
155
156 rawfile.Seek(new_rawaddr,soFromBeginning);
157 rawfile.Write(imgpkg.imgdata[0],Length(imgpkg.imgdata));
158 rawfile.Free;
159 END;
160 END;
161
162END.
Note: See TracBrowser for help on using the repository browser.