unit loaders; {$MODE OBJFPC} {$M+} interface uses type_fixes, framebuffers, colors; type // TODO coalesce with IPixmap, TFramebufferInfo. IPixmapInfo = interface function GetWidth : TCardinal; function GetHeight : TCardinal; function GetPixelBitfield : TPixelBitfield; { if any. } function GetColorspace : TColorspace; function GetPalette : TIColorArray; procedure SetWidth(aValue : TCardinal); procedure SetHeight(aValue : TCardinal); procedure SetPixelBitfield(aValue : TPixelBitfield); { if any. } procedure SetColorspace(aValue : TColorspace); procedure SetPalette(aValue : TIColorArray); property Width : TCardinal read GetWidth write SetWidth; property Height : TCardinal read GetHeight write SetHeight; property PixelComponents : TColorspace read GetColorspace write SetColorspace; {$IFDEF FIXED} property Palette : TIColorArray read GetPalette write SetPalette; property PixelBitfield : TPixelBitfield read GetPixelBitfield write SetPixelBitfield; { if any. } {$ENDIF} end; // TODO coalesce with IPixmap, TFramebufferInfo. TPixmapInfo = class(TInterfacedObject, IPixmapInfo, IInterface) private fWidth : TCardinal; fHeight : TCardinal; fPixelBitfield : TPixelBitfield; fColorspace : TColorspace; fPalette : TIColorArray; published constructor Create; protected function GetPalette : TIColorArray; function GetWidth : Cardinal; function GetHeight : Cardinal; function GetPixelBitfield : TPixelBitfield; { if any. } function GetColorspace : TColorspace; procedure SetWidth(aValue : TCardinal); procedure SetHeight(aValue : TCardinal); procedure SetPixelBitfield(aValue : TPixelBitfield); { if any. } procedure SetColorspace(aValue : TColorspace); procedure SetPalette(aValue : TIColorArray); published property Width : Cardinal read GetWidth write SetWidth; property Height : Cardinal read GetHeight write SetHeight; property Colorspace : TColorspace read GetColorspace write SetColorspace; public property PixelBitfield : TPixelBitfield read GetPixelBitfield write SetPixelBitfield; { if any. } property Palette : TIColorArray read GetPalette write SetPalette; end; TRun = class { speed... } protected fY : Cardinal; published property Y : Cardinal read fY write fY; // don't forget transparency support (alpha channel)... procedure LoadGrayscale(aInput : PByte; aInputSize{bytes} : TSize; aGrayBitCount : TByte); procedure LoadRGB(aInput : PByte; aInputSize{bytes} : TSize; aRedBitCount, aGreenBitCount, aBlueBitCount : TByte); procedure LoadPalette(aInput : PByte; aInputSize{bytes} : TSize; const aPalette : TIColorArray; aIndexBitCount : TByte); procedure LoadGrayscaleAlpha(aInput : PByte; aInputSize{bytes} : TSize; aGrayBitCount, aAlphaBitCount : TByte); procedure LoadRGBA(aInput : PByte; aInputSize{bytes} : TSize; aRedBitCount, aGreenBitCount, aBlueBitCount, aAlphaBitCount : TByte); end; ILoader = interface function GetHeaders : IPixmapInfo; property Headers : IPixmapInfo read GetHeaders; function NextRun() : TRun; end; // used by quite a few formats. supposed to be bitpacked and little-endian. {$PACKRECORDS C} TPaletteEntry = record Red, Green, Blue : TByte; end; // moved to "type_fixes": TFOURCC = type TUINT32; // array[0..3] of Char; implementation { TPixmapInfo } constructor TPixmapInfo.Create; begin inherited; end; function TPixmapInfo.GetWidth : Cardinal; begin Result := fWidth; end; function TPixmapInfo.GetHeight : Cardinal; begin Result := fHeight; end; function TPixmapInfo.GetPixelBitfield : TPixelBitfield; { if any. } begin Result := fPixelBitfield; end; function TPixmapInfo.GetColorspace : TColorspace; begin Result := fColorspace; end; function TPixmapInfo.GetPalette : TIColorArray; begin Result := fPalette; end; procedure TPixmapInfo.SetWidth(aValue : TCardinal); begin fWidth := aValue; end; procedure TPixmapInfo.SetHeight(aValue : TCardinal); begin fHeight := aValue; end; procedure TPixmapInfo.SetPixelBitfield(aValue : TPixelBitfield); { if any. } begin fPixelBitfield := aValue; end; procedure TPixmapInfo.SetColorspace(aValue : TColorspace); begin fColorspace := aValue; end; procedure TPixmapInfo.SetPalette(aValue : TIColorArray); begin fPalette := aValue; end; { TRun } { mode bits per component what. 0 1,2,4,8,16 Each pixel is a grayscale sample. 2 8,16 Each pixel is an R,G,B triple. 3 1,2,4,8 Each pixel is a palette index; 4 8,16 Each pixel is a grayscale sample, followed by an alpha sample. 6 8,16 Each pixel is an R,G,B triple, followed by an alpha sample. } procedure TRun.LoadGrayscale(aInput : PByte; aInputSize{bytes} : TSize; aGrayBitCount : TByte); begin // TODO end; procedure TRun.LoadRGB(aInput : PByte; aInputSize{bytes} : TSize; aRedBitCount, aGreenBitCount, aBlueBitCount : TByte); begin end; procedure TRun.LoadPalette(aInput : PByte; aInputSize{bytes} : TSize; const aPalette : TIColorArray; aIndexBitCount : TByte); begin end; procedure TRun.LoadGrayscaleAlpha(aInput : PByte; aInputSize{bytes} : TSize; aGrayBitCount, aAlphaBitCount : TByte); begin end; procedure TRun.LoadRGBA(aInput : PByte; aInputSize{bytes} : TSize; aRedBitCount, aGreenBitCount, aBlueBitCount, aAlphaBitCount : TByte); begin end; end.