Changeset 22 for branches/gbitmap


Ignore:
Timestamp:
Dec 22, 2016, 1:13:04 PM (8 years ago)
Author:
chronos
Message:
  • Modified: RGB8 related code moved to UColorRGB8 unit.
Location:
branches/gbitmap
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/gbitmap/ColorFormats/UColorRGB8.pas

    r21 r22  
    66
    77uses
    8   Classes, SysUtils, Graphics, GPixmap, GImage;
     8  Classes, SysUtils, GPixmap, GImage, Graphics;
    99
    1010type
     
    1414    constructor Create; override;
    1515  end;
     16
     17  { TColorRGB8 }
     18
     19  TColorRGB8 = record
     20    R: Byte;
     21    B: Byte;
     22    G: Byte;
     23    function Create(R, G, B: Byte): TColorRGB8;
     24  end;
     25
     26  TPixmapRGB8 = class(TGPixmap<TColorRGB8>)
     27    function RGB8ToColor(Value: TColorRGB8): TColor;
     28  end;
     29
     30  { TBColorRGB8 }
     31
     32  TBColorRGB8 = class(TBColor)
     33    Value: TColorRGB8;
     34    constructor Create(Color: TColorRGB8);
     35    procedure SetColorName(ColorName: TColorName); override;
     36    procedure SetRandom; override;
     37  end;
     38
     39  { TBImageRGB8 }
     40
     41  TBImageRGB8 = class(TBImage)
     42  private
     43    FillCallBack: TGetColorPos;
     44    function FillGetColor(Position: TPoint): TColorRGB8;
     45  protected
     46    procedure SetSize(AValue: TPoint); override;
     47  public
     48    Pixmap: TPixmapRGB8;
     49    procedure Fill(Color: IBColor); override;
     50    procedure Fill(Func: TGetColorPos); override;
     51    procedure PaintToCanvas(Canvas: TCanvas); override;
     52    function GetDataSize: Integer; override;
     53    constructor Create; override;
     54    destructor Destroy; override;
     55  end;
     56
    1657
    1758
     
    2566  BitDepth := 24;
    2667  Name := 'RGB8';
     68  BackendImageClass := TBImageRGB8;
     69  BackendColorClass := TBColorRGB8;
    2770  AddChannel('Red', 0, 8);
    2871  AddChannel('Green', 8, 8);
     
    3073end;
    3174
     75{ TColorRGB8 }
     76
     77function TColorRGB8.Create(R, G, B: Byte): TColorRGB8;
     78begin
     79  Result.R := R;
     80  Result.G := G;
     81  Result.B := B;
     82end;
     83
     84{ TPixmapRGB8 }
     85
     86function TPixmapRGB8.RGB8ToColor(Value: TColorRGB8): TColor;
     87begin
     88  Result := (Value.R shl 16) or (Value.G shl 8) or (Value.B shl 0);
     89end;
     90
     91{ TBColorRGB8 }
     92
     93constructor TBColorRGB8.Create(Color: TColorRGB8);
     94begin
     95  Value := Color;
     96end;
     97
     98procedure TBColorRGB8.SetColorName(ColorName: TColorName);
     99begin
     100  case ColorName of
     101    cnBlack: Value := TColorRGB8.Create(0, 0, 0);
     102    cnGray: Value := TColorRGB8.Create($80, $80, $80);
     103    cnSilver: Value := TColorRGB8.Create($C0, $C0, $C0);
     104    cnWhite: Value := TColorRGB8.Create($ff, $ff, $ff);
     105    else Value := TColorRGB8.Create(0, 0, 0);;
     106  end;
     107end;
     108
     109procedure TBColorRGB8.SetRandom;
     110begin
     111  Value := TColorRGB8.Create(Random(256), Random(256), Random(256));
     112end;
     113
     114{ TBImageRGB8 }
     115
     116function TBImageRGB8.FillGetColor(Position: TPoint): TColorRGB8;
     117begin
     118  Result := (FillCallBack(Position) as TBColorRGB8).Value;
     119end;
     120
     121procedure TBImageRGB8.SetSize(AValue: TPoint);
     122begin
     123  inherited;
     124  Pixmap.Size := AValue;
     125end;
     126
     127procedure TBImageRGB8.Fill(Color: IBColor);
     128begin
     129  if Color is TBColorRGB8 then
     130    Pixmap.Fill((Color as TBColorRGB8).Value);
     131end;
     132
     133procedure TBImageRGB8.Fill(Func: TGetColorPos);
     134begin
     135  FillCallBack := Func;
     136  Pixmap.Fill(FillGetColor);
     137end;
     138
     139procedure TBImageRGB8.PaintToCanvas(Canvas: TCanvas);
     140begin
     141  Pixmap.PaintToCanvas(Canvas, Pixmap.RGB8ToColor);
     142end;
     143
     144function TBImageRGB8.GetDataSize: Integer;
     145begin
     146  Result := Pixmap.GetDataSize;
     147end;
     148
     149constructor TBImageRGB8.Create;
     150begin
     151  Pixmap := TPixmapRGB8.Create;
     152end;
     153
     154destructor TBImageRGB8.Destroy;
     155begin
     156  FreeAndNil(Pixmap);
     157  inherited Destroy;
     158end;
     159
     160
    32161end.
    33162
  • branches/gbitmap/GImage.pas

    r21 r22  
    2424
    2525  IBColorClass = class of TBColor;
    26 
    27   { TBColorRGB8 }
    28 
    29   TBColorRGB8 = class(TBColor)
    30     Value: TColorRGB8;
    31     constructor Create(Color: TColorRGB8);
    32     procedure SetColorName(ColorName: TColorName); override;
    33     procedure SetRandom; override;
    34   end;
    3526
    3627  { TBImage }
     
    5748
    5849  TBPixmapClass = class of TBImage;
    59 
    60   { TBImageRGB8 }
    61 
    62   TBImageRGB8 = class(TBImage)
    63   protected
    64     procedure SetSize(AValue: TPoint); override;
    65   public
    66     Pixmap: TGPixmap<TColorRGB8>;
    67     procedure Fill(Color: IBColor); override;
    68     constructor Create;
    69     destructor Destroy; override;
    70   end;
    7150
    7251  { TColorFormatChannel }
     
    267246end;
    268247
    269 { TBColorRGB8 }
    270 
    271 constructor TBColorRGB8.Create(Color: TColorRGB8);
    272 begin
    273   Value := Color;
    274 end;
    275 
    276 procedure TBColorRGB8.SetColorName(ColorName: TColorName);
    277 begin
    278   case ColorName of
    279     cnBlack: Value := TColorRGB8.Create(0, 0, 0);
    280     cnGray: Value := TColorRGB8.Create($80, $80, $80);
    281     cnSilver: Value := TColorRGB8.Create($C0, $C0, $C0);
    282     cnWhite: Value := TColorRGB8.Create($ff, $ff, $ff);
    283     else Value := TColorRGB8.Create(0, 0, 0);;
    284   end;
    285 end;
    286 
    287 procedure TBColorRGB8.SetRandom;
    288 begin
    289   Value := TColorRGB8.Create(Random(256), Random(256), Random(256));
    290 end;
    291 
    292 { TBImageRGB8 }
    293 
    294 procedure TBImageRGB8.SetSize(AValue: TPoint);
    295 begin
    296   inherited;
    297   Pixmap.Size := AValue;
    298 end;
    299 
    300 procedure TBImageRGB8.Fill(Color: IBColor);
    301 begin
    302   if Color is TBColorRGB8 then
    303     Pixmap.Fill((Color as TBColorRGB8).Value);
    304 end;
    305 
    306 constructor TBImageRGB8.Create;
    307 begin
    308   Pixmap := TGPixmap<TColorRGB8>.Create;
    309 end;
    310 
    311 destructor TBImageRGB8.Destroy;
    312 begin
    313   FreeAndNil(Pixmap);
    314   inherited Destroy;
    315 end;
    316 
    317248{ TBImage }
    318249
  • branches/gbitmap/UFormMain.pas

    r21 r22  
    276276  with Image do begin
    277277    Size := Point(100, 100);
    278     ColorFormat := ColorFormatManager.Formats[1];
     278    ColorFormat := ColorFormatManager.Formats[5];
    279279    Fill(GImage.TColor.Create(ColorFormat, cnWhite));
    280280    Pixels[0, 0] := GImage.TColor.Create(ColorFormat, cnBlack);
  • branches/gbitmap/UPixmapSpecialized.pas

    r21 r22  
    1111  TColorGray16 = Word;
    1212  TColorGray32 = Cardinal;
    13 
    14   { TColorRGB8 }
    15 
    16   TColorRGB8 = record
    17     R: Byte;
    18     B: Byte;
    19     G: Byte;
    20     function Create(R, G, B: Byte): TColorRGB8;
    21   end;
    2213
    2314  { TColorRGB16 }
     
    4031  TPixmapGray32 = class(TGPixmap<TColorGray32>)
    4132    function Gray32ToColor(Value: TColorGray32): TColor;
    42   end;
    43 
    44   TPixmapRGB8 = class(TGPixmap<TColorRGB8>)
    45     function RGB8ToColor(Value: TColorRGB8): TColor;
    4633  end;
    4734
     
    6855end;
    6956
    70 { TColorRGB8 }
    71 
    72 function TColorRGB8.Create(R, G, B: Byte): TColorRGB8;
    73 begin
    74   Result.R := R;
    75   Result.G := G;
    76   Result.B := B;
    77 end;
    78 
    7957function TPixmapGray16.Gray16ToColor(Value: TColorGray16): TColor;
    8058begin
     
    8765  Value := (Value shr 24) and $ff;
    8866  Result := (Value shl 16) or (Value shl 8) or (Value shl 0);
    89 end;
    90 
    91 function TPixmapRGB8.RGB8ToColor(Value: TColorRGB8): TColor;
    92 begin
    93   Result := (Value.R shl 16) or (Value.G shl 8) or (Value.B shl 0);
    9467end;
    9568
Note: See TracChangeset for help on using the changeset viewer.