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 244 by alloc, Fri Aug 17 21:09:51 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 +
33 +    function GetImageSize(MipMaps: Boolean): Integer;
34 +
35 +    function LoadFromFile(filename: String): Boolean;
36 +    function WriteToFile(filename: String): Boolean;
37 +    procedure SaveDataToStream(MipMaps: Boolean; var Target: TStream);
38 +    procedure DrawOnCanvas(Canvas: TCanvas; Index: Integer);
39 +
40      function Load(ConnectionID, FileID: Integer): Boolean;
36    function LoadFromPSpc(ConnectionID, FileID: Integer): Boolean;
41      function LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
42      function LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
43 <    function GetImageDataSize(fading: Boolean): Integer;
40 <
41 <    function GetAsData: TByteData;
42 <    function GetAs32bit: TByteData;
43 <    procedure GetAsBMP(var Target: TByteData); overload;
44 <    procedure GetAsBMP(var Target: TStream); overload;
45 <    function LoadFromBMP(filename: String): Boolean;
46 <    function WriteToBMP(filename: String): Boolean;
47 <    function GetMipMappedImage(var faded: TByteData): Boolean;
43 >    function LoadFromPSpc(ConnectionID, FileID: Integer): Boolean;
44    published
45    end;
46  
47  
48   implementation
49  
50 < //uses Functions;
50 > uses Img_DDSTypes, ImagingComponents;
51 >
52 >
53 > function TOniImage.GetImage(MipGen: Integer): TImageData;
54 > begin
55 >  if MipGen <= Length(FImages) then
56 >  begin
57 >    InitImage(Result);
58 >    CloneImage(FImages[MipGen-1], Result);
59 >  end;
60 > end;
61 >
62 >
63 > function TOniImage.GetWidth(MipGen: Integer): Integer;
64 > begin
65 >  if MipGen <= Length(FImages) then
66 >    Result := FImages[MipGen-1].Width
67 >  else
68 >    Result := -1;
69 > end;
70 >
71 >
72 > function TOniImage.GetHeight(MipGen: Integer): Integer;
73 > begin
74 >  if MipGen <= Length(FImages) then
75 >    Result := FImages[MipGen-1].Height
76 >  else
77 >    Result := -1;
78 > end;
79 >
80 >
81 > function TOniImage.GetImageFormat: TImageFormat;
82 > begin
83 >  if Length(FImages) > 0 then
84 >    Result := FImages[0].Format
85 >  else
86 >    Result := ifUnknown;
87 > end;
88 >
89 > procedure TOniImage.SetImageFormat(Format: TImageFormat);
90 > var
91 >  i: Integer;
92 > begin
93 >  if Length(FImages) > 0 then
94 >    for i := 0 to High(FImages) do
95 >      ConvertImage(FImages[i], Format);
96 > end;
97 >
98 >
99 > function TOniImage.pGetImageFormatInfo: TImageFormatInfo;
100 > begin
101 >  if Length(FImages) > 0 then
102 >    GetImageFormatInfo(FImages[0].Format, Result);
103 > end;
104 >
105 >
106 > function TOniImage.GetHasMipMaps: Boolean;
107 > begin
108 >  Result := Length(FImages) > 1;
109 > end;
110  
111  
112  
113  
114   constructor TOniImage.Create;
115   begin
116 <  Self.FLoaded   := False;
117 <  Self.FDataType := [];
118 <  SetLength(Self.FData, 0);
119 <  Self.FWidth     := 0;
120 <  Self.FHeight    := 0;
121 <  Self.FDepth     := 0;
122 <  Self.FStoreType := 0;
116 > end;
117 >
118 > procedure TOniImage.Free;
119 > begin
120 >  FreeImagesInArray(FImages);
121 > end;
122 >
123 >
124 >
125 >
126 > function TOniImage.GetImageSize(MipMaps: Boolean): Integer;
127 > var
128 >  i: Integer;
129 > begin
130 >  if Length(FImages) > 0 then
131 >  begin
132 >    Result := FImages[0].Size;
133 >    if mipmaps then
134 >      for i := 1 to High(FImages) do
135 >        Result := Result + FImages[i].Size;
136 >  end
137 >  else
138 >    Result := -1;
139 > end;
140 >
141 >
142 >
143 >
144 > function TOniImage.LoadFromFile(filename: String): Boolean;
145 > begin
146 >  Result := LoadMultiImageFromFile(filename, FImages);
147 >  if not Result then
148 >    ShowMessage('Couldn''t load image file');
149 > end;
150 >
151 >
152 > function TOniImage.WriteToFile(filename: String): Boolean;
153 > begin
154 >  Result := SaveMultiImageToFile(filename, FImages);
155 > end;
156 >
157 >
158 >
159 > procedure TOniImage.DrawOnCanvas(Canvas: TCanvas; Index: Integer);
160 > var
161 >  singleimg: TImageData;
162 >  rect: TRect;
163 > begin
164 >  InitImage(singleimg);
165 >  CloneImage(FImages[Index-1], singleimg);
166 >  ConvertImage(singleimg, ifX8R8G8B8);
167 >  rect.Left := 0;
168 >  rect.Top := 0;
169 >  rect.Right := singleimg.Width - 1;
170 >  rect.Bottom := singleimg.Height - 1;
171 >  Canvas.Brush.Color := $C8D0D4;
172 >  Canvas.FillRect(Canvas.ClipRect);
173 >  DisplayImageData(Canvas, rect, singleimg, rect);
174 >  FreeImage(singleimg);
175   end;
176  
177  
178  
179  
180 < function TOniImage.ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData;
180 > procedure TOniImage.SaveDataToStream(MipMaps: Boolean; var Target: TStream);
181   var
182 <  i, j: Integer;
183 <  col, row, row_orig: Integer;
182 >  images: TDynImageDataArray;
183 >  mem: TMemoryStream;
184 >  i: Integer;
185   begin
186 <  SetLength(Result, (oldx div 2) * (oldy div 2) * (Self.FDepth div 8));
187 <  row_orig := 0;
188 <  row      := 0;
81 <  col      := 0;
82 <  for i := 0 to (oldx * oldy) - 1 do
186 >  if Length(FImages) = 0 then
187 >    Exit;
188 >  if MipMaps then
189    begin
190 <    if ((i mod oldx) = 0) and (i > 0) then
190 >    if Length(FImages) = 1 then
191      begin
192 <      Inc(row_orig);
87 <      if (row_orig mod 2) = 0 then
192 >      if not GenerateMipMaps(FImages[0], 0, images) then
193        begin
194 <        Inc(row);
195 <        col := 0;
194 >        ShowMessage('Could not generate MipMaps');
195 >        Exit;
196        end;
197 +    end
198 +    else
199 +    begin
200 +      SetLength(images, Length(FImages));
201 +      for i := 0 to High(FImages) do
202 +        CloneImage(FImages[i], images[i]);
203      end;
204 <    if (row_orig mod 2) = 0 then
204 >    mem := TMemoryStream.Create;
205 >    if not SaveMultiImageToStream('dds', mem, images) then
206      begin
207 <      if (i mod 2) = 0 then
208 <      begin
209 <        for j := 0 to (Self.FDepth div 8) - 1 do
210 <          Result[((row * (oldx div 2)) + col) * (Self.FDepth div 8) + j] :=
211 <            img[(i * (Self.FDepth div 8)) + j];
212 <        Inc(col);
213 <      end;
207 >      ShowMessage('Could not save images to stream');
208 >      Exit;
209 >    end;
210 >    FreeImagesInArray(images);
211 >  end
212 >  else
213 >  begin
214 >    mem := TMemoryStream.Create;
215 >    if not SaveImageToStream('dds', mem, FImages[0]) then
216 >    begin
217 >      ShowMessage('Could not save image to stream');
218 >      Exit;
219      end;
220    end;
221 +  if not Assigned(Target) then
222 +    Target := TMemoryStream.Create;
223 +
224 +  mem.Seek(128, soFromBeginning);
225 +  Target.CopyFrom(mem, mem.Size - 128);
226 +  mem.Free;
227 +  Target.Seek(0, soFromBeginning);
228   end;
229  
230  
231  
232  
233 < procedure TOniImage.RevertImage;
233 >
234 > function TOniImage.Load(ConnectionID, FileID: Integer): Boolean;
235   var
236 <  x, y, i: Integer;
112 <  tempd:   TByteData;
236 >  FileInfo: TFileInfo;
237   begin
238 <  SetLength(tempd, Self.FWidth * Self.FHeight * (Self.FDepth div 8));
239 <  for y := 0 to Self.FHeight - 1 do
240 <    for x := 0 to Self.FWidth - 1 do
241 <      for i := 0 to (Self.FDepth div 8) - 1 do
242 <        tempd[((Self.FWidth * (Self.FHeight - 1 - y) + x) * (Self.FDepth div 8)) + i] :=
243 <          Self.FData[(Self.FWidth * y + x) * (Self.FDepth div 8) + i];
244 <  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]
238 >  FileInfo := ConManager.Connection[ConnectionID].GetFileInfo(fileid);
239 >  if FileInfo.Extension = 'PSpc' then
240 >    Result := LoadFromPSpc(ConnectionID, fileid)
241 >  else if FileInfo.Extension = 'TXMB' then
242 >    Result := LoadFromTXMB(ConnectionID, fileid)
243 >  else if FileInfo.Extension = 'TXMP' then
244 >    Result := LoadFromTXMP(ConnectionID, fileid)
245    else
246 <    Self.FDataType := Self.FDataType + [DT_OniReverted];
246 >    Result := False;
247   end;
248  
249  
250  
251  
252 < procedure TOniImage.DecodeImage;
252 > function TOniImage.LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
253   var
254 <  x, y:  Integer;
255 <  tempd: TByteData;
254 >  img_addr: Integer;
255 >  data: TMemoryStream;
256 >  hdr: TDDSDXTHeader;
257 >  imginfo: Integer;
258 >  x,y, i: Integer;
259 >
260 >  _width, _height: Word;
261 >  _storetype: Byte;
262 >  _depth: Byte;
263   begin
264 <  if not (DT_Decoded32 in Self.FDataType) then
264 >  Result := False;
265 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(_width), @_width);
266 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(_height), @_height);
267 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(_storetype), @_storetype);
268 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(imginfo), @imginfo);
269 >  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
270 >    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
271 >  else
272 >    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
273 >
274 >  case _storetype of
275 >    0, 1, 2:
276 >      _depth := 16;
277 >    7, 8:
278 >      _depth := 32;
279 >    9:
280 >      _depth := 16;
281 >    else
282 >      Result := False;
283 >      Exit;
284 >  end;
285 >
286 >  with hdr do
287    begin
288 <    SetLength(tempd, Self.FWidth * Self.FHeight * 4);
289 <    case Self.FStoreType of
290 <      0:
288 >    FOURCC := 'DDS ';
289 >    with SURFACEDESC2 do
290 >    begin
291 >      Size := 124;
292 >      Flags := DDSD_CAPS or DDSD_PIXELFORMAT or DDSD_WIDTH or DDSD_HEIGHT;
293 >      if _storetype = 9 then
294 >        Flags := Flags or DDSD_LINEARSIZE
295 >      else
296 >        Flags := Flags or DDSD_PITCH;
297 >      if (imginfo and $01) > 0 then
298 >        Flags := Flags or DDSD_MIPMAPCOUNT;
299 >      Height := _height;
300 >      Width := _width;
301 >      if _storetype = 9 then
302 >        PitchOrLinearSize := width * height div 2
303 >      else
304 >        PitchOrLinearSize := width * _depth div 8;
305 >      Depth := 0;
306 >      MipMapCount := 1;
307 >      if (imginfo and $01) > 0 then
308        begin
309 <        for y := 0 to Self.FHeight - 1 do
309 >        x := width;
310 >        y := height;
311 >        while (x > 1) and (y > 1) do
312          begin
313 <          for x := 0 to Self.FWidth - 1 do
314 <          begin
315 <            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;
313 >          x := x div 2;
314 >          y := y div 2;
315 >          Inc(MipMapCount);
316          end;
317        end;
318 <      1, 2:
318 >      for i := 1 to 11 do
319 >        Reserved[i] := 0;
320 >      with PIXELFORMAT do
321        begin
322 <        for y := 0 to Self.FHeight - 1 do
322 >        Size := 32;
323 >        if _storetype = 9 then
324 >          Flags := DDPF_FOURCC
325 >        else
326 >          Flags := DDPF_RGB;
327 >        if _storetype in [0, 2] then
328 >          Flags := Flags or DDPF_ALPHAPIXELS;
329 >        if _storetype = 9 then
330 >          FOURCC := 'DXT1'
331 >        else
332          begin
333 <          for x := 0 to Self.FWidth - 1 do
334 <          begin
335 <            tempd[((Self.FWidth * y + x) * 4) + 0] :=
336 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
337 <              $001F) / $001F * 255);
338 <            tempd[((Self.FWidth * y + x) * 4) + 1] :=
339 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
340 <              $03E0) / $03E0 * 255);
341 <            tempd[((Self.FWidth * y + x) * 4) + 2] :=
342 <              Round(((Self.FData[(Self.FWidth * y + x) * 2] + Self.FData[(Self.FWidth * y + x) * 2 + 1] * 256) and
343 <              $7C00) / $7C00 * 255);
344 <            tempd[((Self.FWidth * y + x) * 4) + 3] := 0;
333 >          RGBBitCount := _depth;
334 >          case _storetype of
335 >            0: begin
336 >              RBitMask := $0F00;
337 >              GBitMask := $00F0;
338 >              BBitMask := $000F;
339 >              AlphaBitMask := $F000;
340 >            end;
341 >            1, 2: begin
342 >              RBitMask := $7C00;
343 >              GBitMask := $03E0;
344 >              BBitMask := $001F;
345 >              if _storetype = 2 then
346 >                AlphaBitMask := $8000
347 >              else
348 >                AlphaBitMask := $0000;
349 >            end;
350 >            8: begin
351 >              RBitMask := $00FF0000;
352 >              GBitMask := $0000FF00;
353 >              BBitMask := $000000FF;
354 >              AlphaBitMask := $00000000;
355 >            end;
356            end;
357          end;
358        end;
359 <      9:
359 >      with DDSCAPS2 do
360        begin
361 <        DecompressImage;
361 >        Caps1 := DDSCAPS_TEXTURE;
362 >        if (imginfo and $01) > 0 then
363 >          Caps1 := Caps1 or DDSCAPS_COMPLEX or DDSCAPS_MIPMAP;
364 >        Caps2 := 0;
365 >        Reserved[1] := 0;
366 >        Reserved[2] := 0;
367        end;
368      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];
369    end;
195  if DT_OniReverted in Self.FDataType then
196    Self.RevertImage;
197 end;
198
370  
371 +  data := TMemoryStream.Create;
372 +  data.Write(hdr, SizeOf(hdr));
373 +  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
374 +    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data))
375 +  else
376 +    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data));
377  
378 +  data.Seek(0, soFromBeginning);
379 +  Result := LoadMultiImageFromStream(data, FImages);
380 +  data.Free;
381  
382 < procedure TOniImage.DecompressImage;
383 < type
384 <  Tcolor = record
205 <    RGBb: Byte;
206 <    RGBg: Byte;
207 <    RGBr: Byte;
208 <    RGBa: Byte;
209 <  end;
210 < var
211 <  i, j, x, y: Integer;
212 <  color:      array[1..4] of Tcolor;
213 <  pixel:      array[1..16] of Byte;
214 <  tempd:      TByteData;
215 < begin
216 <  x := 0;
217 <  y := 0;
218 <  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;
382 >  if not result then
383 >  begin
384 >    ShowMessage('Error while loading file' + #13#10 + DetermineStreamFormat(data));
385    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];
386   end;
387  
388  
389  
390  
391  
392 < function TOniImage.Load(ConnectionID, FileID: Integer): Boolean;
392 > function TOniImage.LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
393   var
394 <  FileInfo: TFileInfo;
395 <  ext:      String;
394 >  i, x, y, imgid: Integer;
395 >  rows, cols: Word;
396 >  linkcount: Integer;
397 >  link: Integer;
398 >  images: array of TOniImage;
399 >  x_start, y_start: Integer;
400 >
401 >  width, height: Word;
402   begin
403 <  FileInfo := ConManager.Connection[ConnectionID].GetFileInfo(fileid);
404 <  if FileInfo.Extension = 'PSpc' then
405 <    Result := LoadFromPSpc(ConnectionID, fileid)
406 <  else if FileInfo.Extension = 'TXMB' then
407 <    Result := LoadFromTXMB(ConnectionID, fileid)
408 <  else if FileInfo.Extension = 'TXMP' then
409 <    Result := LoadFromTXMP(ConnectionID, fileid)
410 <  else
411 <    Result := False;
403 >  Result := False;
404 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, SizeOf(width), @width);
405 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $12, SizeOf(height), @height);
406 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
407 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
408 >  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
409 >  SetLength(images, linkcount);
410 >  for i := 0 to linkcount - 1 do
411 >  begin
412 >    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
413 >    link := link div 256;
414 >    images[i] := TOniImage.Create;
415 >    images[i].LoadFromTXMP(ConnectionID, link);
416 >  end;
417 >  SetLength(FImages, 1);
418 >  NewImage(width, height, images[0].Format {ifA1R5G5B5}, FImages[0]);
419 >  for y := 0 to rows - 1 do
420 >  begin
421 >    for x := 0 to cols - 1 do
422 >    begin
423 >      imgid := y * cols + x;
424 >      x_start := 0;
425 >      y_start := 0;
426 >      for i := 0 to x do
427 >        if i < x then
428 >          x_start := x_start + images[i].Image[1].Width;
429 >      for i := 0 to y do
430 >        if i < y then
431 >          y_start := y_start + images[i].Image[1].Height;
432 >      CopyRect(images[imgid].Image[1], 0, 0, images[imgid].Image[1].Width,
433 >          images[imgid].Image[1].Height, FImages[0], x_start, y_start);
434 >    end;
435 >  end;
436 >  for i := 0 to linkcount - 1 do
437 >    images[i].Free;
438 >  Result := True;
439   end;
440  
441  
442  
443  
444 +
445   function TOniImage.LoadFromPSpc(ConnectionID, FileID: Integer): Boolean;
446   type
447    TPoint = packed record
# Line 338 | Line 458 | type
458      x_txmp, y_txmp: Word;
459      x_pspc, y_pspc: Word;
460      w, h:    Word;
461 <    imgdata: TByteData;
461 >    imgdata: TImageData;
462      used:    Boolean;
463    end;
464   const
465    PartMatch: array[0..8] of Byte = (0, 3, 6, 1, 4, 7, 2, 5, 8);
466 +  stretch_x: Integer = 1;
467 +  stretch_y: Integer = 1;
468   var
469 <  x, y, pixel: Word;
469 >  x, y: Word;
470    i: Integer;
471  
472    PSpc:     TPSpc;
473    txmpimg:  TOniImage;
352  txmpdata: TByteData;
474  
475    parts:    array[0..8] of TPart;
476    part:     Byte;
477    cols:     array[0..2] of Word;
478    rows:     array[0..2] of Word;
479    col, row: Byte;
480 +
481 +  pspcimage: TImageData;
482   begin
483    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
484    PSpc.TXMP := PSpc.TXMP div 256;
# Line 365 | Line 488 | begin
488      Exit;
489    end;
490    txmpimg := TOniImage.Create;
491 <  txmpimg.LoadFromTXMP(ConnectionID, PSpc.TXMP);
492 <  txmpimg.DecodeImage;
493 < //  txmpimg.WriteToBMP('C:\file.bmp');
494 <  txmpdata := txmpimg.GetAs32bit;
495 < {    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
496 <    for i:=0 to High(txmpdata) do
497 <      txmpimg.Data[i]:=txmpdata[i];
375 <    txmpimg.WriteToBMP('D:\file2.bmp');
376 < }
377 <  with PSpc do
491 >  txmpimg.Load(ConnectionID, PSpc.TXMP);
492 >  CloneImage(txmpimg.Image[1], pspcimage);
493 >  txmpimg.Free;
494 >
495 >  Result := False;
496 >
497 >  with pspc do
498    begin
499      for i := 0 to 2 do
500      begin
# Line 388 | Line 508 | begin
508        row  := i mod 3;
509        if (p2[i].X > 0) or (p2[i].Y > 0) then
510        begin
511 <        parts[part].x_txmp := p1[i].X - 1;
512 <        parts[part].y_txmp := p1[i].Y - 1;
511 >        parts[part].x_txmp := p1[i].X;// - 1;
512 >        parts[part].y_txmp := p1[i].Y;// - 1;
513          parts[part].x_pspc := 0;
514          if col > 0 then
515            for x := 0 to col - 1 do
# Line 398 | Line 518 | begin
518          if row > 0 then
519            for y := 0 to row - 1 do
520              Inc(parts[part].y_pspc, rows[y]);
521 <        parts[part].w := p2[i].X - p1[i].X + 1;
522 <        parts[part].h := p2[i].Y - p1[i].Y + 1;
521 >        parts[part].w := Max(p2[i].X - p1[i].X, 1);// + 1;
522 >        parts[part].h := Max(p2[i].Y - p1[i].Y, 1);// + 1;
523          parts[part].used := True;
524          cols[col] := parts[part].w;
525          rows[row] := parts[part].h;
526 <        SetLength(parts[part].imgdata, parts[part].w * parts[part].h * 4);
527 <        for y := 0 to parts[part].h - 1 do
528 <        begin
529 <          for x := 0 to parts[part].w - 1 do
530 <          begin
531 <            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;
526 >
527 >        NewImage(parts[part].w, parts[part].h, pspcimage.Format, parts[part].imgdata);
528 >
529 >        CopyRect(pspcimage,
530 >            parts[part].x_txmp, parts[part].y_txmp, parts[part].w, parts[part].h,
531 >            parts[part].imgdata, 0, 0);
532        end
533        else
534        begin
# Line 425 | Line 538 | begin
538  
539    end;
540  
428  txmpimg.Free;
429  txmpimg := TOniImage.Create;
541    for i := 0 to 8 do
542    begin
543      if parts[i].used then
544      begin
545 <      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');
443 <    end;
444 <  end;
445 <  txmpimg.Free;
446 <
447 <  Self.FWidth  := 0;
448 <  Self.FHeight := 0;
449 <  for i := 0 to 2 do
450 <  begin
451 <    Inc(Self.FWidth, cols[i]);
452 <    Inc(Self.FHeight, rows[i]);
453 <  end;
454 <  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
455 <
456 <  //Combine data parts
457 <
458 <  Self.FDepth     := 32;
459 <  Self.FStoreType := 8;
460 <  Self.FDataType  := [DT_Decoded32];
461 <  //    Self.RevertImage;
462 < end;
463 <
464 <
465 <
466 <
467 < function TOniImage.LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
468 < var
469 <  img_addr: Integer;
470 < begin
471 <  Result := True;
472 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
473 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
474 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
475 <    @Self.FStoreType);
476 <  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
477 <    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
478 <  else
479 <    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $A0, SizeOf(img_addr), @img_addr);
480 <
481 <  case Self.FStoreType of
482 <    0, 1, 2:
483 <    begin
484 <      SetLength(Self.FData, Self.FWidth * Self.FHeight * 2);
485 <      Self.FDepth := 16;
545 > //      SaveImageToFile('M:\' + IntToStr(i) + '.bmp', parts[i].imgdata);
546      end;
487    8:
488    begin
489      SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
490      Self.FDepth := 32;
491    end;
492    9:
493    begin
494      SetLength(Self.FData, Self.FWidth * Self.FHeight div 2);
495      Self.FDepth := 16;
496    end;
497    else
498      Result := False;
499      Exit;
547    end;
548  
549 <  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
550 <    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, FData)
551 <  else
505 <    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, FData);
506 <
507 <  Self.FDataType := [DT_OniReverted, DT_Oni];
508 < end;
509 <
510 <
549 >  SetLength(FImages, 1);
550 >  x := cols[0] + cols[1] * stretch_x + cols[2];
551 >  y := rows[0] + rows[1] * stretch_y + rows[2];
552  
553 +  NewImage(x, y, pspcimage.Format, FImages[0]);
554  
555 < function TOniImage.LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
556 < var
515 <  i, x, y, x2, y2, pixelid, imgid: Integer;
516 <  rows, cols: Word;
517 <  linkcount: Integer;
518 <  link: Integer;
519 <  images_decoded: array of TOniImage;
520 <  x_start, y_start: Integer;
521 < begin
522 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $10, SizeOf(Self.FWidth), @Self.FWidth);
523 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $12, SizeOf(Self.FHeight), @Self.FHeight);
524 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $18, SizeOf(cols), @cols);
525 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1A, SizeOf(rows), @rows);
526 <  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $1C, SizeOf(linkcount), @linkcount);
527 <  SetLength(images_decoded, linkcount);
528 <  for i := 0 to linkcount - 1 do
529 <  begin
530 <    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $20 + i * 4, SizeOf(link), @link);
531 <    link := link div 256;
532 <    images_decoded[i] := TOniImage.Create;
533 <    images_decoded[i].LoadFromTXMP(ConnectionID, link);
534 <    images_decoded[i].DecodeImage;
535 <    images_decoded[i].RevertImage;
536 <  end;
537 <  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
538 <  for y := 0 to rows - 1 do
555 >  x := 0;
556 >  for col := 0 to 2 do
557    begin
558 <    for x := 0 to cols - 1 do
558 >    y := 0;
559 >    for row := 0 to 2 do
560      begin
561 <      imgid   := y * cols + x;
562 <      x_start := 0;
544 <      y_start := 0;
545 <      for i := 0 to x do
546 <        if i < x then
547 <          x_start := x_start + images_decoded[i].Width;
548 <      for i := 0 to y do
549 <        if i < y then
550 <          y_start := y_start + images_decoded[i].Height;
551 <      for y2 := 0 to images_decoded[imgid].Height - 1 do
561 >      part := row*3 + col;
562 >      if parts[part].used then
563        begin
564 <        for x2 := 0 to images_decoded[imgid].Width - 1 do
565 <        begin
566 <          if ((x_start + x2) < Self.FWidth) and ((y_start + y2) < Self.FHeight) then
567 <          begin
568 <            pixelid := y_start * Self.FWidth + x_start + y2 * Self.FWidth + x2;
569 <            Self.FData[pixelid * 4 + 0] :=
570 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 0];
571 <            Self.FData[pixelid * 4 + 1] :=
572 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 1];
573 <            Self.FData[pixelid * 4 + 2] :=
574 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 2];
575 <            Self.FData[pixelid * 4 + 3] :=
576 <              images_decoded[imgid].Data[(y2 * images_decoded[imgid].Width + x2) * 4 + 3];
577 <          end;
578 <        end;
564 >        if (row = 1) and (col = 1) then
565 >          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
566 >              FImages[0], x, y, parts[part].w * stretch_x, parts[part].h * stretch_y, rfNearest)
567 >        else
568 >        if (row = 1) then
569 >          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
570 >              FImages[0], x, y, parts[part].w, parts[part].h * stretch_y, rfNearest)
571 >        else
572 >        if (col = 1) then
573 >          StretchRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
574 >              FImages[0], x, y, parts[part].w * stretch_x, parts[part].h, rfNearest)
575 >        else
576 >          CopyRect(parts[part].imgdata, 0, 0, parts[part].w, parts[part].h,
577 >              FImages[0], x, y );
578 >        if row = 1 then
579 >          y := y + parts[part].h * stretch_y
580 >        else
581 >          y := y + parts[part].h;
582        end;
583      end;
584 <  end;
571 <  for i := 0 to linkcount - 1 do
572 <    images_decoded[i].Free;
573 <  Self.FDepth     := 32;
574 <  Self.FStoreType := 8;
575 <  Self.FDataType  := [DT_Decoded32];
576 <  Self.RevertImage;
577 < end;
578 <
579 <
580 <
581 <
582 < function TOniImage.GetImageDataSize(fading: Boolean): Integer;
583 < var
584 <  size: Integer;
585 <  x, y: Word;
586 <  bpp:  Byte;
587 < begin
588 <  case Self.FStoreType of
589 <    9:
590 <      bpp := 8;
591 <    0, 1, 2:
592 <      bpp := 16;
593 <    8:
594 <      bpp := 32;
595 <    else
596 <      Result := 0;
597 <      Exit;
598 <  end;
599 <
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;
628 <  end
629 <  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
669 <  begin
670 <    for x := 0 to Self.FWidth - 1 do
584 >    if cols[col] > 0 then
585      begin
586 <      Target[((Self.FWidth * y + x) * 3) + 0 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 0];
587 <      Target[((Self.FWidth * y + x) * 3) + 1 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 1];
588 <      Target[((Self.FWidth * y + x) * 3) + 2 + 54] := Self.FData[(Self.FWidth * y + x) * 4 + 2];
589 <    end;
676 <  end;
677 <
678 <  for i := 0 to High(BMPheader) do
679 <    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 <
698 <
699 < procedure TOniImage.GetAsBMP(var Target: TStream);
700 < var
701 <  data: TByteData;
702 < begin
703 <  GetAsBMP(data);
704 <  Target.Write(data[0], Length(data));
705 < end;
706 <
707 <
708 < function TOniImage.LoadFromBMP(filename: String): Boolean;
709 < var
710 <  filestream: TFileStream;
711 <  tempd:      TByteData;
712 <
713 <  x, y: Integer;
714 < begin
715 <  filestream := TFileStream.Create(filename, fmOpenRead);
716 <  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;
586 >      if (col = 1) then
587 >        x := x + parts[part].w * stretch_x
588 >      else
589 >        x := x + parts[part].w;
590      end;
591    end;
592  
593 <  Self.FDataType := [DT_Decoded32];
594 < end;
595 <
596 <
772 <
773 <
774 < function TOniImage.WriteToBMP(filename: String): Boolean;
775 < var
776 <  filestream: TFileStream;
777 < begin
778 <  filestream := TFileStream.Create(filename, fmCreate);
779 <  GetAsBMP(TStream(filestream));
780 <  filestream.Free;
781 < end;
782 <
783 <
784 <
785 <
786 < function TOniImage.GetMipMappedImage(var faded: TByteData): Boolean;
787 < var
788 <  i:      Integer;
789 <  x, y:   Word;
790 <  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
800 <  begin
801 <    revert := True;
802 <    Self.RevertImage;
803 <  end
804 <  else
805 <    revert := False;
593 >  FreeImage(pspcimage);
594 >  for i := 0 to 8 do
595 >    if parts[i].used then
596 >      FreeImage(parts[i].imgdata);
597  
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;
598    Result := True;
827
828  if revert then
829    Self.RevertImage;
599   end;
600  
832
601   end.

Diff Legend

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