--- oup/current/Global/OniImgClass.pas 2007/03/28 00:57:53 128 +++ oup/current/Global/OniImgClass.pas 2007/05/19 17:54:34 181 @@ -2,11 +2,13 @@ unit OniImgClass; interface -uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs; +uses Math, Dialogs, Types, SysUtils, Classes, Data, ConnectionManager, TypeDefs, + Imaging, ImagingTypes; type TImgDataType = set of (DT_OniReverted, DT_Oni, DT_Decoded32); + type TOniImage = class private @@ -17,11 +19,14 @@ type FDepth: Byte; FStoreType: Byte; + FImage: TImageData; + function ResizeImage(oldx, oldy: Integer; img: TByteData): TByteData; procedure RevertImage; procedure DecompressImage; protected public + property Image: TImageData Read FImage Write FImage; property Loaded: Boolean Read FLoaded Write FLoaded; property DataType: TImgDataType Read FDataType Write FDataType; property Width: Word Read FWidth Write FWidth; @@ -35,6 +40,7 @@ type function LoadFromPSpc(ConnectionID, FileID: Integer): Boolean; function LoadFromTXMP(ConnectionID, FileID: Integer): Boolean; function LoadFromTXMB(ConnectionID, FileID: Integer): Boolean; + function GetImgSize(w,h, storetype: Integer): Integer; function GetImageDataSize(fading: Boolean): Integer; procedure DecodeImageTo32bit; @@ -56,8 +62,7 @@ type implementation //uses Functions; - - +uses Img_DDSTypes; constructor TOniImage.Create; @@ -69,6 +74,8 @@ begin Self.FHeight := 0; Self.FDepth := 0; Self.FStoreType := 0; + + InitImage(FImage); end; @@ -472,12 +479,16 @@ end; function TOniImage.LoadFromTXMP(ConnectionID, FileID: Integer): Boolean; var img_addr: Integer; + data: TMemoryStream; + hdr: TDDSDXTHeader; + imginfo: Integer; + x,y, i: Integer; begin Result := True; ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8C, SizeOf(Self.FWidth), @Self.FWidth); ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $8E, SizeOf(Self.FHeight), @Self.FHeight); - ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType), - @Self.FStoreType); + ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $90, SizeOf(Self.FStoreType), @Self.FStoreType); + ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $88, SizeOf(imginfo), @imginfo); if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then ConManager.Connection[ConnectionID].LoadDatFilePart(fileid, $9C, SizeOf(img_addr), @img_addr) else @@ -485,30 +496,69 @@ begin case Self.FStoreType of 0, 1, 2: - begin - SetLength(Self.FData, Self.FWidth * Self.FHeight * 2); Self.FDepth := 16; - end; 8: - begin - SetLength(Self.FData, Self.FWidth * Self.FHeight * 4); Self.FDepth := 32; - end; 9: - begin - SetLength(Self.FData, Self.FWidth * Self.FHeight div 2); Self.FDepth := 16; - end; else Result := False; Exit; end; if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then + ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, TStream(data)) + else + ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, TStream(data)); + + with hdr do + begin + FOURCC := 'DDS '; + with SURFACEDESC2 do + begin + Size := 124; + Flags := DDSD_CAPS or DDSD_PIXELFORMAT or DDSD_WIDTH or DDSD_HEIGHT; + if FStoreType = 9 then + Flags := Flags or DDSD_LINEARSIZE + else + Flags := Flags or DDSD_PITCH; + if (imginfo and $01) > 0 then + Flags := Flags or DDSD_MIPMAPCOUNT; + Height := FHeight; + Width := FWidth; + if FStoreType = 9 then + PitchOrLinearSize := FWidth * FHeight div 2 + else + PitchOrLinearSize := FWidth * FDepth div 2; + Depth := 0; + MipMapCount := 1; + x := FWidth; + y := FHeight; + while (x > 1) and (y > 1) do + begin + x := x div 2; + y := y div 2; + Inc(MipMapCount); + end; + for i := 1 to 11 do + Reserved[i] := 0; + with PIXELFORMAT do + begin + Size := 32; + if FStoreType = 9 then + Flags := DDPF_FOURCC + else + Flags := DDPF_RGB; + end; + end; + end; + LoadImageFromStream(data, FImage); +{ + if ConManager.Connection[ConnectionID].DataOS = DOS_WIN then ConManager.Connection[ConnectionID].LoadRawFile(fileid, $9C, FData) else ConManager.Connection[ConnectionID].LoadRawFile(fileid, $A0, FData); - +} Self.FDataType := [DT_OniReverted, DT_Oni]; end; @@ -583,26 +633,25 @@ end; +function TOniImage.GetImgSize(w,h, storetype: Integer): Integer; +begin + case storetype of + 0, 1, 2: + Result := w*h*2; + 8: + Result := w*h*4; + 9: + Result := Max(1, w div 4) * Max(1, h div 4) * 8; + else + Result := -1; + end; +end; + function TOniImage.GetImageDataSize(fading: Boolean): Integer; var size: Integer; x, y: Word; - - function GetImgSize(w,h, storetype: Integer): Integer; - begin - case storetype of - 0, 1, 2: - Result := w*h*2; - 8: - Result := w*h*4; - 9: - Result := Max(1, w div 4) * Max(1, h div 4) * 8; - else - Result := -1; - end; - end; - begin x := Self.FWidth; y := Self.FHeight;