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

Comparing:
oup/rewrite/Global/OniImgClass.pas (file contents), Revision 97 by alloc, Mon Jan 22 23:05:45 2007 UTC vs.
oup/current/Global/OniImgClass.pas (file contents), Revision 198 by alloc, Sat May 26 19:28:08 2007 UTC

# Line 2 | Line 2 | unit OniImgClass;
2  
3   interface
4  
5 < uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs;
5 > uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs,
6 >  Imaging, ImagingTypes, Graphics;
7  
7 type
8  TImgDataType = set of (DT_OniReverted, DT_Oni, DT_Decoded32);
8  
9   type
10    TOniImage = class
11    private
12 <    FLoaded:    Boolean;
13 <    FDataType:  TImgDataType;
14 <    FData:      TByteData;
15 <    FWidth, FHeight: Word;
16 <    FDepth:     Byte;
17 <    FStoreType: Byte;
18 <
19 <    function ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData;
21 <    procedure RevertImage;
22 <    procedure DecodeImage;
23 <    procedure DecompressImage;
12 >    FImages: TDynImageDataArray;
13 >    function GetImage(MipGen: Integer): TImageData;
14 >    function GetWidth(MipGen: Integer): Integer;
15 >    function GetHeight(MipGen: Integer): Integer;
16 >    function GetImageFormat: TImageFormat;
17 >    procedure SetImageFormat(Format: TImageFormat);
18 >    function pGetImageFormatInfo: TImageFormatInfo;
19 >    function GetHasMipMaps: Boolean;
20    protected
21    public
22 <    property Loaded:    Boolean      Read FLoaded    Write FLoaded;
23 <    property DataType:  TImgDataType Read FDataType  Write FDataType;
24 <    property Width:     Word         Read FWidth     Write FWidth;
25 <    property Height:    Word         Read FHeight    Write FHeight;
26 <    property Depth:     Byte         Read FDepth     Write FDepth;
27 <    property StoreType: Byte         Read FStoreType Write FStoreType;
28 <    property Data:      TByteData    Read FData      Write FData;
22 >    property Images: TDynImageDataArray         read FImages;
23 >    property Image[MipGen: Integer]: TImageData read GetImage;
24 >    property Width[MipGen: Integer]: Integer    read GetWidth;
25 >    property Height[MipGen: Integer]: Integer   read GetHeight;
26 >    property Format: TImageFormat read GetImageFormat write SetImageFormat;
27 >    property FormatInfo: TImageFormatInfo read pGetImageFormatInfo;
28 >    property HasMipMaps: Boolean read GetHasMipMaps;
29  
30      constructor Create;
31 +    procedure Free;
32      function Load(ConnectionID, FileID: Integer): Boolean;
33      function LoadFromPSpc(ConnectionID, FileID: Integer): Boolean;
34      function LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
35      function LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
39    function GetImageDataSize(fading: Boolean): Integer;
36  
37 <    function GetAsData: TByteData;
38 <    function GetAs32bit: TByteData;
39 <    procedure GetAsBMP(var Target: TByteData); overload;
40 <    procedure GetAsBMP(var Target: TStream); overload;
41 <    function LoadFromBMP(filename: String): Boolean;
42 <    function WriteToBMP(filename: String): Boolean;
43 <    function GetMipMappedImage(var faded: TByteData): Boolean;
37 >    procedure SaveDataToStream(MipMaps: Boolean; var Target: TStream);
38 >
39 >    function LoadFromFile(filename: String): Boolean;
40 >    function WriteToFile(filename: String): Boolean;
41 >
42 >    procedure DrawOnCanvas(Canvas: TCanvas; Index: Integer);
43 >    function GetImageSize(MipMaps: Boolean): Integer;
44    published
45    end;
46  
47  
48   implementation
49  
50 < //uses Functions;
50 > uses Img_DDSTypes, ImagingComponents;
51 >
52  
53 + procedure TOniImage.DrawOnCanvas(Canvas: TCanvas; Index: Integer);
54 + var
55 +  singleimg: TImageData;
56 +  rect: TRect;
57 + begin
58 +  InitImage(singleimg);
59 +  CloneImage(FImages[Index-1], singleimg);
60 +  ConvertImage(singleimg, ifX8R8G8B8);
61 +  rect.Left := 0;
62 +  rect.Top := 0;
63 +  rect.Right := singleimg.Width - 1;
64 +  rect.Bottom := singleimg.Height - 1;
65 +  Canvas.Brush.Color := $C8D0D4;
66 +  Canvas.FillRect(Canvas.ClipRect);
67 +  DisplayImageData(Canvas, rect, singleimg, rect);
68 +  FreeImage(singleimg);
69 + end;
70  
71  
72  
73   constructor TOniImage.Create;
74   begin
61  Self.FLoaded   := False;
62  Self.FDataType := [];
63  SetLength(Self.FData, 0);
64  Self.FWidth     := 0;
65  Self.FHeight    := 0;
66  Self.FDepth     := 0;
67  Self.FStoreType := 0;
75   end;
76  
77  
78  
79 + procedure TOniImage.Free;
80 + begin
81 +  FreeImagesInArray(FImages);
82 + end;
83  
84 < function TOniImage.ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData;
85 < var
86 <  i, j: Integer;
87 <  col, row, row_orig: Integer;
84 >
85 >
86 >
87 > function TOniImage.GetImage(MipGen: Integer): TImageData;
88   begin
89 <  SetLength(Result, (oldx div 2) * (oldy div 2) * (Self.FDepth div 8));
79 <  row_orig := 0;
80 <  row      := 0;
81 <  col      := 0;
82 <  for i := 0 to (oldx * oldy) - 1 do
89 >  if MipGen <= Length(FImages) then
90    begin
91 <    if ((i mod oldx) = 0) and (i > 0) then
92 <    begin
86 <      Inc(row_orig);
87 <      if (row_orig mod 2) = 0 then
88 <      begin
89 <        Inc(row);
90 <        col := 0;
91 <      end;
92 <    end;
93 <    if (row_orig mod 2) = 0 then
94 <    begin
95 <      if (i mod 2) = 0 then
96 <      begin
97 <        for j := 0 to (Self.FDepth div 8) - 1 do
98 <          Result[((row * (oldx div 2)) + col) * (Self.FDepth div 8) + j] :=
99 <            img[(i * (Self.FDepth div 8)) + j];
100 <        Inc(col);
101 <      end;
102 <    end;
91 >    InitImage(Result);
92 >    CloneImage(FImages[MipGen-1], Result);
93    end;
94   end;
95  
96  
97  
98 <
109 < procedure TOniImage.RevertImage;
110 < var
111 <  x, y, i: Integer;
112 <  tempd:   TByteData;
98 > function TOniImage.GetWidth(MipGen: Integer): Integer;
99   begin
100 <  SetLength(tempd, Self.FWidth * Self.FHeight * (Self.FDepth div 8));
101 <  for y := 0 to Self.FHeight - 1 do
116 <    for x := 0 to Self.FWidth - 1 do
117 <      for i := 0 to (Self.FDepth div 8) - 1 do
118 <        tempd[((Self.FWidth * (Self.FHeight - 1 - y) + x) * (Self.FDepth div 8)) + i] :=
119 <          Self.FData[(Self.FWidth * y + x) * (Self.FDepth div 8) + i];
120 <  for x := 0 to High(tempd) do
121 <    Self.FData[x] := tempd[x];
122 <  if DT_OniReverted in Self.FDataType then
123 <    Self.FDataType := Self.FDataType - [DT_OniReverted]
100 >  if MipGen <= Length(FImages) then
101 >    Result := FImages[MipGen-1].Width
102    else
103 <    Self.FDataType := Self.FDataType + [DT_OniReverted];
103 >    Result := -1;
104   end;
105  
106  
107 <
130 <
131 < procedure TOniImage.DecodeImage;
132 < var
133 <  x, y:  Integer;
134 <  tempd: TByteData;
107 > function TOniImage.GetHeight(MipGen: Integer): Integer;
108   begin
109 <  if not (DT_Decoded32 in Self.FDataType) then
110 <  begin
111 <    SetLength(tempd, Self.FWidth * Self.FHeight * 4);
112 <    case Self.FStoreType of
140 <      0:
141 <      begin
142 <        for y := 0 to Self.FHeight - 1 do
143 <        begin
144 <          for x := 0 to Self.FWidth - 1 do
145 <          begin
146 <            tempd[((Self.FWidth * y + x) * 4) + 0] :=
147 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
148 <              $000F) / $000F * 255);
149 <            tempd[((Self.FWidth * y + x) * 4) + 1] :=
150 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
151 <              $00F0) / $00F0 * 255);
152 <            tempd[((Self.FWidth * y + x) * 4) + 2] :=
153 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
154 <              $0F00) / $0F00 * 255);
155 <            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
156 <          end;
157 <        end;
158 <      end;
159 <      1, 2:
160 <      begin
161 <        for y := 0 to Self.FHeight - 1 do
162 <        begin
163 <          for x := 0 to Self.FWidth - 1 do
164 <          begin
165 <            tempd[((Self.FWidth * y + x) * 4) + 0] :=
166 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
167 <              $001F) / $001F * 255);
168 <            tempd[((Self.FWidth * y + x) * 4) + 1] :=
169 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
170 <              $03E0) / $03E0 * 255);
171 <            tempd[((Self.FWidth * y + x) * 4) + 2] :=
172 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
173 <              $7C00) / $7C00 * 255);
174 <            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
175 <          end;
176 <        end;
177 <      end;
178 <      9:
179 <      begin
180 <        DecompressImage;
181 <      end;
182 <    end;
183 <    Self.FDepth := 32;
184 <    if (Self.FStoreType <> 9) and (Self.FStoreType <> 8) then
185 <    begin
186 <      SetLength(Self.FData, Length(tempd));
187 <      for x := 0 to High(tempd) do
188 <        Self.FData[x] := tempd[x];
189 <    end;
190 <    Self.FStoreType := 8;
191 <    if DT_Oni in Self.FDataType then
192 <      Self.FDataType := Self.FDataType - [DT_Oni];
193 <    Self.FDataType := Self.FDataType + [DT_Decoded32];
194 <  end;
195 <  if DT_OniReverted in Self.FDataType then
196 <    Self.RevertImage;
109 >  if MipGen <= Length(FImages) then
110 >    Result := FImages[MipGen-1].Height
111 >  else
112 >    Result := -1;
113   end;
114  
115  
116 + function TOniImage.GetImageFormat: TImageFormat;
117 + begin
118 +  if Length(FImages) > 0 then
119 +    Result := FImages[0].Format
120 +  else
121 +    Result := ifUnknown;
122 + end;
123  
124 <
202 < procedure TOniImage.DecompressImage;
203 < type
204 <  Tcolor = record
205 <    RGBb: Byte;
206 <    RGBg: Byte;
207 <    RGBr: Byte;
208 <    RGBa: Byte;
209 <  end;
124 > procedure TOniImage.SetImageFormat(Format: TImageFormat);
125   var
126 <  i, j, x, y: Integer;
212 <  color:      array[1..4] of Tcolor;
213 <  pixel:      array[1..16] of Byte;
214 <  tempd:      TByteData;
126 >  i: Integer;
127   begin
128 <  x := 0;
129 <  y := 0;
130 <  SetLength(tempd, Self.FWidth * Self.FHeight * 4);
219 <  for i := 0 to ((Self.FWidth * Self.FHeight) div 16) - 1 do
220 <  begin
221 <    Color[1].RGBb := Round(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $001F) /
222 <      $001F * 255);
223 <    Color[1].RGBg := Round(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $07E0) /
224 <      $07E0 * 255);
225 <    Color[1].RGBr := Round(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $F800) /
226 <      $F800 * 255);
227 <    Color[1].RGBa := 255;
228 <    Color[2].RGBb := Round(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $001F) /
229 <      $001F * 255);
230 <    Color[2].RGBg := Round(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $07E0) /
231 <      $07E0 * 255);
232 <    Color[2].RGBr := Round(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $F800) /
233 <      $F800 * 255);
234 <    Color[2].RGBa := 255;
235 <    Color[3].RGBb := Round(Color[1].RGBb / 3 * 2 + Color[2].RGBb / 3);
236 <    Color[3].RGBg := Round(Color[1].RGBg / 3 * 2 + Color[2].RGBg / 3);
237 <    Color[3].RGBr := Round(Color[1].RGBr / 3 * 2 + Color[2].RGBr / 3);
238 <    Color[3].RGBa := 255;
239 <    Color[4].RGBb := Round(Color[1].RGBb / 3 + Color[2].RGBb / 3 * 2);
240 <    Color[4].RGBg := Round(Color[1].RGBg / 3 + Color[2].RGBg / 3 * 2);
241 <    Color[4].RGBr := Round(Color[1].RGBr / 3 + Color[2].RGBr / 3 * 2);
242 <    Color[4].RGBa := 255;
243 <    Pixel[1]      := Round((Self.FData[(i * 8) + 4] and $C0) / $40 + 1);
244 <    Pixel[2]      := Round((Self.FData[(i * 8) + 4] and $30) / $10 + 1);
245 <    Pixel[3]      := Round((Self.FData[(i * 8) + 4] and $0C) / $04 + 1);
246 <    Pixel[4]      := Round((Self.FData[(i * 8) + 4] and $03) + 1);
247 <    Pixel[5]      := Round((Self.FData[(i * 8) + 5] and $C0) / $40 + 1);
248 <    Pixel[6]      := Round((Self.FData[(i * 8) + 5] and $30) / $10 + 1);
249 <    Pixel[7]      := Round((Self.FData[(i * 8) + 5] and $0C) / $04 + 1);
250 <    Pixel[8]      := Round((Self.FData[(i * 8) + 5] and $03) + 1);
251 <    Pixel[9]      := Round((Self.FData[(i * 8) + 6] and $C0) / $40 + 1);
252 <    Pixel[10]     := Round((Self.FData[(i * 8) + 6] and $30) / $10 + 1);
253 <    Pixel[11]     := Round((Self.FData[(i * 8) + 6] and $0C) / $04 + 1);
254 <    Pixel[12]     := Round((Self.FData[(i * 8) + 6] and $03) + 1);
255 <    Pixel[13]     := Round((Self.FData[(i * 8) + 7] and $C0) / $40 + 1);
256 <    Pixel[14]     := Round((Self.FData[(i * 8) + 7] and $30) / $10 + 1);
257 <    Pixel[15]     := Round((Self.FData[(i * 8) + 7] and $0C) / $04 + 1);
258 <    Pixel[16]     := Round((Self.FData[(i * 8) + 7] and $03) + 1);
259 <    for j := 0 to 3 do
260 <    begin
261 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[16 - j]].RGBb;
262 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[16 - j]].RGBg;
263 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[16 - j]].RGBr;
264 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 3] := 0;
265 <    end;
266 <    for j := 0 to 3 do
267 <    begin
268 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[12 - j]].RGBb;
269 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[12 - j]].RGBg;
270 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[12 - j]].RGBr;
271 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 3] := 0;
272 <    end;
273 <    for j := 0 to 3 do
274 <    begin
275 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[8 - j]].RGBb;
276 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[8 - j]].RGBg;
277 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[8 - j]].RGBr;
278 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 3] := 0;
279 <    end;
280 <    for j := 0 to 3 do
281 <    begin
282 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[4 - j]].RGBb;
283 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[4 - j]].RGBg;
284 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[4 - j]].RGBr;
285 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 3] := 0;
286 <    end;
287 <    x := x + 4;
288 <    if x = Self.FWidth then
289 <    begin
290 <      y := y + 4;
291 <      x := 0;
292 <    end;
293 <  end;
294 <  SetLength(Self.FData, Length(tempd));
295 <  for i := 0 to High(tempd) do
296 <    Self.FData[i] := tempd[i];
297 <  Self.FStoreType := 8;
298 <  Self.FDepth    := 32;
299 <  Self.FDataType := Self.FDataType - [DT_Oni] + [DT_Decoded32];
128 >  if Length(FImages) > 0 then
129 >    for i := 0 to High(FImages) do
130 >      ConvertImage(FImages[i], Format);
131   end;
132  
133  
134 + function TOniImage.pGetImageFormatInfo: TImageFormatInfo;
135 + begin
136 +  if Length(FImages) > 0 then
137 +    GetImageFormatInfo(FImages[0].Format, Result);
138 + end;
139  
140  
141 + function TOniImage.GetHasMipMaps: Boolean;
142 + begin
143 +  Result := Length(FImages) > 1;
144 + end;
145 +
146  
147   function TOniImage.Load(ConnectionID, FileID: Integer): Boolean;
148   var
149    FileInfo: TFileInfo;
309  ext:      String;
150   begin
151    FileInfo := ConManager.Connection[ConnectionID].GetFileInfo(fileid);
152    if FileInfo.Extension = 'PSpc' then
# Line 338 | Line 178 | type
178      x_txmp, y_txmp: Word;
179      x_pspc, y_pspc: Word;
180      w, h:    Word;
181 <    imgdata: TByteData;
181 >    imgdata: TImageData;
182      used:    Boolean;
183    end;
184   const
185    PartMatch: array[0..8] of Byte = (0, 3, 6, 1, 4, 7, 2, 5, 8);
186 +  stretch_x: Integer = 50;
187 +  stretch_y: Integer = 1;
188   var
189 <  x, y, pixel: Word;
189 >  x, y: Word;
190    i: Integer;
191  
192    PSpc:     TPSpc;
193    txmpimg:  TOniImage;
194 <  txmpdata: TByteData;
194 > //  txmpdata: TByteData;
195  
196    parts:    array[0..8] of TPart;
197    part:     Byte;
198    cols:     array[0..2] of Word;
199    rows:     array[0..2] of Word;
200    col, row: Byte;
201 +
202 +  pspcimage: TImageData;
203   begin
204    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
205    PSpc.TXMP := PSpc.TXMP div 256;
# Line 365 | Line 209 | begin
209      Exit;
210    end;
211    txmpimg := TOniImage.Create;
212 <  txmpimg.LoadFromTXMP(ConnectionID, PSpc.TXMP);
213 <  txmpimg.DecodeImage;
214 < //  txmpimg.WriteToBMP('C:\file.bmp');
215 <  txmpdata := txmpimg.GetAs32bit;
216 < {    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
373 <    for i:=0 to High(txmpdata) do
374 <      txmpimg.Data[i]:=txmpdata[i];
375 <    txmpimg.WriteToBMP('D:\file2.bmp');
376 < }
377 <  with PSpc do
212 >  txmpimg.Load(ConnectionID, PSpc.TXMP);
213 >  CloneImage(txmpimg.Image[1], pspcimage);
214 >  txmpimg.Free;
215 >
216 >  with pspc do
217    begin
218      for i := 0 to 2 do
219      begin
# Line 403 | Line 242 | begin
242          parts[part].used := True;
243          cols[col] := parts[part].w;
244          rows[row] := parts[part].h;
245 <        SetLength(parts[part].imgdata, parts[part].w * parts[part].h * 4);
246 <        for y := 0 to parts[part].h - 1 do
247 <        begin
248 <          for x := 0 to parts[part].w - 1 do
249 <          begin
250 <            for pixel := 0 to 3 do
412 <            begin
413 <              parts[part].imgdata[(y * parts[part].w + x) * 4 + pixel] :=
414 <                txmpdata[((parts[part].y_txmp + y) * txmpimg.Width +
415 <                parts[part].x_txmp + x) * 4 + pixel];
416 <            end;
417 <          end;
418 <        end;
245 >
246 >        NewImage(parts[part].w, parts[part].h, pspcimage.Format, parts[part].imgdata);
247 >
248 >        CopyRect(pspcimage,
249 >            parts[part].x_txmp, parts[part].y_txmp, parts[part].w, parts[part].h,
250 >            parts[part].imgdata, 0, 0);
251        end
252        else
253        begin
# Line 425 | Line 257 | begin
257  
258    end;
259  
428  txmpimg.Free;
429  txmpimg := TOniImage.Create;
260    for i := 0 to 8 do
261    begin
262      if parts[i].used then
263      begin
264 <      SetLength(txmpimg.FData, Length(parts[i].imgdata));
435 <      for pixel := 0 to High(parts[i].imgdata) do
436 <        txmpimg.Data[pixel] := parts[i].imgdata[pixel];
437 <      txmpimg.Width := parts[i].w;
438 <      txmpimg.Height    := parts[i].h;
439 <      txmpimg.StoreType := 8;
440 <      txmpimg.DataType  := [DT_Decoded32];
441 <      txmpimg.Depth     := 32;
442 <      txmpimg.WriteToBMP('M:\' + IntToStr(i) + '.bmp');
264 > //      SaveImageToFile('M:\' + IntToStr(i) + '.bmp', parts[i].imgdata);
265      end;
266    end;
445  txmpimg.Free;
267  
268 <  Self.FWidth  := 0;
269 <  Self.FHeight := 0;
270 <  for i := 0 to 2 do
268 >  SetLength(FImages, 1);
269 >  x := cols[0] + cols[1] * stretch_x + cols[2];
270 >  y := rows[0] + rows[1] * stretch_y + rows[2];
271 >
272 >  NewImage(x, y, pspcimage.Format, FImages[0]);
273 >
274 >  x := 0;
275 >  for col := 0 to 2 do
276    begin
277 <    Inc(Self.FWidth, cols[i]);
278 <    Inc(Self.FHeight, rows[i]);
277 >    y := 0;
278 >    for row := 0 to 2 do
279 >    begin
280 >      part := row*3 + col;
281 >      if (row = 1) and (col = 1) then
282 >        StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
283 >            FImages[0], x, y, parts[part].w * stretch_x, parts[part].h * stretch_y, rfNearest)
284 >      else
285 >      if (row = 1) then
286 >        StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
287 >            FImages[0], x, y, parts[part].w, parts[part].h * stretch_y, rfNearest)
288 >      else
289 >      if (col = 1) then
290 >        StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
291 >            FImages[0], x, y, parts[part].w * stretch_x, parts[part].h, rfNearest)
292 >      else
293 >        CopyRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
294 >            FImages[0], x, y );
295 >      if row = 1 then
296 >        y := y + parts[part].h * stretch_y
297 >      else
298 >        y := y + parts[part].h;
299 >    end;
300 >    if (part mod 3) = 1 then
301 >      x := x + parts[part].w * stretch_x
302 >    else
303 >      x := x + parts[part].w;
304    end;
454  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
455
456  //Combine data parts
305  
306 <  Self.FDepth     := 32;
307 <  Self.FStoreType := 8;
308 <  Self.FDataType  := [DT_Decoded32];
309 <  //    Self.RevertImage;
306 >  FreeImage(pspcimage);
307 >  for i := 0 to 8 do
308 >    if parts[i].used then
309 >      FreeImage(parts[i].imgdata);
310   end;
311  
312  
# Line 467 | Line 315 | end;
315   function TOniImage.LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
316   var
317    img_addr: Integer;
318 +  data: TMemoryStream;
319 +  hdr: TDDSDXTHeader;
320 +  imginfo: Integer;
321 +  x,y, i: Integer;
322 +
323 +  _width, _height: Word;
324 +  _storetype: Byte;
325 +  _depth: Byte;
326   begin
327    Result := True;
328 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
329 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
330 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
331 <    @Self.FStoreType);
328 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(_width), @_width);
329 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(_height), @_height);
330 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(_storetype), @_storetype);
331 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(imginfo), @imginfo);
332    if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
333      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
334    else
335      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
336  
337 <  case Self.FStoreType of
337 >  case _storetype of
338      0, 1, 2:
339 <    begin
340 <      SetLength(Self.FData, Self.FWidth * Self.FHeight * 2);
341 <      Self.FDepth := 16;
486 <    end;
487 <    8:
488 <    begin
489 <      SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
490 <      Self.FDepth := 32;
491 <    end;
339 >      _depth := 16;
340 >    7, 8:
341 >      _depth := 32;
342      9:
343 <    begin
494 <      SetLength(Self.FData, Self.FWidth * Self.FHeight div 2);
495 <      Self.FDepth := 16;
496 <    end;
343 >      _depth := 16;
344      else
345        Result := False;
346        Exit;
347    end;
348  
349 +  with hdr do
350 +  begin
351 +    FOURCC := 'DDS ';
352 +    with SURFACEDESC2 do
353 +    begin
354 +      Size := 124;
355 +      Flags := DDSD_CAPS or DDSD_PIXELFORMAT or DDSD_WIDTH or DDSD_HEIGHT;
356 +      if _storetype = 9 then
357 +        Flags := Flags or DDSD_LINEARSIZE
358 +      else
359 +        Flags := Flags or DDSD_PITCH;
360 +      if (imginfo and $01) > 0 then
361 +        Flags := Flags or DDSD_MIPMAPCOUNT;
362 +      Height := _height;
363 +      Width := _width;
364 +      if _storetype = 9 then
365 +        PitchOrLinearSize := width * height div 2
366 +      else
367 +        PitchOrLinearSize := width * _depth div 8;
368 +      Depth := 0;
369 +      MipMapCount := 1;
370 +      if (imginfo and $01) > 0 then
371 +      begin
372 +        x := width;
373 +        y := height;
374 +        while (x > 1) and (y > 1) do
375 +        begin
376 +          x := x div 2;
377 +          y := y div 2;
378 +          Inc(MipMapCount);
379 +        end;
380 +      end;
381 +      for i := 1 to 11 do
382 +        Reserved[i] := 0;
383 +      with PIXELFORMAT do
384 +      begin
385 +        Size := 32;
386 +        if _storetype = 9 then
387 +          Flags := DDPF_FOURCC
388 +        else
389 +          Flags := DDPF_RGB;
390 +        if _storetype in [0, 2] then
391 +          Flags := Flags or DDPF_ALPHAPIXELS;
392 +        if _storetype = 9 then
393 +          FOURCC := 'DXT1'
394 +        else
395 +        begin
396 +          RGBBitCount := _depth;
397 +          case _storetype of
398 +            0: begin
399 +              RBitMask := $0F00;
400 +              GBitMask := $00F0;
401 +              BBitMask := $000F;
402 +              AlphaBitMask := $F000;
403 +            end;
404 +            1, 2: begin
405 +              RBitMask := $7C00;
406 +              GBitMask := $03E0;
407 +              BBitMask := $001F;
408 +              if _storetype = 2 then
409 +                AlphaBitMask := $8000
410 +              else
411 +                AlphaBitMask := $0000;
412 +            end;
413 +            8: begin
414 +              RBitMask := $00FF0000;
415 +              GBitMask := $0000FF00;
416 +              BBitMask := $000000FF;
417 +              AlphaBitMask := $00000000;
418 +            end;
419 +          end;
420 +        end;
421 +      end;
422 +      with DDSCAPS2 do
423 +      begin
424 +        Caps1 := DDSCAPS_TEXTURE;
425 +        if (imginfo and $01) > 0 then
426 +          Caps1 := Caps1 or DDSCAPS_COMPLEX or DDSCAPS_MIPMAP;
427 +        Caps2 := 0;
428 +        Reserved[1] := 0;
429 +        Reserved[2] := 0;
430 +      end;
431 +    end;
432 +  end;
433 +
434 +  data := TMemoryStream.Create;
435 +  data.Write(hdr, SizeOf(hdr));
436    if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
437 <    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, FData)
437 >    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data))
438    else
439 <    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, FData);
439 >    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data));
440  
441 <  Self.FDataType := [DT_OniReverted, DT_Oni];
441 > //  data.Seek(0, soFromBeginning);
442 > //  data.SaveToFile('m:\test.txmp');
443 >
444 >  data.Seek(0, soFromBeginning);
445 >  result := LoadMultiImageFromStream(data, FImages);
446 >  data.Free;
447 > {
448 >  if result then
449 >  begin
450 >    for i := 0 to High(FImages) do
451 >    begin
452 >      data := TMemoryStream.Create;
453 >      data.Write(FImages[i].Bits^, FImages[i].Size);
454 >      data.Seek(0, soFromBeginning);
455 >      data.SaveToFile('m:\test.txmp.'+IntToStr(i));
456 >      data.Free;
457 >    end;
458 >  end;
459 > }
460 >  if not result then
461 >  begin
462 >    ShowMessage('Error while loading file' + #13#10 + DetermineStreamFormat(data));
463 > //    data.SaveToFile('m:\prob.dds');
464 >  end;
465   end;
466  
467  
# Line 512 | Line 469 | end;
469  
470   function TOniImage.LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
471   var
472 <  i, x, y, x2, y2, pixelid, imgid: Integer;
472 >  i, x, y, imgid: Integer;
473    rows, cols: Word;
474    linkcount: Integer;
475    link: Integer;
476 <  images_decoded: array of TOniImage;
476 >  images: array of TOniImage;
477    x_start, y_start: Integer;
478 +
479 +  width, height: Word;
480   begin
481 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
482 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
481 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, SizeOf(width), @width);
482 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $12, SizeOf(height), @height);
483    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
484    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
485    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
486 <  SetLength(images_decoded, linkcount);
486 >  SetLength(images, linkcount);
487    for i := 0 to linkcount - 1 do
488    begin
489      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
490      link := link div 256;
491 <    images_decoded[i] := TOniImage.Create;
492 <    images_decoded[i].LoadFromTXMP(ConnectionID, link);
493 <    images_decoded[i].DecodeImage;
494 <    images_decoded[i].RevertImage;
491 >    images[i] := TOniImage.Create;
492 >    images[i].LoadFromTXMP(ConnectionID, link);
493 >    SetLength(FImages, 1);
494 >    NewImage(width, height, ifA1R5G5B5, FImages[0]);
495    end;
537  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
496    for y := 0 to rows - 1 do
497    begin
498      for x := 0 to cols - 1 do
499      begin
500 <      imgid   := y * cols + x;
500 >      imgid := y * cols + x;
501        x_start := 0;
502        y_start := 0;
503        for i := 0 to x do
504          if i < x then
505 <          x_start := x_start + images_decoded[i].Width;
505 >          x_start := x_start + images[i].Image[0].Width;
506        for i := 0 to y do
507          if i < y then
508 <          y_start := y_start + images_decoded[i].Height;
509 <      for y2 := 0 to images_decoded[imgid].Height - 1 do
510 <      begin
553 <        for x2 := 0 to images_decoded[imgid].Width - 1 do
554 <        begin
555 <          if ((x_start + x2) < Self.FWidth) and ((y_start + y2) < Self.FHeight) then
556 <          begin
557 <            pixelid := y_start * Self.FWidth + x_start + y2 * Self.FWidth + x2;
558 <            Self.FData[pixelid * 4 + 0] :=
559 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 0];
560 <            Self.FData[pixelid * 4 + 1] :=
561 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 1];
562 <            Self.FData[pixelid * 4 + 2] :=
563 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 2];
564 <            Self.FData[pixelid * 4 + 3] :=
565 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 3];
566 <          end;
567 <        end;
568 <      end;
508 >          y_start := y_start + images[i].Image[0].Height;
509 >      CopyRect(images[imgid].Image[0], 0, 0, images[imgid].Image[0].Width,
510 >          images[imgid].Image[0].Height, FImages[0], x_start, y_start);
511      end;
512    end;
513    for i := 0 to linkcount - 1 do
514 <    images_decoded[i].Free;
573 <  Self.FDepth     := 32;
574 <  Self.FStoreType := 8;
575 <  Self.FDataType  := [DT_Decoded32];
576 <  Self.RevertImage;
514 >    images[i].Free;
515   end;
516  
517  
518  
519 <
582 < function TOniImage.GetImageDataSize(fading: Boolean): Integer;
519 > procedure TOniImage.SaveDataToStream(MipMaps: Boolean; var Target: TStream);
520   var
521 <  size: Integer;
522 <  x, y: Word;
523 <  bpp:  Byte;
521 >  images: TDynImageDataArray;
522 >  mem: TMemoryStream;
523 >  i: Integer;
524   begin
525 <  case Self.FStoreType of
526 <    9:
527 <      bpp := 8;
528 <    0, 1, 2:
529 <      bpp := 16;
530 <    8:
531 <      bpp := 32;
525 >  if Length(FImages) = 0 then
526 >    Exit;
527 >  if MipMaps then
528 >  begin
529 >    if Length(FImages) = 1 then
530 >    begin
531 >      if not GenerateMipMaps(FImages[0], 0, images) then
532 >      begin
533 >        ShowMessage('Could not generate MipMaps');
534 >        Exit;
535 >      end;
536 >    end
537      else
538 <      Result := 0;
538 >    begin
539 >      SetLength(images, Length(FImages));
540 >      for i := 0 to High(FImages) do
541 >        CloneImage(FImages[i], images[i]);
542 >    end;
543 >    mem := TMemoryStream.Create;
544 >    if not SaveMultiImageToStream('dds', mem, images) then
545 >    begin
546 >      ShowMessage('Could not save images to stream');
547        Exit;
548 <  end;
549 <
600 <  x    := Self.FWidth;
601 <  y    := Self.FHeight;
602 <  size := x * y * bpp div 8;
603 <  if fading then
604 <  begin
605 <    repeat
606 <      x    := x div 2;
607 <      y    := y div 2;
608 <      size := size + x * y * bpp div 8;
609 <    until (x = 1) or (y = 1);
610 <  end;
611 <  Result := size;
612 < end;
613 <
614 <
615 <
616 <
617 < function TOniImage.GetAsData: TByteData;
618 < var
619 <  i:      Integer;
620 <  revert: Boolean;
621 < begin
622 <  //    if not (DT_Decoded32 in Self.FDataType) then
623 <  //      Self.DecodeImage;
624 <  if not (DT_OniReverted in Self.FDataType) then
625 <  begin
626 <    revert := True;
627 <    Self.RevertImage;
548 >    end;
549 >    FreeImagesInArray(images);
550    end
551    else
630    revert := False;
631  SetLength(Result, Length(Self.FData));
632  for i := 0 to High(Result) do
633    Result[i] := Self.FData[i];
634  if revert then
635    Self.RevertImage;
636 end;
637
638
639
640
641 function TOniImage.GetAs32bit: TByteData;
642 var
643  i: Integer;
644 begin
645  if not (DT_Decoded32 in Self.FDataType) then
646    Self.DecodeImage;
647  SetLength(Result, Length(Self.FData));
648  for i := 0 to High(Result) do
649    Result[i] := Self.FData[i];
650 end;
651
652
653
654
655 procedure TOniImage.GetAsBMP(var Target: TByteData);
656 const
657  BMPheader: array[0..53] of Byte =
658    ($42, $4D, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0,
659    40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, $18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
660    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
661 var
662  i, x, y: Integer;
663 begin
664  if not (DT_Decoded32 in Self.FDataType) then
665    Self.DecodeImage;
666
667  SetLength(Target, Self.FWidth * Self.FHeight * 3 + 54);
668  for y := 0 to Self.FHeight - 1 do
552    begin
553 <    for x := 0 to Self.FWidth - 1 do
553 >    mem := TMemoryStream.Create;
554 >    if not SaveImageToStream('dds', mem, FImages[0]) then
555      begin
556 <      Target[((Self.FWidth * y + x) * 3) + 0 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 0];
557 <      Target[((Self.FWidth * y + x) * 3) + 1 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 1];
674 <      Target[((Self.FWidth * y + x) * 3) + 2 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 2];
556 >      ShowMessage('Could not save image to stream');
557 >      Exit;
558      end;
559    end;
560 +  if not Assigned(Target) then
561 +    Target := TMemoryStream.Create;
562  
563 <  for i := 0 to High(BMPheader) do
564 <    Target[i] := BMPheader[i];
680 <  Target[2] := ((Self.FWidth * Self.FHeight * 3 + 54) and $000000FF) div $1;
681 <  Target[3]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $0000FF00) div $100;
682 <  Target[4]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $00FF0000) div $10000;
683 <  Target[5]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $FF000000) div $1000000;
684 <  Target[18] := (Self.FWidth and $000000FF) div $1;
685 <  Target[19] := (Self.FWidth and $0000FF00) div $100;
686 <  Target[20] := (Self.FWidth and $00FF0000) div $10000;
687 <  Target[21] := (Self.FWidth and $FF000000) div $1000000;
688 <  Target[22] := (Self.FHeight and $000000FF) div $1;
689 <  Target[23] := (Self.FHeight and $0000FF00) div $100;
690 <  Target[24] := (Self.FHeight and $00FF0000) div $10000;
691 <  Target[25] := (Self.FHeight and $FF000000) div $1000000;
692 <  Target[34] := ((Self.FWidth * Self.FHeight * 3) and $000000FF) div $1;
693 <  Target[35] := ((Self.FWidth * Self.FHeight * 3) and $0000FF00) div $100;
694 <  Target[36] := ((Self.FWidth * Self.FHeight * 3) and $00FF0000) div $10000;
695 <  Target[37] := ((Self.FWidth * Self.FHeight * 3) and $FF000000) div $1000000;
696 < end;
697 <
563 > //  mem.Seek(0, soFromBeginning);
564 > //  mem.SaveToFile('m:\dds.dds');
565  
566 < procedure TOniImage.GetAsBMP(var Target: TStream);
567 < var
568 <  data: TByteData;
569 < begin
703 <  GetAsBMP(data);
704 <  Target.Write(data[0], Length(data));
566 >  mem.Seek(128, soFromBeginning);
567 >  Target.CopyFrom(mem, mem.Size - 128);
568 >  mem.Free;
569 >  Target.Seek(0, soFromBeginning);
570   end;
571  
572  
573 < function TOniImage.LoadFromBMP(filename: String): Boolean;
709 < var
710 <  filestream: TFileStream;
711 <  tempd:      TByteData;
712 <
713 <  x, y: Integer;
573 > function TOniImage.LoadFromFile(filename: String): Boolean;
574   begin
575 <  filestream := TFileStream.Create(filename, fmOpenRead);
576 <  SetLength(tempd, filestream.Size);
717 <  filestream.Read(tempd[0], filestream.Size);
718 <  filestream.Free;
719 <
720 <  if not ((tempd[00] = $42) and (tempd[01] = $4D)) then
721 <  begin
722 <    Result := False;
723 <    ShowMessage('Not a standard 24bit bitmap');
724 <    Exit;
725 <  end;
726 <  if not (tempd[10] = 54) then
727 <  begin
728 <    Result := False;
729 <    ShowMessage('Imagedata has to start at 0x54');
730 <    Exit;
731 <  end;
732 <  if not (tempd[14] = 40) then
733 <  begin
734 <    Result := False;
735 <    ShowMessage('Second bitmap header has to have 40 bytes');
736 <    Exit;
737 <  end;
738 <  if not (tempd[28] = 24) then
739 <  begin
740 <    Result := False;
741 <    ShowMessage('Bitmap has to have 24bits');
742 <    Exit;
743 <  end;
744 <  if not (tempd[30] = 0) then
745 <  begin
746 <    Result := False;
747 <    ShowMessage('Bitmap has to be uncompressed');
748 <    Exit;
749 <  end;
750 <
751 <  Self.FWidth     := tempd[18] + tempd[19] * 256 + tempd[20] * 256 * 256 + tempd[21] * 256 * 256 * 256;
752 <  Self.FHeight    := tempd[22] + tempd[23] * 256 + tempd[24] * 256 * 256 + tempd[25] * 256 * 256 * 256;
753 <  Self.FDepth     := 32;
754 <  Self.FStoreType := 8;
755 <
756 <  SetLength(Self.FData, Self.FWidth * Self.FHeight * Self.FDepth div 8);
757 <  for y := 0 to Self.FHeight - 1 do
758 <  begin
759 <    for x := 0 to Self.FWidth - 1 do
760 <    begin
761 <      Self.FData[((Self.FWidth * y + x) * 4) + 0] := tempd[54 + (Self.FWidth * y + x) * 3 + 0];
762 <      Self.FData[((Self.FWidth * y + x) * 4) + 1] := tempd[54 + (Self.FWidth * y + x) * 3 + 1];
763 <      Self.FData[((Self.FWidth * y + x) * 4) + 2] := tempd[54 + (Self.FWidth * y + x) * 3 + 2];
764 <      Self.FData[((Self.FWidth * y + x) * 4) + 3] := 0;
765 <    end;
766 <  end;
767 <
768 <  Self.FDataType := [DT_Decoded32];
575 >  if not LoadMultiImageFromFile(filename, FImages) then
576 >    ShowMessage('Couldn''t load image file');
577   end;
578  
579  
580 <
773 <
774 < function TOniImage.WriteToBMP(filename: String): Boolean;
775 < var
776 <  filestream: TFileStream;
580 > function TOniImage.WriteToFile(filename: String): Boolean;
581   begin
582 <  filestream := TFileStream.Create(filename, fmCreate);
779 <  GetAsBMP(TStream(filestream));
780 <  filestream.Free;
582 >  SaveMultiImageToFile(filename, FImages);
583   end;
584  
585  
586  
587 <
786 < function TOniImage.GetMipMappedImage(var faded: TByteData): Boolean;
587 > function TOniImage.GetImageSize(MipMaps: Boolean): Integer;
588   var
589 <  i:      Integer;
590 <  x, y:   Word;
591 <  fadelvldata: TByteData;
791 <  revert: Boolean;
792 < begin
793 <  Result := False;
794 <
795 <  //    if not (DT_Decoded32 in Self.FDataType) then
796 <  //      Self.DecodeImage;
797 <  if Self.FStoreType = 9 then
798 <    Self.DecompressImage;
799 <  if not (DT_OniReverted in Self.FDataType) then
589 >  i: Integer;
590 > begin
591 >  if Length(FImages) > 0 then
592    begin
593 <    revert := True;
594 <    Self.RevertImage;
593 >    Result := FImages[0].Size;
594 >    if mipmaps then
595 >      for i := 1 to High(FImages) do
596 >        Result := Result + FImages[i].Size;
597    end
598    else
599 <    revert := False;
806 <
807 <  x := Self.FWidth;
808 <  y := Self.FHeight;
809 <  SetLength(faded, x * y * Self.FDepth div 8);
810 <  SetLength(fadelvldata, x * y * Self.FDepth div 8);
811 <  for i := 0 to Length(faded) - 1 do
812 <  begin
813 <    faded[i] := Self.FData[i];
814 <    fadelvldata[i] := Self.FData[i];
815 <  end;
816 <  repeat
817 <    fadelvldata := Self.ResizeImage(x, y, fadelvldata);
818 <    x := x div 2;
819 <    y := y div 2;
820 <    SetLength(faded, Length(faded) + x * y * Self.FDepth div 8);
821 <    for i := 0 to Length(fadelvldata) - 1 do
822 <      faded[Length(faded) - x * y * Self.FDepth div 8 + i] := fadelvldata[i];
823 <  until (x = 1) or (y = 1) or ((x mod 2) = 1) or ((y mod 2) = 1);
824 <  if (x > 1) and (y > 1) then
825 <    Exit;
826 <  Result := True;
827 <
828 <  if revert then
829 <    Self.RevertImage;
599 >    Result := -1;
600   end;
601  
832
602   end.

Diff Legend

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