ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/TxmpReplace.pas
(Generate patch)

Comparing oup/current/Tools/TxmpReplace.pas (file contents):
Revision 192 by alloc, Thu May 24 17:48:18 2007 UTC vs.
Revision 199 by alloc, Sat May 26 20:41:34 2007 UTC

# Line 27 | Line 27 | type
27      procedure btn_saveClick(Sender: TObject);
28      procedure btn_loadClick(Sender: TObject);
29      procedure btn_replaceClick(Sender: TObject);
30 +    procedure Splitter1Moved(Sender: TObject);
31    private
32      OniImage_Old: TOniImage;
33      OniImage_New: TOniImage;
# Line 56 | Line 57 | begin
57  
58    OniImage_Old.LoadFromTXMP(ConnectionID, fileid);
59    old_size := OniImage_Old.GetImageSize(True);
60 <  OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 0);
60 >  OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 1);
61  
62    check_fading.Checked := OniImage_Old.HasMipMaps;
63   //  check_transparency.Checked := (depthbyte and $04) > 0;
# Line 66 | Line 67 | begin
67   end;
68  
69  
70 + procedure TForm_TxmpReplace.Splitter1Moved(Sender: TObject);
71 + begin
72 +  inherited;
73 +  image_txmppreview.Picture.Assign(nil);
74 +  image_bmppreview.Picture.Assign(nil);
75 +  if Length(OniImage_Old.Images) > 0 then
76 +    OniImage_Old.DrawOnCanvas(image_txmppreview.Canvas, 1);
77 +  if Length(OniImage_New.Images) > 0 then
78 +    OniImage_New.DrawOnCanvas(image_bmppreview.Canvas, 1);
79 + end;
80 +
81   procedure TForm_TxmpReplace.btn_loadClick(Sender: TObject);
82   var
83    mem:   TMemoryStream;
# Line 73 | Line 85 | begin
85    if opend.Execute then
86    begin
87      OniImage_New.LoadFromFile(opend.FileName);
88 <    OniImage_New.DrawOnCanvas(image_bmppreview.Canvas, 0);
88 >    OniImage_New.DrawOnCanvas(image_bmppreview.Canvas, 1);
89      group_options.Enabled := True;
90    end;
91   end;
# Line 88 | Line 100 | var
100    oldfading: Byte;
101    datbyte: Word;
102    mem: TMemoryStream;
103 +  new_storetype: Byte;
104 +  formatinfo: TImageFormatInfo;
105   begin
106    if filelist.ItemIndex >= 0 then
107    begin
# Line 114 | Line 128 | begin
128  
129      mem := TMemoryStream.Create;
130  
131 +    case OniImage_New.Format of
132 +      ifX1R5G5B5: new_storetype := 1;
133 +      ifA1R5G5B5: new_storetype := 2;
134 +      ifA4R4G4B4: new_storetype := 0;
135 +      ifA8R8G8B8:
136 +        begin
137 +          new_storetype := 8;
138 +          OniImage_New.Format := ifX8R8G8B8;
139 +        end;
140 +      ifX8R8G8B8: new_storetype := 8;
141 +      ifDXT1: new_storetype := 9;
142 +    else
143 +      if OniImage_New.FormatInfo.HasAlphaChannel then
144 +        ShowMessage('Loaded image has an alpha-channel.' + #13#10 +
145 +                    'Because the format is neither ARGB1555' +#13#10 +
146 +                    'nor ARGB4444 it can not be imported without conversion.' + #13#10 +
147 +                    'It is converted to RGB888, so alpha gets dropped.' + #13#10 +
148 +                    'If you need alpha you have to save your image in' + #13#10 +
149 +                    'one of the previously named formats.');  
150 +      OniImage_New.Format := ifX8R8G8B8;
151 +      new_storetype := 8;
152 +    end;
153 +
154      OniImage_New.SaveDataToStream(check_fading.Checked, TStream(mem));
155  
156      newsize := mem.Size;
# Line 121 | Line 158 | begin
158  
159      if (newsize > old_size) and (ConManager.Connection[ConnectionID].Backend = DB_ONI) then
160        new_rawaddr := ConManager.Connection[ConnectionID].AppendRawFile(
161 <        not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN),
125 <        mem.Size, mem)
161 >        not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN), mem)
162      else
163      begin
164        new_rawaddr := old_rawaddr;
165        ConManager.Connection[ConnectionID].UpdateRawFile(fileid, $9C, mem);
166      end;
167  
132    datbyte := $00;
168      if check_fading.Checked then
169 <      datbyte := datbyte or $01;
169 >      oldfading := oldfading or $01
170 >    else
171 >      oldfading := oldfading and (not Byte($01));
172      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $88, 1, @datbyte);
173      datbyte := $10;
174   //    if check_transparency.Checked then
# Line 141 | Line 178 | begin
178      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8C, 2, @datbyte);
179      datbyte := OniImage_New.Height[1];
180      ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $8E, 2, @datbyte);
181 <    case OniImage_New.Format of
145 <      ifA1R5G5B5: datbyte := 2;
146 <      ifA4R4G4B4: datbyte := 0;
147 <      ifA8R8G8B8:
148 <        begin
149 <          datbyte := 8;
150 <          OniImage_New.Format := ifX8R8G8B8;
151 <        end;
152 <      ifX8R8G8B8: datbyte := 8;
153 <      ifDXT1: datbyte := 9;
154 <    else
155 <      OniImage_New.Format := ifX8R8G8B8;
156 <      datbyte := 8;
157 <    end;
158 <    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @datbyte);
181 >    ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $90, 1, @new_storetype);
182      if not (ConManager.Connection[ConnectionID].DataOS = DOS_WIN) then
183        ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $A0, 4, @new_rawaddr)
184      else
185        ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, $9C, 4, @new_rawaddr);
186  
187      ShowMessage('TXMP-image replaced');
188 +    Self.listClick(Self);
189    end;
190   end;
191  

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)