Changeset 25


Ignore:
Timestamp:
Dec 22, 2016, 2:34:33 PM (7 years ago)
Author:
chronos
Message:
  • Fixed: Memory leaks introduced by TFColor. TFColor now use reference counting as descendant of IFColor.
  • Added: Line drawing for TFPixmap class.
Location:
branches/gbitmap
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/gbitmap/Packages/FastGraphics/ColorFormats/UColorGray1.pas

    r24 r25  
    4646    procedure Fill(Color: IBColor); override;
    4747    procedure Fill(Func: TGetColorPos); override;
     48    procedure Line(P1, P2: TPoint; Color: IBColor); override;
    4849    procedure PaintToCanvas(Canvas: TCanvas); override;
    4950    function GetDataSize: Integer; override;
     
    132133end;
    133134
     135procedure TBPixmapGray1.Line(P1, P2: TPoint; Color: IBColor);
     136begin
     137  Pixmap.Canvas.Pen.Color := (Color as TBColorGray1).Value;
     138  Pixmap.Canvas.Pen.MoveTo(P1);
     139  Pixmap.Canvas.Pen.LineTo(P2);
     140end;
     141
    134142procedure TBPixmapGray1.PaintToCanvas(Canvas: TCanvas);
    135143begin
  • branches/gbitmap/Packages/FastGraphics/ColorFormats/UColorGray2.pas

    r24 r25  
    4646    procedure Fill(Color: IBColor); override;
    4747    procedure Fill(Func: TGetColorPos); override;
     48    procedure Line(P1, P2: TPoint; Color: IBColor); override;
    4849    procedure PaintToCanvas(Canvas: TCanvas); override;
    4950    function GetDataSize: Integer; override;
     
    127128end;
    128129
     130procedure TBPixmapGray2.Line(P1, P2: TPoint; Color: IBColor);
     131begin
     132  Pixmap.Canvas.Pen.Color := (Color as TBColorGray2).Value;
     133  Pixmap.Canvas.Pen.MoveTo(P1);
     134  Pixmap.Canvas.Pen.LineTo(P2);
     135end;
     136
    129137procedure TBPixmapGray2.PaintToCanvas(Canvas: TCanvas);
    130138begin
  • branches/gbitmap/Packages/FastGraphics/UFGraphics.pas

    r24 r25  
    4040    procedure Fill(Color: IBColor); virtual; overload;
    4141    procedure Fill(Func: TGetColorPos); virtual; overload;
     42    procedure Line(P1, P2: TPoint; Color: IBColor); virtual;
    4243    procedure PaintToCanvas(Canvas: TCanvas); virtual;
    4344    function GetDataSize: Integer; virtual;
     
    8889  end;
    8990
     91  IFColor = interface
     92  end;
     93
    9094  { TFColor }
    9195
    92   TFColor = class
     96  TFColor = class(TInterfacedObject, IFColor)
    9397  private
    9498    FBackend: IBColor;
     
    105109  end;
    106110
     111  TFCanvas = class;
     112  TFPixmap = class;
     113
     114  { TFBrush }
     115
     116  TFBrush = class
     117    Color: IFColor;
     118    Canvas: TFCanvas;
     119  end;
     120
     121  { TFPen }
     122
     123  TFPen = class
     124    Position: TPoint;
     125    Color: IFColor;
     126    Canvas: TFCanvas;
     127    procedure MoveTo(Pos: TPoint);
     128    procedure LineTo(Pos: TPoint);
     129  end;
     130
     131  { TFCanvas }
     132
     133  TFCanvas = class
     134    Pixmap: TFPixmap;
     135    Pen: TFPen;
     136    Brush: TFBrush;
     137    constructor Create;
     138    destructor Destroy; override;
     139  end;
     140
     141
    107142  { TFPixmap }
    108143
     
    110145  public
    111146    type
    112       TGetColorPos = function (Position: TPoint; ColorFormat: TColorFormat): TFColor of object;
     147      TGetColorPos = function (Position: TPoint; ColorFormat: TColorFormat): IFColor of object;
    113148  private
    114149    FBackend: TBImage;
     150    FCanvas: TFCanvas;
    115151    FColorFormat: TColorFormat;
    116152    FSize: TPoint;
    117153    FillCallBack: TGetColorPos;
    118154    function FillGetColor(Position: TPoint): IBColor;
    119     function GetPixel(X, Y: Integer): TFColor;
     155    function GetPixel(X, Y: Integer): IFColor;
    120156    procedure SetColorFormat(AValue: TColorFormat);
    121     procedure SetPixel(X, Y: Integer; AValue: TFColor);
     157    procedure SetPixel(X, Y: Integer; AValue: IFColor);
    122158    procedure SetSize(AValue: TPoint);
    123159  public
    124     procedure Fill(Color: TFColor); overload;
     160    procedure Fill(Color: IFColor); overload;
    125161    procedure Fill(Func: TGetColorPos); overload;
    126162    procedure PaintToCanvas(Canvas: TCanvas);
     
    128164    constructor Create(AOwner: TComponent); override;
    129165    destructor Destroy; override;
     166    property Canvas: TFCanvas read FCanvas;
    130167    property Backend: TBImage read FBackend;
    131168    property ColorFormat: TColorFormat read FColorFormat write SetColorFormat;
    132169    property Size: TPoint read FSize write SetSize;
    133     property Pixels[X, Y: Integer]: TFColor read GetPixel write SetPixel;
     170    property Pixels[X, Y: Integer]: IFColor read GetPixel write SetPixel;
    134171  end;
    135172
     
    149186begin
    150187  RegisterComponents('FastGraphics', [TFPixmap]);
     188end;
     189
     190{ TFPen }
     191
     192procedure TFPen.MoveTo(Pos: TPoint);
     193begin
     194  Position := Pos;
     195end;
     196
     197procedure TFPen.LineTo(Pos: TPoint);
     198begin
     199  Canvas.Pixmap.Backend.Line(Position, Pos, (Color as TFColor).Backend);
     200  Position := Pos;
     201end;
     202
     203{ TFCanvas }
     204
     205constructor TFCanvas.Create;
     206begin
     207  Pen := TFPen.Create;
     208  Pen.Canvas := Self;
     209  Brush := TFBrush.Create;
     210  Brush.Canvas := Self;
     211end;
     212
     213destructor TFCanvas.Destroy;
     214begin
     215  FreeAndNil(Pen);
     216  FreeAndNil(Brush);
     217  inherited Destroy;
    151218end;
    152219
     
    254321destructor TFColor.Destroy;
    255322begin
     323  FColorFormat := nil;
    256324  inherited Destroy;
    257325end;
     
    279347
    280348procedure TBImage.Fill(Func: TGetColorPos);
     349begin
     350end;
     351
     352procedure TBImage.Line(P1, P2: TPoint; Color: IBColor);
    281353begin
    282354end;
     
    309381function TFPixmap.FillGetColor(Position: TPoint): IBColor;
    310382begin
    311   Result := FillCallBack(Position, ColorFormat).Backend;
    312 end;
    313 
    314 function TFPixmap.GetPixel(X, Y: Integer): TFColor;
     383  Result := (FillCallBack(Position, ColorFormat) as TFColor).Backend;
     384end;
     385
     386function TFPixmap.GetPixel(X, Y: Integer): IFColor;
    315387begin
    316388  Result := TFColor.Create;
    317   Result.ColorFormat := ColorFormat;
    318   Result.FBackend := FBackend.Pixels[X, Y];
    319 end;
    320 
    321 procedure TFPixmap.SetPixel(X, Y: Integer; AValue: TFColor);
    322 begin
    323   FBackend.Pixels[X, Y] := AValue.FBackend;
     389  (Result as TFColor).ColorFormat := ColorFormat;
     390  (Result as TFColor).FBackend := FBackend.Pixels[X, Y];
     391end;
     392
     393procedure TFPixmap.SetPixel(X, Y: Integer; AValue: IFColor);
     394begin
     395  FBackend.Pixels[X, Y] := (AValue as TFColor).FBackend;
    324396end;
    325397
     
    331403end;
    332404
    333 procedure TFPixmap.Fill(Color: TFColor);
    334 begin
    335   FBackend.Fill(Color.Backend);
     405procedure TFPixmap.Fill(Color: IFColor);
     406begin
     407  FBackend.Fill((Color as TFColor).Backend);
    336408end;
    337409
     
    349421function TFPixmap.GetDataSize: Integer;
    350422begin
    351   FBackend.GetDataSize;
    352 end;
    353 
    354 constructor TFPixmap.Create;
     423  Result := FBackend.GetDataSize;
     424end;
     425
     426constructor TFPixmap.Create(AOwner: TComponent);
    355427begin
    356428  inherited;
     429  FBackend := TBImage.Create;
     430  FCanvas := TFCanvas.Create;
     431  FCanvas.Pixmap := Self;
    357432  ColorFormat := ColorFormatManager.GetFormat(0);
    358   FBackend := TBImage.Create;
    359433end;
    360434
    361435destructor TFPixmap.Destroy;
    362436begin
     437  FreeAndNil(FCanvas);
    363438  FreeAndNil(FBackend);
    364439  inherited Destroy;
  • branches/gbitmap/Packages/FastGraphics/UGGraphics.pas

    r24 r25  
    192192    ((Canvas as TGCanvas<TGColor>).Bitmap as TGPixmap<TGColor>).Pixels[Trunc(Position.X + I * (Pos.X - Position.X) / Len),
    193193      Trunc(Position.Y + I * (Pos.Y - Position.Y) / Len)] := Color;
     194  Position := Pos;
    194195end;
    195196
  • branches/gbitmap/UFormMain.pas

    r24 r25  
    2929    function RGB8Random(Position: TPoint): TColorRGB8;
    3030    function RGB16Random(Position: TPoint): TColorRGB16;
    31     function ColorRandom(Position: TPoint; ColorFormat: TColorFormat): UFGraphics.TFColor;
     31    function ColorRandom(Position: TPoint; ColorFormat: TColorFormat): IFColor;
    3232  public
    3333    procedure TestGray1;
     
    9898end;
    9999
    100 function TForm1.ColorRandom(Position: TPoint; ColorFormat: TColorFormat): UFGraphics.TFColor;
    101 begin
    102   Result := UFGraphics.TFColor.Create;
    103   Result.ColorFormat := ColorFormat;
    104   Result.SetRandom;
     100function TForm1.ColorRandom(Position: TPoint; ColorFormat: TColorFormat): IFColor;
     101begin
     102  Result := TFColor.Create;
     103  (Result as TFColor).ColorFormat := ColorFormat;
     104  (Result as TFColor).SetRandom;
    105105end;
    106106
     
    276276  with Image do begin
    277277    Size := Point(100, 100);
    278     ColorFormat := ColorFormatManager.Formats[5];
     278    ColorFormat := ColorFormatManager.Formats[2];
    279279    Fill(TFColor.Create(ColorFormat, cnWhite));
     280    Fill(ColorRandom);
    280281    Pixels[0, 0] := TFColor.Create(ColorFormat, cnBlack);
    281     Fill(ColorRandom);
     282    Canvas.Pen.Color := TFColor.Create(ColorFormat, cnBlack);
     283    Canvas.Pen.MoveTo(Point(10, 20));
     284    Canvas.Pen.LineTo(Point(60, 40));
    282285    PaintToCanvas(Image1.Picture.Bitmap.Canvas);
    283286    Label1.Caption := IntToStr(GetDataSize);
Note: See TracChangeset for help on using the changeset viewer.