Ignore:
Timestamp:
Dec 20, 2016, 6:02:51 PM (8 years ago)
Author:
chronos
Message:
  • Added: Define specialized classes for various usual pixmaxs.
Location:
branches/gbitmap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/gbitmap

    • Property svn:ignore
      •  

        old new  
        33project1.lps
        44project1.res
         5project1.exe
  • branches/gbitmap/GImage.pas

    r18 r19  
    66
    77uses
    8   Classes, SysUtils, GPixmap;
     8  Classes, SysUtils, Graphics, GPixmap, UPixmapSpecialized;
    99
    1010type
    11   TColorGray8 = Byte;
    12 
    13   { TRGB8 }
    14 
    15   TRGB8 = record
    16     R: Byte;
    17     B: Byte;
    18     G: Byte;
    19     function Create(R, G, B: Byte): TRGB8;
    20   end;
    21 
    22 
    2311  TBColor = class
    2412  end;
    2513
    2614  TBColorGray1 = class(TBColor)
    27     Value: TColorGray8;
     15    Value: TColorGray1;
     16  end;
     17
     18  TBColorGray2 = class(TBColor)
     19    Value: TColorGray2;
    2820  end;
    2921
    3022  TBColorRGB8 = class(TBColor)
    31     Value: TRGB8;
     23    Value: TColorRGB8;
    3224  end;
    3325
     
    3527
    3628  TBImage = class
    37     procedure Fill(Color: TBColor); virtual;
     29  public
     30    type
     31      TGetColorPos = function (Position: TPoint): TBColor of object;
     32  private
     33    FSize: TPoint;
     34  protected
     35    procedure SetSize(AValue: TPoint); virtual;
     36  public
     37    procedure Fill(Color: TBColor); virtual; overload;
     38    procedure Fill(Func: TGetColorPos); virtual; overload;
     39    procedure PaintToCanvas(Canvas: TCanvas); virtual;
     40    property Size: TPoint read FSize write SetSize;
    3841  end;
    3942
     
    4144
    4245  TBImageGray1 = class(TBImage)
    43     Pixmap: TGPixmap<TColorGray8>;
     46  protected
     47    procedure SetSize(AValue: TPoint); override;
     48  public
     49    Pixmap: TPixmapGray1;
    4450    procedure Fill(Color: TBColor); override;
     51    procedure Fill(Func: TGetColorPos); override;
     52    procedure PaintToCanvas(Canvas: TCanvas); override;
     53    constructor Create;
     54    destructor Destroy; override;
     55  end;
     56
     57  { TBImageGray2 }
     58
     59  TBImageGray2 = class(TBImage)
     60  protected
     61    procedure SetSize(AValue: TPoint); override;
     62  public
     63    Pixmap: TPixmapGray2;
     64    procedure Fill(Color: TBColor); override;
     65    procedure PaintToCanvas(Canvas: TCanvas); override;
     66    constructor Create;
     67    destructor Destroy; override;
    4568  end;
    4669
     
    4871
    4972  TBImageRGB8 = class(TBImage)
    50     Pixmap: TGPixmap<TRGB8>;
     73  protected
     74    procedure SetSize(AValue: TPoint); override;
     75  public
     76    Pixmap: TGPixmap<TColorRGB8>;
    5177    procedure Fill(Color: TBColor); override;
    52   end;
    53 
    54 
    55   TColorFormat = (cfNone, cfGray1, cfRGB8);
    56 
    57   { TImage }
    58 
    59   TImage = class
     78    constructor Create;
     79    destructor Destroy; override;
     80  end;
     81
     82
     83  TColorFormat = (cfNone, cfGray1, cfGray2, cfGray4, cfGray8, cfGray16, cfGray32,
     84    cfRGB8, cfRGB16);
     85
     86  { TGImage }
     87
     88  TGImage = class
     89  public
     90    type
     91      TGetColorPos = function (Position: TPoint): TBColor of object;
    6092  private
    6193    FBackend: TBImage;
    6294    FColorFormat: TColorFormat;
     95    FSize: TPoint;
    6396    procedure SetColorFormat(AValue: TColorFormat);
     97    procedure SetSize(AValue: TPoint);
    6498  public
    6599    property Backend: TBImage read FBackend;
    66100    property ColorFormat: TColorFormat read FColorFormat write SetColorFormat;
    67     procedure Fill(Color: TBColor);
    68     constructor Create;
    69     destructor Destroy; override;
    70   end;
     101    property Size: TPoint read FSize write SetSize;
     102    procedure Fill(Color: TBColor); overload;
     103    procedure Fill(Func: TGetColorPos); overload;
     104    procedure PaintToCanvas(Canvas: TCanvas);
     105    constructor Create;
     106    destructor Destroy; override;
     107  end;
     108
    71109
    72110implementation
    73111
    74 { TRGB8 }
    75 
    76 function TRGB8.Create(R, G, B: Byte): TRGB8;
    77 begin
    78   Result.R := R;
    79   Result.G := G;
    80   Result.B := B;
    81 end;
     112{ TBImageGray2 }
     113
     114procedure TBImageGray2.SetSize(AValue: TPoint);
     115begin
     116  inherited;
     117  Pixmap.Size := AValue;
     118end;
     119
     120procedure TBImageGray2.Fill(Color: TBColor);
     121begin
     122  if Color is TBColorGray2 then
     123    Pixmap.Fill((Color as TBColorGray2).Value);
     124end;
     125
     126procedure TBImageGray2.PaintToCanvas(Canvas: TCanvas);
     127begin
     128  Pixmap.PaintToCanvas(Canvas, Pixmap.Gray2ToColor);
     129end;
     130
     131constructor TBImageGray2.Create;
     132begin
     133  Pixmap := TPixmapGray2.Create;
     134end;
     135
     136destructor TBImageGray2.Destroy;
     137begin
     138  Pixmap.Free;
     139  inherited Destroy;
     140end;
     141
    82142
    83143{ TBImageRGB8 }
     144
     145procedure TBImageRGB8.SetSize(AValue: TPoint);
     146begin
     147  inherited;
     148  Pixmap.Size := AValue;
     149end;
    84150
    85151procedure TBImageRGB8.Fill(Color: TBColor);
     
    89155end;
    90156
     157constructor TBImageRGB8.Create;
     158begin
     159  Pixmap := TGPixmap<TColorRGB8>.Create;
     160end;
     161
     162destructor TBImageRGB8.Destroy;
     163begin
     164  Pixmap.Free;
     165  inherited Destroy;
     166end;
     167
    91168{ TBImage }
    92169
     170procedure TBImage.SetSize(AValue: TPoint);
     171begin
     172  if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit;
     173  FSize := AValue;
     174end;
     175
    93176procedure TBImage.Fill(Color: TBColor);
    94177begin
    95178end;
    96179
     180procedure TBImage.Fill(Func: TGetColorPos);
     181begin
     182end;
     183
     184procedure TBImage.PaintToCanvas(Canvas: TCanvas);
     185begin
     186end;
     187
    97188{ TBImageGray1 }
     189
     190procedure TBImageGray1.SetSize(AValue: TPoint);
     191begin
     192  inherited;
     193  Pixmap.Size := AValue;
     194end;
    98195
    99196procedure TBImageGray1.Fill(Color: TBColor);
     
    103200end;
    104201
    105 { TImage }
    106 
    107 procedure TImage.SetColorFormat(AValue: TColorFormat);
     202procedure TBImageGray1.Fill(Func: TGetColorPos);
     203begin
     204  //Pixmap.Fill();
     205end;
     206
     207procedure TBImageGray1.PaintToCanvas(Canvas: TCanvas);
     208begin
     209  Pixmap.PaintToCanvas(Canvas, Pixmap.Gray1ToColor);
     210end;
     211
     212constructor TBImageGray1.Create;
     213begin
     214  Pixmap := TPixmapGray1.Create;
     215end;
     216
     217destructor TBImageGray1.Destroy;
     218begin
     219  Pixmap.Free;
     220  inherited Destroy;
     221end;
     222
     223{ TGImage }
     224
     225procedure TGImage.SetColorFormat(AValue: TColorFormat);
    108226begin
    109227  if FColorFormat = AValue then Exit;
    110228  FBackend.Free;
    111   if FColorFormat = cfGray1 then
    112     FBackend := TBImageGray1.Create;
    113   if FColorFormat = cfRGB8 then
    114     FBackend := TBImageRGB8.Create;
     229  if AValue = cfGray1 then FBackend := TBImageGray1.Create
     230  else if AValue = cfGray2 then FBackend := TBImageGray2.Create
     231  else if AValue = cfRGB8 then FBackend := TBImageRGB8.Create
     232  else FBackend := nil;
     233  if Assigned(FBackend) then FBackend.Size := FSize;
    115234  FColorFormat := AValue;
    116235end;
    117236
    118 procedure TImage.Fill(Color: TBColor);
    119 begin
    120   if Assigned(Backend) then
    121     Backend.Fill(Color);
    122 end;
    123 
    124 constructor TImage.Create;
     237procedure TGImage.SetSize(AValue: TPoint);
     238begin
     239  if (FSize.X = AValue.X) and (FSize.Y = AValue.Y) then Exit;
     240  FSize := AValue;
     241  if Assigned(FBackend) then
     242    FBackend.Size := AValue;
     243end;
     244
     245procedure TGImage.Fill(Color: TBColor);
     246begin
     247  if Assigned(FBackend) then FBackend.Fill(Color);
     248end;
     249
     250procedure TGImage.Fill(Func: TGetColorPos);
     251begin
     252//  if Assigned(FBackend) then FBackend.Fill(Func: TGetColorPos);
     253end;
     254
     255procedure TGImage.PaintToCanvas(Canvas: TCanvas);
     256begin
     257  if Assigned(FBackend) then FBackend.PaintToCanvas(Canvas);
     258end;
     259
     260constructor TGImage.Create;
    125261begin
    126262  FBackend := nil;
    127263end;
    128264
    129 destructor TImage.Destroy;
     265destructor TGImage.Destroy;
    130266begin
    131267  if Assigned(FBackend) then FreeAndNil(FBackend);
Note: See TracChangeset for help on using the changeset viewer.