Changeset 181


Ignore:
Timestamp:
May 19, 2007, 7:54:34 PM (14 years ago)
Author:
alloc
Message:
 
Location:
oup/current
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • oup/current/Global/OniImgClass.pas

    r128 r181  
    33interface
    44
    5 uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs;
     5uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs,
     6  Imaging, ImagingTypes;
    67
    78type
    89  TImgDataType = set of (DT_OniReverted, DT_Oni, DT_Decoded32);
     10
    911
    1012type
     
    1820    FStoreType: Byte;
    1921
     22    FImage:     TImageData;
     23
    2024    function ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData;
    2125    procedure RevertImage;
     
    2327  protected
    2428  public
     29    property Image:     TImageData   Read FImage     Write FImage;
    2530    property Loaded:    Boolean      Read FLoaded    Write FLoaded;
    2631    property DataType:  TImgDataType Read FDataType  Write FDataType;
     
    3641    function LoadFromTXMP(ConnectionID, FileID: Integer): Boolean;
    3742    function LoadFromTXMB(ConnectionID, FileID: Integer): Boolean;
     43    function GetImgSize(w,h, storetype: Integer): Integer;
    3844    function GetImageDataSize(fading: Boolean): Integer;
    3945
     
    5763
    5864//uses Functions;
    59 
    60 
     65uses Img_DDSTypes;
    6166
    6267
     
    7075  Self.FDepth     := 0;
    7176  Self.FStoreType := 0;
     77
     78  InitImage(FImage);
    7279end;
    7380
     
    473480var
    474481  img_addr: Integer;
     482  data: TMemoryStream;
     483  hdr: TDDSDXTHeader;
     484  imginfo: Integer;
     485  x,y, i: Integer;
    475486begin
    476487  Result := True;
    477488  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth);
    478489  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight);
    479   ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType),
    480     @Self.FStoreType);
     490  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType), @Self.FStoreType);
     491  ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(imginfo), @imginfo);
    481492  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
    482493    ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr)
     
    486497  case Self.FStoreType of
    487498    0, 1, 2:
    488     begin
    489       SetLength(Self.FData, Self.FWidth * Self.FHeight * 2);
    490499      Self.FDepth := 16;
    491     end;
    492500    8:
    493     begin
    494       SetLength(Self.FData, Self.FWidth * Self.FHeight * 4);
    495501      Self.FDepth := 32;
    496     end;
    497502    9:
    498     begin
    499       SetLength(Self.FData, Self.FWidth * Self.FHeight div 2);
    500503      Self.FDepth := 16;
    501     end;
    502504    else
    503505      Result := False;
     
    505507  end;
    506508
     509  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
     510    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data))
     511  else
     512    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data));
     513
     514  with hdr do
     515  begin
     516    FOURCC := 'DDS ';
     517    with SURFACEDESC2 do
     518    begin
     519      Size := 124;
     520      Flags := DDSD_CAPS or DDSD_PIXELFORMAT or DDSD_WIDTH or DDSD_HEIGHT;
     521      if FStoreType = 9 then
     522        Flags := Flags or DDSD_LINEARSIZE
     523      else
     524        Flags := Flags or DDSD_PITCH;
     525      if (imginfo and $01) > 0 then
     526        Flags := Flags or DDSD_MIPMAPCOUNT;
     527      Height := FHeight;
     528      Width := FWidth;
     529      if FStoreType = 9 then
     530        PitchOrLinearSize := FWidth * FHeight div 2
     531      else
     532        PitchOrLinearSize := FWidth * FDepth div 2;
     533      Depth := 0;
     534      MipMapCount := 1;
     535      x := FWidth;
     536      y := FHeight;
     537      while (x > 1) and (y > 1) do
     538      begin
     539        x := x div 2;
     540        y := y div 2;
     541        Inc(MipMapCount);
     542      end;
     543      for i := 1 to 11 do
     544        Reserved[i] := 0;
     545      with PIXELFORMAT do
     546      begin
     547        Size := 32;
     548        if FStoreType = 9 then
     549          Flags := DDPF_FOURCC
     550        else
     551          Flags := DDPF_RGB;
     552      end;
     553    end;
     554  end;
     555  LoadImageFromStream(data, FImage);
     556{
    507557  if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then
    508558    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, FData)
    509559  else
    510560    ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, FData);
    511 
     561}
    512562  Self.FDataType := [DT_OniReverted, DT_Oni];
    513563end;
     
    584634
    585635
     636function TOniImage.GetImgSize(w,h, storetype: Integer): Integer;
     637begin
     638  case storetype of
     639    0, 1, 2:
     640      Result := w*h*2;
     641    8:
     642      Result := w*h*4;
     643    9:
     644      Result := Max(1, w div 4) * Max(1, h div 4) * 8;
     645  else
     646    Result := -1;
     647  end;
     648end;
     649
    586650
    587651function TOniImage.GetImageDataSize(fading: Boolean): Integer;
     
    589653  size: Integer;
    590654  x, y: Word;
    591 
    592   function GetImgSize(w,h, storetype: Integer): Integer;
    593   begin
    594     case storetype of
    595       0, 1, 2:
    596         Result := w*h*2;
    597       8:
    598         Result := w*h*4;
    599       9:
    600         Result :=  Max(1, w div 4) * Max(1, h div 4) * 8;
    601     else
    602       Result := -1;
    603     end;
    604   end;
    605 
    606655begin
    607656  x    := Self.FWidth;
  • oup/current/OniUnPacker.dpr

    r129 r181  
    3030  _DataTypes in 'FileClasses\_DataTypes.pas',
    3131  _FileTypes in 'FileClasses\_FileTypes.pas',
    32   LevelDB in 'Helper\LevelDB.pas' {Form_LevelDB};
     32  LevelDB in 'Helper\LevelDB.pas' {Form_LevelDB},
     33  Img_DDSTypes in 'Global\Img_DDSTypes.pas';
    3334
    3435{$R *.res}
Note: See TracChangeset for help on using the changeset viewer.