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

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

# Line 15 | Line 15 | type
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
# Line 23 | Line 24 | type
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;
# Line 45 | Line 47 | type
47  
48   implementation
49  
48 //uses Functions;
50   uses Img_DDSTypes, ImagingComponents;
51  
52  
# Line 55 | Line 56 | var
56    rect: TRect;
57   begin
58    InitImage(singleimg);
59 <  CloneImage(FImages[Index], singleimg);
59 >  CloneImage(FImages[Index-1], singleimg);
60    ConvertImage(singleimg, ifX8R8G8B8);
61    rect.Left := 0;
62    rect.Top := 0;
# Line 130 | Line 131 | begin
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;
# Line 170 | 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
192 (*
204    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $08, SizeOf(PSpc), @PSpc);
205    PSpc.TXMP := PSpc.TXMP div 256;
206    if PSpc.TXMP = 0 then
# Line 198 | Line 209 | begin
209      Exit;
210    end;
211    txmpimg := TOniImage.Create;
212 <  txmpimg.LoadFromTXMP(ConnectionID, PSpc.TXMP);
213 <  txmpimg.DecodeImageTo32bit;
214 < //  txmpimg.WriteToBMP('C:\file.bmp');
215 <  txmpimg.GetAs32bit(txmpdata);
216 < {    ShowMessage(IntToStr(txmpimg.Width)+'x'+IntToStr(txmpimg.Height));
206 <    for i:=0 to High(txmpdata) do
207 <      txmpimg.Data[i]:=txmpdata[i];
208 <    txmpimg.WriteToBMP('D:\file2.bmp');
209 < }
210 <  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 221 | 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 231 | 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
245 <            begin
246 <              parts[part].imgdata[(y * parts[part].w + x) * 4 + pixel] :=
247 <                txmpdata[((parts[part].y_txmp + y) * txmpimg.Width +
248 <                parts[part].x_txmp + x) * 4 + pixel];
249 <            end;
250 <          end;
251 <        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 258 | Line 257 | begin
257  
258    end;
259  
261  txmpimg.Free;
262  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));
268 <      for pixel := 0 to High(parts[i].imgdata) do
269 <        txmpimg.Data[pixel] := parts[i].imgdata[pixel];
270 <      txmpimg.Width := parts[i].w;
271 <      txmpimg.Height    := parts[i].h;
272 <      txmpimg.StoreType := 8;
273 <      txmpimg.DataType  := [DT_Decoded32];
274 <      txmpimg.Depth     := 32;
275 <      txmpimg.WriteToBMP('M:\' + IntToStr(i) + '.bmp');
264 > //      SaveImageToFile('M:\' + IntToStr(i) + '.bmp', parts[i].imgdata);
265      end;
266    end;
278  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;
287  SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
311  
312 <  //Combine data parts
313 <
314 <  Self.FDepth     := 32;
315 <  Self.FStoreType := 8;
293 <  Self.FDataType  := [DT_Decoded32];
294 <  //    Self.RevertImage;
295 < *)
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 423 | Line 443 | begin
443      ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data))
444    else
445      ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data));
446 +
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 <
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));
# Line 439 | 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;

Diff Legend

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