Ignore:
Timestamp:
Sep 19, 2014, 9:25:56 AM (10 years ago)
Author:
chronos
Message:
  • Added: Mono image color format. Pixels/channels with lower size then byte are not supported yet.
  • Added: Slow image flip and mirror operation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ColorFormats/UColorRGBA8.pas

    r4 r7  
    1515    function GetBitDepth: Integer; override;
    1616    function GetName: string; override;
    17     function GetChannelBytePos(Channel: TGColorChannel): Integer; override;
     17    function GetChannelBitPos(Channel: TGColorChannel): Integer; override;
    1818    function GetChannelBitWidth(Channel: TGColorChannel): Integer; override;
    1919    function ColorToTColor(Color: TGColor): TColor; override;
     
    4242end;
    4343
    44 function TGColorFormatRGBA8.GetChannelBytePos(Channel: TGColorChannel): Integer;
     44function TGColorFormatRGBA8.GetChannelBitPos(Channel: TGColorChannel): Integer;
    4545begin
    4646  case Channel of
    4747    ccRed: Result := 0;
    48     ccGreen: Result := 1;
    49     ccBlue: Result := 2;
    50     ccOpacity: Result := 3;
     48    ccGreen: Result := 8;
     49    ccBlue: Result := 16;
     50    ccOpacity: Result := 24;
    5151    else raise Exception.Create('Unsupported color channel');
    5252  end;
     
    6262function TGColorFormatRGBA8.ColorToTColor(Color: TGColor): TColor;
    6363begin
    64   Result := PByte(Color.Data + GetChannelBytePos(ccRed))^ or
    65     (PByte(Color.Data + GetChannelBytePos(ccGreen))^ shl 8) or
    66     (PByte(Color.Data + GetChannelBytePos(ccBlue))^ shl 16);
     64  Result := PByte(Color.Data + (GetChannelBitPos(ccRed) shr 3))^ or
     65    (PByte(Color.Data + (GetChannelBitPos(ccGreen) shr 3))^ shl 8) or
     66    (PByte(Color.Data + (GetChannelBitPos(ccBlue) shr 3))^ shl 16);
    6767end;
    6868
    6969procedure TGColorFormatRGBA8.ColorFromTColor(GColor: TGColor; Color: TColor);
    7070begin
    71   PByte(GColor.Data + GetChannelBytePos(ccRed))^ := Color and $ff;
    72   PByte(GColor.Data + GetChannelBytePos(ccGreen))^ := (Color shr 8) and $ff;
    73   PByte(GColor.Data + GetChannelBytePos(ccBlue))^ := (Color shr 16) and $ff;
     71  PByte(GColor.Data + (GetChannelBitPos(ccRed) shr 3))^ := Color and $ff;
     72  PByte(GColor.Data + (GetChannelBitPos(ccGreen) shr 3))^ := (Color shr 8) and $ff;
     73  PByte(GColor.Data + (GetChannelBitPos(ccBlue) shr 3))^ := (Color shr 16) and $ff;
    7474end;
    7575
Note: See TracChangeset for help on using the changeset viewer.