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 105 by alloc, Wed Feb 21 00:29:27 2007 UTC vs.
oup/current/Global/OniImgClass.pas (file contents), Revision 199 by alloc, Sat May 26 20:41:34 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 <    procedure GetAsData(var Target: TStream); overload;
38 <    procedure GetAsData(var Target: TByteData); overload;
39 <    procedure GetAs32bit(var Target: TStream); overload;
40 <    procedure GetAs32bit(var Target: TByteData); overload;
41 <    procedure GetAsBMP(var Target: TStream); overload;
42 <    procedure GetAsBMP(var Target: TByteData); overload;
43 <    function LoadFromBMP(filename: String): Boolean;
48 <    function WriteToBMP(filename: String): Boolean;
49 <    function GetMipMappedImage(var Target: TStream): Boolean; overload;
50 <    function GetMipMappedImage(var Target: TByteData): Boolean; overload;
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
64  Self.FLoaded   := False;
65  Self.FDataType := [];
66  SetLength(Self.FData, 0);
67  Self.FWidth     := 0;
68  Self.FHeight    := 0;
69  Self.FDepth     := 0;
70  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));
82 <  row_orig := 0;
83 <  row      := 0;
84 <  col      := 0;
85 <  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
89 <      Inc(row_orig);
90 <      if (row_orig mod 2) = 0 then
91 <      begin
92 <        Inc(row);
93 <        col := 0;
94 <      end;
95 <    end;
96 <    if (row_orig mod 2) = 0 then
97 <    begin
98 <      if (i mod 2) = 0 then
99 <      begin
100 <        for j := 0 to (Self.FDepth div 8) - 1 do
101 <          Result[((row * (oldx div 2)) + col) * (Self.FDepth div 8) + j] :=
102 <            img[(i * (Self.FDepth div 8)) + j];
103 <        Inc(col);
104 <      end;
105 <    end;
91 >    InitImage(Result);
92 >    CloneImage(FImages[MipGen-1], Result);
93    end;
94   end;
95  
96  
97  
98 <
112 < procedure TOniImage.RevertImage;
113 < var
114 <  x, y, i: Integer;
115 <  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
119 <    for x := 0 to Self.FWidth - 1 do
120 <      for i := 0 to (Self.FDepth div 8) - 1 do
121 <        tempd[((Self.FWidth * (Self.FHeight - 1 - y) + x) * (Self.FDepth div 8)) + i] :=
122 <          Self.FData[(Self.FWidth * y + x) * (Self.FDepth div 8) + i];
123 <  for x := 0 to High(tempd) do
124 <    Self.FData[x] := tempd[x];
125 <  if DT_OniReverted in Self.FDataType then
126 <    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 <
133 <
134 < procedure TOniImage.DecodeImage;
135 < var
136 <  x, y:  Integer;
137 <  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
143 <      0:
144 <      begin
145 <        for y := 0 to Self.FHeight - 1 do
146 <        begin
147 <          for x := 0 to Self.FWidth - 1 do
148 <          begin
149 <            tempd[((Self.FWidth * y + x) * 4) + 0] :=
150 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
151 <              $000F) / $000F * 255);
152 <            tempd[((Self.FWidth * y + x) * 4) + 1] :=
153 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
154 <              $00F0) / $00F0 * 255);
155 <            tempd[((Self.FWidth * y + x) * 4) + 2] :=
156 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
157 <              $0F00) / $0F00 * 255);
158 <            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
159 <          end;
160 <        end;
161 <      end;
162 <      1, 2:
163 <      begin
164 <        for y := 0 to Self.FHeight - 1 do
165 <        begin
166 <          for x := 0 to Self.FWidth - 1 do
167 <          begin
168 <            tempd[((Self.FWidth * y + x) * 4) + 0] :=
169 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
170 <              $001F) / $001F * 255);
171 <            tempd[((Self.FWidth * y + x) * 4) + 1] :=
172 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
173 <              $03E0) / $03E0 * 255);
174 <            tempd[((Self.FWidth * y + x) * 4) + 2] :=
175 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
176 <              $7C00) / $7C00 * 255);
177 <            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
178 <          end;
179 <        end;
180 <      end;
181 <      9:
182 <      begin
183 <        DecompressImage;
184 <      end;
185 <    end;
186 <    Self.FDepth := 32;
187 <    if (Self.FStoreType <> 9) and (Self.FStoreType <> 8) then
188 <    begin
189 <      SetLength(Self.FData, Length(tempd));
190 <      for x := 0 to High(tempd) do
191 <        Self.FData[x] := tempd[x];
192 <    end;
193 <    Self.FStoreType := 8;
194 <    if DT_Oni in Self.FDataType then
195 <      Self.FDataType := Self.FDataType - [DT_Oni];
196 <    Self.FDataType := Self.FDataType + [DT_Decoded32];
197 <  end;
198 <  if DT_OniReverted in Self.FDataType then
199 <    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 <
205 < procedure TOniImage.DecompressImage;
206 < type
207 <  Tcolor = record
208 <    RGBb: Byte;
209 <    RGBg: Byte;
210 <    RGBr: Byte;
211 <    RGBa: Byte;
212 <  end;
124 > procedure TOniImage.SetImageFormat(Format: TImageFormat);
125   var
126 <  i, j, x, y: Integer;
215 <  color:      array[1..4] of Tcolor;
216 <  pixel:      array[1..16] of Byte;
217 <  tempd:      TByteData;
126 >  i: Integer;
127   begin
128 <  x := 0;
129 <  y := 0;
130 <  SetLength(tempd, Self.FWidth * Self.FHeight * 4);
222 <  for i := 0 to ((Self.FWidth * Self.FHeight) div 16) - 1 do
223 <  begin
224 <    Color[1].RGBb := Round(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $001F) /
225 <      $001F * 255);
226 <    Color[1].RGBg := Round(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $07E0) /
227 <      $07E0 * 255);
228 <    Color[1].RGBr := Round(((Self.FData[(i * 8) + 0] + Self.FData[(i * 8) + 1] * 256) and $F800) /
229 <      $F800 * 255);
230 <    Color[1].RGBa := 255;
231 <    Color[2].RGBb := Round(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $001F) /
232 <      $001F * 255);
233 <    Color[2].RGBg := Round(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $07E0) /
234 <      $07E0 * 255);
235 <    Color[2].RGBr := Round(((Self.FData[(i * 8) + 2] + Self.FData[(i * 8) + 3] * 256) and $F800) /
236 <      $F800 * 255);
237 <    Color[2].RGBa := 255;
238 <    Color[3].RGBb := Round(Color[1].RGBb / 3 * 2 + Color[2].RGBb / 3);
239 <    Color[3].RGBg := Round(Color[1].RGBg / 3 * 2 + Color[2].RGBg / 3);
240 <    Color[3].RGBr := Round(Color[1].RGBr / 3 * 2 + Color[2].RGBr / 3);
241 <    Color[3].RGBa := 255;
242 <    Color[4].RGBb := Round(Color[1].RGBb / 3 + Color[2].RGBb / 3 * 2);
243 <    Color[4].RGBg := Round(Color[1].RGBg / 3 + Color[2].RGBg / 3 * 2);
244 <    Color[4].RGBr := Round(Color[1].RGBr / 3 + Color[2].RGBr / 3 * 2);
245 <    Color[4].RGBa := 255;
246 <    Pixel[1]      := Round((Self.FData[(i * 8) + 4] and $C0) / $40 + 1);
247 <    Pixel[2]      := Round((Self.FData[(i * 8) + 4] and $30) / $10 + 1);
248 <    Pixel[3]      := Round((Self.FData[(i * 8) + 4] and $0C) / $04 + 1);
249 <    Pixel[4]      := Round((Self.FData[(i * 8) + 4] and $03) + 1);
250 <    Pixel[5]      := Round((Self.FData[(i * 8) + 5] and $C0) / $40 + 1);
251 <    Pixel[6]      := Round((Self.FData[(i * 8) + 5] and $30) / $10 + 1);
252 <    Pixel[7]      := Round((Self.FData[(i * 8) + 5] and $0C) / $04 + 1);
253 <    Pixel[8]      := Round((Self.FData[(i * 8) + 5] and $03) + 1);
254 <    Pixel[9]      := Round((Self.FData[(i * 8) + 6] and $C0) / $40 + 1);
255 <    Pixel[10]     := Round((Self.FData[(i * 8) + 6] and $30) / $10 + 1);
256 <    Pixel[11]     := Round((Self.FData[(i * 8) + 6] and $0C) / $04 + 1);
257 <    Pixel[12]     := Round((Self.FData[(i * 8) + 6] and $03) + 1);
258 <    Pixel[13]     := Round((Self.FData[(i * 8) + 7] and $C0) / $40 + 1);
259 <    Pixel[14]     := Round((Self.FData[(i * 8) + 7] and $30) / $10 + 1);
260 <    Pixel[15]     := Round((Self.FData[(i * 8) + 7] and $0C) / $04 + 1);
261 <    Pixel[16]     := Round((Self.FData[(i * 8) + 7] and $03) + 1);
262 <    for j := 0 to 3 do
263 <    begin
264 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[16 - j]].RGBb;
265 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[16 - j]].RGBg;
266 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[16 - j]].RGBr;
267 <      tempd[((y + 3) * Self.FWidth + x + j) * 4 + 3] := 0;
268 <    end;
269 <    for j := 0 to 3 do
270 <    begin
271 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[12 - j]].RGBb;
272 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[12 - j]].RGBg;
273 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[12 - j]].RGBr;
274 <      tempd[((y + 2) * Self.FWidth + x + j) * 4 + 3] := 0;
275 <    end;
276 <    for j := 0 to 3 do
277 <    begin
278 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[8 - j]].RGBb;
279 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[8 - j]].RGBg;
280 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[8 - j]].RGBr;
281 <      tempd[((y + 1) * Self.FWidth + x + j) * 4 + 3] := 0;
282 <    end;
283 <    for j := 0 to 3 do
284 <    begin
285 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 0] := Color[Pixel[4 - j]].RGBb;
286 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 1] := Color[Pixel[4 - j]].RGBg;
287 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 2] := Color[Pixel[4 - j]].RGBr;
288 <      tempd[((y + 0) * Self.FWidth + x + j) * 4 + 3] := 0;
289 <    end;
290 <    x := x + 4;
291 <    if x = Self.FWidth then
292 <    begin
293 <      y := y + 4;
294 <      x := 0;
295 <    end;
296 <  end;
297 <  SetLength(Self.FData, Length(tempd));
298 <  for i := 0 to High(tempd) do
299 <    Self.FData[i] := tempd[i];
300 <  Self.FStoreType := 8;
301 <  Self.FDepth    := 32;
302 <  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;
312  ext:      String;
150   begin
151    FileInfo := ConManager.Connection[ConnectionID].GetFileInfo(fileid);
152    if FileInfo.Extension = 'PSpc' then
# Line 341 | 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 = 1;
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 368 | 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 <  txmpimg.GetAs32bit(txmpdata);
216 < {    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
376 <    for i:=0 to High(txmpdata) do
377 <      txmpimg.Data[i]:=txmpdata[i];
378 <    txmpimg.WriteToBMP('D:\file2.bmp');
379 < }
380 <  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 391 | Line 227 | begin
227        row  := i mod 3;
228        if (p2[i].X > 0) or (p2[i].Y > 0) then
229        begin
230 <        parts[part].x_txmp := p1[i].X - 1;
231 <        parts[part].y_txmp := p1[i].Y - 1;
230 >        parts[part].x_txmp := p1[i].X;// - 1;
231 >        parts[part].y_txmp := p1[i].Y;// - 1;
232          parts[part].x_pspc := 0;
233          if col > 0 then
234            for x := 0 to col - 1 do
# Line 401 | Line 237 | begin
237          if row > 0 then
238            for y := 0 to row - 1 do
239              Inc(parts[part].y_pspc, rows[y]);
240 <        parts[part].w := p2[i].X - p1[i].X + 1;
241 <        parts[part].h := p2[i].Y - p1[i].Y + 1;
240 >        parts[part].w := Max(p2[i].X - p1[i].X, 1);// + 1;
241 >        parts[part].h := Max(p2[i].Y - p1[i].Y, 1);// + 1;
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
415 <            begin
416 <              parts[part].imgdata[(y * parts[part].w + x) * 4 + pixel] :=
417 <                txmpdata[((parts[part].y_txmp + y) * txmpimg.Width +
418 <                parts[part].x_txmp + x) * 4 + pixel];
419 <            end;
420 <          end;
421 <        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 428 | Line 257 | begin
257  
258    end;
259  
431  txmpimg.Free;
432  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));
438 <      for pixel := 0 to High(parts[i].imgdata) do
439 <        txmpimg.Data[pixel] := parts[i].imgdata[pixel];
440 <      txmpimg.Width := parts[i].w;
441 <      txmpimg.Height    := parts[i].h;
442 <      txmpimg.StoreType := 8;
443 <      txmpimg.DataType  := [DT_Decoded32];
444 <      txmpimg.Depth     := 32;
445 <      txmpimg.WriteToBMP('M:\' + IntToStr(i) + '.bmp');
264 > //      SaveImageToFile('M:\' + IntToStr(i) + '.bmp', parts[i].imgdata);
265      end;
266    end;
448  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 parts[part].used then
282 >      begin
283 >        if (row = 1) and (col = 1) then
284 >          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
285 >              FImages[0], x, y, parts[part].w * stretch_x, parts[part].h * stretch_y, rfNearest)
286 >        else
287 >        if (row = 1) then
288 >          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
289 >              FImages[0], x, y, parts[part].w, parts[part].h * stretch_y, rfNearest)
290 >        else
291 >        if (col = 1) then
292 >          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
293 >              FImages[0], x, y, parts[part].w * stretch_x, parts[part].h, rfNearest)
294 >        else
295 >          CopyRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
296 >              FImages[0], x, y );
297 >        if row = 1 then
298 >          y := y + parts[part].h * stretch_y
299 >        else
300 >          y := y + parts[part].h;
301 >      end;
302 >    end;
303 >    if cols[col] > 0 then
304 >    begin
305 >      if (col = 1) then
306 >        x := x + parts[part].w * stretch_x
307 >      else
308 >        x := x + parts[part].w;
309 >    end;
310    end;
457  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
458
459  //Combine data parts
311  
312 <  Self.FDepth     := 32;
313 <  Self.FStoreType := 8;
314 <  Self.FDataType  := [DT_Decoded32];
315 <  //    Self.RevertImage;
312 >  FreeImage(pspcimage);
313 >  for i := 0 to 8 do
314 >    if parts[i].used then
315 >      FreeImage(parts[i].imgdata);
316   end;
317  
318  
# Line 470 | Line 321 | end;
321   function TOniImage.LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
322   var
323    img_addr: Integer;
324 +  data: TMemoryStream;
325 +  hdr: TDDSDXTHeader;
326 +  imginfo: Integer;
327 +  x,y, i: Integer;
328 +
329 +  _width, _height: Word;
330 +  _storetype: Byte;
331 +  _depth: Byte;
332   begin
333    Result := True;
334 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
335 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
336 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
337 <    @Self.FStoreType);
334 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(_width), @_width);
335 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(_height), @_height);
336 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(_storetype), @_storetype);
337 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(imginfo), @imginfo);
338    if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
339      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
340    else
341      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
342  
343 <  case Self.FStoreType of
343 >  case _storetype of
344      0, 1, 2:
345 <    begin
346 <      SetLength(Self.FData, Self.FWidth * Self.FHeight * 2);
347 <      Self.FDepth := 16;
489 <    end;
490 <    8:
491 <    begin
492 <      SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
493 <      Self.FDepth := 32;
494 <    end;
345 >      _depth := 16;
346 >    7, 8:
347 >      _depth := 32;
348      9:
349 <    begin
497 <      SetLength(Self.FData, Self.FWidth * Self.FHeight div 2);
498 <      Self.FDepth := 16;
499 <    end;
349 >      _depth := 16;
350      else
351        Result := False;
352        Exit;
353    end;
354  
355 +  with hdr do
356 +  begin
357 +    FOURCC := 'DDS ';
358 +    with SURFACEDESC2 do
359 +    begin
360 +      Size := 124;
361 +      Flags := DDSD_CAPS or DDSD_PIXELFORMAT or DDSD_WIDTH or DDSD_HEIGHT;
362 +      if _storetype = 9 then
363 +        Flags := Flags or DDSD_LINEARSIZE
364 +      else
365 +        Flags := Flags or DDSD_PITCH;
366 +      if (imginfo and $01) > 0 then
367 +        Flags := Flags or DDSD_MIPMAPCOUNT;
368 +      Height := _height;
369 +      Width := _width;
370 +      if _storetype = 9 then
371 +        PitchOrLinearSize := width * height div 2
372 +      else
373 +        PitchOrLinearSize := width * _depth div 8;
374 +      Depth := 0;
375 +      MipMapCount := 1;
376 +      if (imginfo and $01) > 0 then
377 +      begin
378 +        x := width;
379 +        y := height;
380 +        while (x > 1) and (y > 1) do
381 +        begin
382 +          x := x div 2;
383 +          y := y div 2;
384 +          Inc(MipMapCount);
385 +        end;
386 +      end;
387 +      for i := 1 to 11 do
388 +        Reserved[i] := 0;
389 +      with PIXELFORMAT do
390 +      begin
391 +        Size := 32;
392 +        if _storetype = 9 then
393 +          Flags := DDPF_FOURCC
394 +        else
395 +          Flags := DDPF_RGB;
396 +        if _storetype in [0, 2] then
397 +          Flags := Flags or DDPF_ALPHAPIXELS;
398 +        if _storetype = 9 then
399 +          FOURCC := 'DXT1'
400 +        else
401 +        begin
402 +          RGBBitCount := _depth;
403 +          case _storetype of
404 +            0: begin
405 +              RBitMask := $0F00;
406 +              GBitMask := $00F0;
407 +              BBitMask := $000F;
408 +              AlphaBitMask := $F000;
409 +            end;
410 +            1, 2: begin
411 +              RBitMask := $7C00;
412 +              GBitMask := $03E0;
413 +              BBitMask := $001F;
414 +              if _storetype = 2 then
415 +                AlphaBitMask := $8000
416 +              else
417 +                AlphaBitMask := $0000;
418 +            end;
419 +            8: begin
420 +              RBitMask := $00FF0000;
421 +              GBitMask := $0000FF00;
422 +              BBitMask := $000000FF;
423 +              AlphaBitMask := $00000000;
424 +            end;
425 +          end;
426 +        end;
427 +      end;
428 +      with DDSCAPS2 do
429 +      begin
430 +        Caps1 := DDSCAPS_TEXTURE;
431 +        if (imginfo and $01) > 0 then
432 +          Caps1 := Caps1 or DDSCAPS_COMPLEX or DDSCAPS_MIPMAP;
433 +        Caps2 := 0;
434 +        Reserved[1] := 0;
435 +        Reserved[2] := 0;
436 +      end;
437 +    end;
438 +  end;
439 +
440 +  data := TMemoryStream.Create;
441 +  data.Write(hdr, SizeOf(hdr));
442    if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
443 <    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, FData)
443 >    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data))
444    else
445 <    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, FData);
445 >    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data));
446  
447 <  Self.FDataType := [DT_OniReverted, DT_Oni];
447 > //  data.Seek(0, soFromBeginning);
448 > //  data.SaveToFile('m:\test.txmp');
449 >
450 >  data.Seek(0, soFromBeginning);
451 >  result := LoadMultiImageFromStream(data, FImages);
452 >  data.Free;
453 > {
454 >  if result then
455 >  begin
456 >    for i := 0 to High(FImages) do
457 >    begin
458 >      data := TMemoryStream.Create;
459 >      data.Write(FImages[i].Bits^, FImages[i].Size);
460 >      data.Seek(0, soFromBeginning);
461 >      data.SaveToFile('m:\test.txmp.'+IntToStr(i));
462 >      data.Free;
463 >    end;
464 >  end;
465 > }
466 >  if not result then
467 >  begin
468 >    ShowMessage('Error while loading file' + #13#10 + DetermineStreamFormat(data));
469 > //    data.SaveToFile('m:\prob.dds');
470 >  end;
471   end;
472  
473  
# Line 515 | Line 475 | end;
475  
476   function TOniImage.LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
477   var
478 <  i, x, y, x2, y2, pixelid, imgid: Integer;
478 >  i, x, y, imgid: Integer;
479    rows, cols: Word;
480    linkcount: Integer;
481    link: Integer;
482 <  images_decoded: array of TOniImage;
482 >  images: array of TOniImage;
483    x_start, y_start: Integer;
484 +
485 +  width, height: Word;
486   begin
487 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
488 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
487 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, SizeOf(width), @width);
488 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $12, SizeOf(height), @height);
489    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
490    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
491    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
492 <  SetLength(images_decoded, linkcount);
492 >  SetLength(images, linkcount);
493    for i := 0 to linkcount - 1 do
494    begin
495      ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
496      link := link div 256;
497 <    images_decoded[i] := TOniImage.Create;
498 <    images_decoded[i].LoadFromTXMP(ConnectionID, link);
499 <    images_decoded[i].DecodeImage;
500 <    images_decoded[i].RevertImage;
497 >    images[i] := TOniImage.Create;
498 >    images[i].LoadFromTXMP(ConnectionID, link);
499 >    SetLength(FImages, 1);
500 >    NewImage(width, height, ifA1R5G5B5, FImages[0]);
501    end;
540  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
502    for y := 0 to rows - 1 do
503    begin
504      for x := 0 to cols - 1 do
505      begin
506 <      imgid   := y * cols + x;
506 >      imgid := y * cols + x;
507        x_start := 0;
508        y_start := 0;
509        for i := 0 to x do
510          if i < x then
511 <          x_start := x_start + images_decoded[i].Width;
511 >          x_start := x_start + images[i].Image[0].Width;
512        for i := 0 to y do
513          if i < y then
514 <          y_start := y_start + images_decoded[i].Height;
515 <      for y2 := 0 to images_decoded[imgid].Height - 1 do
516 <      begin
556 <        for x2 := 0 to images_decoded[imgid].Width - 1 do
557 <        begin
558 <          if ((x_start + x2) < Self.FWidth) and ((y_start + y2) < Self.FHeight) then
559 <          begin
560 <            pixelid := y_start * Self.FWidth + x_start + y2 * Self.FWidth + x2;
561 <            Self.FData[pixelid * 4 + 0] :=
562 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 0];
563 <            Self.FData[pixelid * 4 + 1] :=
564 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 1];
565 <            Self.FData[pixelid * 4 + 2] :=
566 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 2];
567 <            Self.FData[pixelid * 4 + 3] :=
568 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 3];
569 <          end;
570 <        end;
571 <      end;
514 >          y_start := y_start + images[i].Image[0].Height;
515 >      CopyRect(images[imgid].Image[0], 0, 0, images[imgid].Image[0].Width,
516 >          images[imgid].Image[0].Height, FImages[0], x_start, y_start);
517      end;
518    end;
519    for i := 0 to linkcount - 1 do
520 <    images_decoded[i].Free;
576 <  Self.FDepth     := 32;
577 <  Self.FStoreType := 8;
578 <  Self.FDataType  := [DT_Decoded32];
579 <  Self.RevertImage;
520 >    images[i].Free;
521   end;
522  
523  
524  
525 <
585 < function TOniImage.GetImageDataSize(fading: Boolean): Integer;
525 > procedure TOniImage.SaveDataToStream(MipMaps: Boolean; var Target: TStream);
526   var
527 <  size: Integer;
528 <  x, y: Word;
529 <  bpp:  Byte;
527 >  images: TDynImageDataArray;
528 >  mem: TMemoryStream;
529 >  i: Integer;
530   begin
531 <  case Self.FStoreType of
532 <    9:
533 <      bpp := 8;
534 <    0, 1, 2:
535 <      bpp := 16;
536 <    8:
537 <      bpp := 32;
531 >  if Length(FImages) = 0 then
532 >    Exit;
533 >  if MipMaps then
534 >  begin
535 >    if Length(FImages) = 1 then
536 >    begin
537 >      if not GenerateMipMaps(FImages[0], 0, images) then
538 >      begin
539 >        ShowMessage('Could not generate MipMaps');
540 >        Exit;
541 >      end;
542 >    end
543      else
544 <      Result := 0;
544 >    begin
545 >      SetLength(images, Length(FImages));
546 >      for i := 0 to High(FImages) do
547 >        CloneImage(FImages[i], images[i]);
548 >    end;
549 >    mem := TMemoryStream.Create;
550 >    if not SaveMultiImageToStream('dds', mem, images) then
551 >    begin
552 >      ShowMessage('Could not save images to stream');
553        Exit;
554 <  end;
555 <
603 <  x    := Self.FWidth;
604 <  y    := Self.FHeight;
605 <  size := x * y * bpp div 8;
606 <  if fading then
607 <  begin
608 <    repeat
609 <      x    := x div 2;
610 <      y    := y div 2;
611 <      size := size + x * y * bpp div 8;
612 <    until (x = 1) or (y = 1);
613 <  end;
614 <  Result := size;
615 < end;
616 <
617 <
618 <
619 <
620 < procedure TOniImage.GetAsData(var Target: TStream);
621 < var
622 <  i:      Integer;
623 <  revert: Boolean;
624 < begin
625 <  //    if not (DT_Decoded32 in Self.FDataType) then
626 <  //      Self.DecodeImage;
627 <  if not (DT_OniReverted in Self.FDataType) then
628 <  begin
629 <    revert := True;
630 <    Self.RevertImage;
554 >    end;
555 >    FreeImagesInArray(images);
556    end
557    else
633    revert := False;
634  if not Assigned(Target) then
635    Target := TMemoryStream.Create;
636  Target.Write(FData[0], Length(FData));
637  Target.Seek(0, soFromBeginning);
638  if revert then
639    Self.RevertImage;
640 end;
641
642 procedure TOniImage.GetAsData(var Target: TByteData);
643 var
644  mem: TStream;
645 begin
646  mem := TMemoryStream.Create;
647  GetAsData(mem);
648  SetLength(Target, mem.Size);
649  mem.Read(Target[0], mem.Size);
650  mem.Free;
651 end;
652
653
654 procedure TOniImage.GetAs32bit(var Target: TStream);
655 begin
656  if not (DT_Decoded32 in Self.FDataType) then
657    Self.DecodeImage;
658  if not Assigned(Target) then
659    Target := TMemoryStream.Create;
660  Target.Write(FData[0], Length(FData));
661  Target.Seek(0, soFromBeginning);
662 end;
663
664 procedure TOniImage.GetAs32bit(var Target: TByteData);
665 var
666  mem: TStream;
667 begin
668  mem := TMemoryStream.Create;
669  GetAs32bit(mem);
670  SetLength(Target, mem.Size);
671  mem.Read(Target[0], mem.Size);
672  mem.Free;
673 end;
674
675
676 procedure TOniImage.GetAsBMP(var Target: TByteData);
677 const
678  BMPheader: array[0..53] of Byte =
679    ($42, $4D, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0,
680    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,
681    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
682 var
683  i, x, y: Integer;
684 begin
685  if not (DT_Decoded32 in Self.FDataType) then
686    Self.DecodeImage;
687
688  SetLength(Target, Self.FWidth * Self.FHeight * 3 + 54);
689  for y := 0 to Self.FHeight - 1 do
558    begin
559 <    for x := 0 to Self.FWidth - 1 do
559 >    mem := TMemoryStream.Create;
560 >    if not SaveImageToStream('dds', mem, FImages[0]) then
561      begin
562 <      Target[((Self.FWidth * y + x) * 3) + 0 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 0];
563 <      Target[((Self.FWidth * y + x) * 3) + 1 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 1];
695 <      Target[((Self.FWidth * y + x) * 3) + 2 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 2];
562 >      ShowMessage('Could not save image to stream');
563 >      Exit;
564      end;
565    end;
566 +  if not Assigned(Target) then
567 +    Target := TMemoryStream.Create;
568  
569 <  for i := 0 to High(BMPheader) do
570 <    Target[i] := BMPheader[i];
701 <  Target[2] := ((Self.FWidth * Self.FHeight * 3 + 54) and $000000FF) div $1;
702 <  Target[3]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $0000FF00) div $100;
703 <  Target[4]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $00FF0000) div $10000;
704 <  Target[5]  := ((Self.FWidth * Self.FHeight * 3 + 54) and $FF000000) div $1000000;
705 <  Target[18] := (Self.FWidth and $000000FF) div $1;
706 <  Target[19] := (Self.FWidth and $0000FF00) div $100;
707 <  Target[20] := (Self.FWidth and $00FF0000) div $10000;
708 <  Target[21] := (Self.FWidth and $FF000000) div $1000000;
709 <  Target[22] := (Self.FHeight and $000000FF) div $1;
710 <  Target[23] := (Self.FHeight and $0000FF00) div $100;
711 <  Target[24] := (Self.FHeight and $00FF0000) div $10000;
712 <  Target[25] := (Self.FHeight and $FF000000) div $1000000;
713 <  Target[34] := ((Self.FWidth * Self.FHeight * 3) and $000000FF) div $1;
714 <  Target[35] := ((Self.FWidth * Self.FHeight * 3) and $0000FF00) div $100;
715 <  Target[36] := ((Self.FWidth * Self.FHeight * 3) and $00FF0000) div $10000;
716 <  Target[37] := ((Self.FWidth * Self.FHeight * 3) and $FF000000) div $1000000;
717 < end;
718 <
569 > //  mem.Seek(0, soFromBeginning);
570 > //  mem.SaveToFile('m:\dds.dds');
571  
572 < procedure TOniImage.GetAsBMP(var Target: TStream);
573 < var
574 <  data: TByteData;
575 <  streampos: Integer;
724 < begin
725 <  GetAsBMP(data);
726 <  streampos := Target.Position;
727 <  Target.Write(data[0], Length(data));
728 <  Target.Seek(streampos, soFromBeginning);
572 >  mem.Seek(128, soFromBeginning);
573 >  Target.CopyFrom(mem, mem.Size - 128);
574 >  mem.Free;
575 >  Target.Seek(0, soFromBeginning);
576   end;
577  
578  
579 < function TOniImage.LoadFromBMP(filename: String): Boolean;
733 < var
734 <  filestream: TFileStream;
735 <  tempd:      TByteData;
736 <
737 <  x, y: Integer;
579 > function TOniImage.LoadFromFile(filename: String): Boolean;
580   begin
581 <  filestream := TFileStream.Create(filename, fmOpenRead);
582 <  SetLength(tempd, filestream.Size);
741 <  filestream.Read(tempd[0], filestream.Size);
742 <  filestream.Free;
743 <
744 <  if not ((tempd[00] = $42) and (tempd[01] = $4D)) then
745 <  begin
746 <    Result := False;
747 <    ShowMessage('Not a standard 24bit bitmap');
748 <    Exit;
749 <  end;
750 <  if not (tempd[10] = 54) then
751 <  begin
752 <    Result := False;
753 <    ShowMessage('Imagedata has to start at 0x54');
754 <    Exit;
755 <  end;
756 <  if not (tempd[14] = 40) then
757 <  begin
758 <    Result := False;
759 <    ShowMessage('Second bitmap header has to have 40 bytes');
760 <    Exit;
761 <  end;
762 <  if not (tempd[28] = 24) then
763 <  begin
764 <    Result := False;
765 <    ShowMessage('Bitmap has to have 24bits');
766 <    Exit;
767 <  end;
768 <  if not (tempd[30] = 0) then
769 <  begin
770 <    Result := False;
771 <    ShowMessage('Bitmap has to be uncompressed');
772 <    Exit;
773 <  end;
774 <
775 <  Self.FWidth     := tempd[18] + tempd[19] * 256 + tempd[20] * 256 * 256 + tempd[21] * 256 * 256 * 256;
776 <  Self.FHeight    := tempd[22] + tempd[23] * 256 + tempd[24] * 256 * 256 + tempd[25] * 256 * 256 * 256;
777 <  Self.FDepth     := 32;
778 <  Self.FStoreType := 8;
779 <
780 <  SetLength(Self.FData, Self.FWidth * Self.FHeight * Self.FDepth div 8);
781 <  for y := 0 to Self.FHeight - 1 do
782 <  begin
783 <    for x := 0 to Self.FWidth - 1 do
784 <    begin
785 <      Self.FData[((Self.FWidth * y + x) * 4) + 0] := tempd[54 + (Self.FWidth * y + x) * 3 + 0];
786 <      Self.FData[((Self.FWidth * y + x) * 4) + 1] := tempd[54 + (Self.FWidth * y + x) * 3 + 1];
787 <      Self.FData[((Self.FWidth * y + x) * 4) + 2] := tempd[54 + (Self.FWidth * y + x) * 3 + 2];
788 <      Self.FData[((Self.FWidth * y + x) * 4) + 3] := 0;
789 <    end;
790 <  end;
791 <
792 <  Self.FDataType := [DT_Decoded32];
581 >  if not LoadMultiImageFromFile(filename, FImages) then
582 >    ShowMessage('Couldn''t load image file');
583   end;
584  
585  
586 <
797 <
798 < function TOniImage.WriteToBMP(filename: String): Boolean;
799 < var
800 <  filestream: TFileStream;
586 > function TOniImage.WriteToFile(filename: String): Boolean;
587   begin
588 <  filestream := TFileStream.Create(filename, fmCreate);
803 <  GetAsBMP(TStream(filestream));
804 <  filestream.Free;
588 >  SaveMultiImageToFile(filename, FImages);
589   end;
590  
591  
592  
593 < function TOniImage.GetMipMappedImage(var Target: TByteData): Boolean;
593 > function TOniImage.GetImageSize(MipMaps: Boolean): Integer;
594   var
595 <  i:      Integer;
596 <  x, y:   Word;
597 <  fadelvldata: TByteData;
814 <  revert: Boolean;
815 < begin
816 <  Result := False;
817 <
818 <  //    if not (DT_Decoded32 in Self.FDataType) then
819 <  //      Self.DecodeImage;
820 <  if Self.FStoreType = 9 then
821 <    Self.DecompressImage;
822 <  if not (DT_OniReverted in Self.FDataType) then
595 >  i: Integer;
596 > begin
597 >  if Length(FImages) > 0 then
598    begin
599 <    revert := True;
600 <    Self.RevertImage;
599 >    Result := FImages[0].Size;
600 >    if mipmaps then
601 >      for i := 1 to High(FImages) do
602 >        Result := Result + FImages[i].Size;
603    end
604    else
605 <    revert := False;
829 <
830 <  x := Self.FWidth;
831 <  y := Self.FHeight;
832 <  SetLength(Target, x * y * Self.FDepth div 8);
833 <  SetLength(fadelvldata, x * y * Self.FDepth div 8);
834 <  for i := 0 to Length(Target) - 1 do
835 <  begin
836 <    Target[i] := Self.FData[i];
837 <    fadelvldata[i] := Self.FData[i];
838 <  end;
839 <  repeat
840 <    fadelvldata := Self.ResizeImage(x, y, fadelvldata);
841 <    x := x div 2;
842 <    y := y div 2;
843 <    SetLength(Target, Length(Target) + x * y * Self.FDepth div 8);
844 <    for i := 0 to Length(fadelvldata) - 1 do
845 <      Target[Length(Target) - x * y * Self.FDepth div 8 + i] := fadelvldata[i];
846 <  until (x = 1) or (y = 1) or ((x mod 2) = 1) or ((y mod 2) = 1);
847 <  if (x > 1) and (y > 1) then
848 <    Exit;
849 <  Result := True;
850 <
851 <  if revert then
852 <    Self.RevertImage;
853 < end;
854 <
855 <
856 < function TOniImage.GetMipMappedImage(var Target: TStream): Boolean;
857 < var
858 <  data: TByteData;
859 <  streampos: Integer;
860 < begin
861 <  Result := GetMipMappedImage(data);
862 <  if not Assigned(Target) then
863 <    Target := TMemoryStream.Create;
864 <  streampos := Target.Position;
865 <  Target.Write(data[0], Length(data));
866 <  Target.Seek(streampos, soFromBeginning);
605 >    Result := -1;
606   end;
607  
869
608   end.

Diff Legend

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