diff options
-rw-r--r-- | gfx/gdi/gfx_gdi.pas | 6 | ||||
-rw-r--r-- | gfx/gelimage.pas | 91 | ||||
-rw-r--r-- | gfx/gfxbase.pas | 50 | ||||
-rw-r--r-- | gfx/x11/gfx_x11.pas | 8 |
4 files changed, 139 insertions, 16 deletions
diff --git a/gfx/gdi/gfx_gdi.pas b/gfx/gdi/gfx_gdi.pas index ac5753d6..90d2c491 100644 --- a/gfx/gdi/gfx_gdi.pas +++ b/gfx/gdi/gfx_gdi.pas @@ -879,6 +879,12 @@ begin Color^.rgbBlue := 255; Color^.rgbReserved := 0; end; + ftPal4, ftPal4A: + begin + FStride := (AWidth + 1) shr 1; + GetMem(BitmapInfo, SizeOf(TBitmapInfoHeader) + 16 * SizeOf(RGBQUAD)); + BitmapInfo^.bmiHeader.biClrUsed := 0; + end; ftPal8, ftPal8A: begin FStride := AWidth; diff --git a/gfx/gelimage.pas b/gfx/gelimage.pas index e33fa861..14b7b56e 100644 --- a/gfx/gelimage.pas +++ b/gfx/gelimage.pas @@ -79,6 +79,26 @@ begin end; end; +procedure ConvertPal4ToInternal(Params: TConvertParams; Data: Pointer; + StartX, EndX: Integer; Dest: Pointer); +var + b: Byte; +begin + // !!!: Just works for even StartX and EndX values + ASSERT((StartX and 1) = 0); + ASSERT((EndX and 1) = 0); + Inc(Data, StartX shr 1); + while StartX < EndX do + begin + b := PByte(Data)^; + PLongWord(Dest)[0] := Params.Palette[b shr 4]; + PLongWord(Dest)[1] := Params.Palette[b and 15]; + Inc(StartX, 2); + Inc(Data); + Inc(Dest, 8); + end; +end; + procedure ConvertPal8ToInternal(Params: TConvertParams; Data: Pointer; StartX, EndX: Integer; Dest: Pointer); begin @@ -92,6 +112,26 @@ begin end; end; +procedure ConvertRGB24ToInternal(Params: TConvertParams; Data: Pointer; + StartX, EndX: Integer; Dest: Pointer); +var + PixelIn: LongWord; +begin + Inc(Data, StartX * 3); + while StartX < EndX do + begin + PixelIn := 0; + Move(Data^, PixelIn, 3); + PLongWord(Dest)^ := + (((PixelIn shr Params.RedShiftR) and $ff) shl Params.RedShiftL) or + (((PixelIn shr Params.GreenShiftR) and $ff) shl Params.GreenShiftL) or + (((PixelIn shr Params.BlueShiftR) and $ff) shl Params.BlueShiftL); + Inc(StartX); + Inc(Data, 3); + Inc(Dest, 4); + end; +end; + procedure ConvertRGB32ToInternal(Params: TConvertParams; Data: Pointer; StartX, EndX: Integer; Dest: Pointer); var @@ -130,6 +170,26 @@ begin until Width = 0; end; +procedure ConvertInternalToRGB24(Params: TConvertParams; Data: Pointer; + Dest: Pointer; Width: Integer); +var + PixelIn, PixelOut: LongWord; +begin + repeat + PixelIn := PLongWord(Data)^; + PixelOut := + (((PixelIn and $0000ff) shr Params.RedShiftR) shl Params.RedShiftL) or + (((PixelIn and $00ff00) shr Params.GreenShiftR) shl Params.GreenShiftL) or + (((PixelIn and $ff0000) shr Params.BlueShiftR) shl Params.BlueShiftL); + PWord(Dest)^ := Word(PixelOut); + PByte(Dest)[2] := PixelOut shr 16; + + Inc(Data, 4); + Inc(Dest, 3); + Dec(Width); + until Width = 0; +end; + procedure ConvertInternalToRGB32(Params: TConvertParams; Data: Pointer; Dest: Pointer; Width: Integer); var @@ -215,7 +275,7 @@ begin Scanline := nil; ParamsI2D.BlueShiftL := 0; ParamsS2I.BlueShiftL := 0; - + case ASourceFormat.FormatType of ftMono: begin @@ -228,6 +288,13 @@ begin ParamsS2I.Palette[0] := 0; end; end; + ftPal4, ftPal4A: + begin + ConvertToInternal := @ConvertPal4ToInternal; + max := ConvertPalette(15, ParamsS2I); + for i := max + 1 to 15 do + ParamsS2I.Palette[i] := 0; + end; ftPal8, ftPal8A: begin ConvertToInternal := @ConvertPal8ToInternal; @@ -235,6 +302,16 @@ begin for i := max + 1 to 255 do ParamsS2I.Palette[i] := i or (i shl 8) or (i shl 16); end; + ftRGB24: + begin + ConvertToInternal := @ConvertRGB24ToInternal; + ParamsS2I.RedShiftR := 8 - + GetBitShiftAndCount(ASourceFormat.RedMask, ParamsS2I.RedShiftL); + ParamsS2I.GreenShiftR := 16 - + GetBitShiftAndCount(ASourceFormat.GreenMask, ParamsS2I.GreenShiftL); + ParamsS2I.BlueShiftR := 24 - + GetBitShiftAndCount(ASourceFormat.BlueMask, ParamsS2I.BlueShiftL); + end; ftRGB32: begin ConvertToInternal := @ConvertRGB32ToInternal; @@ -250,18 +327,28 @@ begin end; case ADestFormat.FormatType of + ftPal8, ftPal8A: + begin +// ConvertFromInternal := @ConvertInternalTo8Pal; +// SetupShifts(ADestFormat, ParamsI2D); + end; ftRGB16: begin ConvertFromInternal := @ConvertInternalToRGB16; SetupShifts(ADestFormat, ParamsI2D); end; + ftRGB24: + begin + ConvertFromInternal := @ConvertInternalToRGB24; + SetupShifts(ADestFormat, ParamsI2D); + end; ftRGB32: begin ConvertFromInternal := @ConvertInternalToRGB32; SetupShifts(ADestFormat, ParamsI2D); end; else - raise EGfxUnsupportedPixelFormat.Create(ASourceFormat); + raise EGfxUnsupportedPixelFormat.Create(ADestFormat); end; w := ASourceRect.Right - ASourceRect.Left; diff --git a/gfx/gfxbase.pas b/gfx/gfxbase.pas index 124d6dd7..d772566f 100644 --- a/gfx/gfxbase.pas +++ b/gfx/gfxbase.pas @@ -77,31 +77,33 @@ type TGfxPixel = LongWord; - TGfxFormatType = ( + TGfxImageType = ( ftInvalid, ftMono, // Monochrome + ftPal4, // 4 bpp using palette + ftPal4A, // 4 bpp using palette with alpha values > 0 ftPal8, // 8 bpp using palette ftPal8A, // 8 bpp using palette with alpha values > 0 ftRGB16, // 15/16 bpp RGB ftRGBA16, // 16 bpp RGBA + ftRGB24, // 24 bpp RGB ftRGB32, // 32 bpp RGB ftRGBA32); // 32 bpp RGBA TGfxPixelFormat = record - case FormatType: TGfxFormatType of - ftRGB16, ftRGBA16, ftRGB32, ftRGBA32: ( - RedMask: TGfxPixel; - GreenMask: TGfxPixel; - BlueMask: TGfxPixel; - AlphaMask: TGfxPixel); // only used for RGBA types - end; + FormatType: TGfxImageType; + RedMask: TGfxPixel; + GreenMask: TGfxPixel; + BlueMask: TGfxPixel; + AlphaMask: TGfxPixel; + end; const - FormatTypeBPPTable: array[TGfxFormatType] of Integer = - (0, 1, 8, 8, 16, 16, 32, 32); + FormatTypeBPPTable: array[TGfxImageType] of Integer = + (0, 1, 4, 4, 8, 8, 16, 16, 24, 32, 32); { Predefined colors } @@ -150,6 +152,20 @@ const BlueMask: 0; AlphaMask: 0); + PixelFormatPal4: TGfxPixelFormat = ( + FormatType: ftPal4; + RedMask: 0; + GreenMask: 0; + BlueMask: 0; + AlphaMask: 0); + + PixelFormatPal4A: TGfxPixelFormat = ( + FormatType: ftPal4A; + RedMask: 0; + GreenMask: 0; + BlueMask: 0; + AlphaMask: 0); + PixelFormatPal8: TGfxPixelFormat = ( FormatType: ftPal8; RedMask: 0; @@ -164,6 +180,20 @@ const BlueMask: 0; AlphaMask: 0); + PixelFormatRGB24: TGfxPixelFormat = ( + FormatType: ftRGB24; + RedMask: $0000ff; + GreenMask: $00ff00; + BlueMask: $ff0000; + AlphaMask: 0); + + PixelFormatBGR24: TGfxPixelFormat = ( + FormatType: ftRGB24; + RedMask: $ff0000; + GreenMask: $00ff00; + BlueMask: $0000ff; + AlphaMask: 0); + PixelFormatRGB32: TGfxPixelFormat = ( FormatType: ftRGB32; RedMask: $0000ff; diff --git a/gfx/x11/gfx_x11.pas b/gfx/x11/gfx_x11.pas index 26a68e63..0f2f69e6 100644 --- a/gfx/x11/gfx_x11.pas +++ b/gfx/x11/gfx_x11.pas @@ -818,12 +818,10 @@ begin case Attr.Depth of 1: PixelFormat.FormatType := ftMono; -// 4: PixelFormat.FormatType := ftPal4; - 4, + 4: PixelFormat.FormatType := ftPal4; 8: PixelFormat.FormatType := ftPal8; 16: PixelFormat.FormatType := ftRGB16; -// 24: PixelFormat.FormatType := ftRGB24; - 24, + 24: PixelFormat.FormatType := ftRGB24; 32: PixelFormat.FormatType := ftRGB32; else raise EX11Error.CreateFmt(SWindowUnsupportedPixelFormat, [Attr.Depth]); @@ -870,6 +868,8 @@ begin case APixelFormat.FormatType of ftMono: FStride := (AWidth + 7) shr 3; + ftPal4, ftPal4A: + FStride := (AWidth + 1) and not 1; else FStride := AWidth * (FormatTypeBPPTable[APixelFormat.FormatType] shr 3); end; |