Changeset 30 for trunk/Packages


Ignore:
Timestamp:
Dec 23, 2016, 10:07:39 AM (8 years ago)
Author:
chronos
Message:
  • Modified: Drawing and loading using bitmap rawimage improvement.
Location:
trunk/Packages/FastGraphics
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/FastGraphics/ColorFormats/UColorGray1.pas

    r26 r30  
    5050    procedure PaintToCanvas(Canvas: TCanvas); override;
    5151    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override;
     52    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override;
    5253    procedure LoadFromCanvas(Canvas: TCanvas); override;
     54    procedure LoadFromBitmap(Bitmap: TBitmap); override;
    5355    function GetDataSize: Integer; override;
    5456    constructor Create; override;
     
    158160end;
    159161
     162procedure TBPixmapGray1.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
     163begin
     164  Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.Gray1ToColor);
     165end;
     166
    160167procedure TBPixmapGray1.LoadFromCanvas(Canvas: TCanvas);
    161168begin
    162169  Pixmap.LoadFromCanvas(Canvas, Pixmap.ColorToGray1);
     170end;
     171
     172procedure TBPixmapGray1.LoadFromBitmap(Bitmap: TBitmap);
     173begin
     174  Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToGray1);
    163175end;
    164176
  • trunk/Packages/FastGraphics/ColorFormats/UColorGray2.pas

    r26 r30  
    5050    procedure PaintToCanvas(Canvas: TCanvas); override;
    5151    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override;
     52    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override;
    5253    procedure LoadFromCanvas(Canvas: TCanvas); override;
     54    procedure LoadFromBitmap(Bitmap: TBitmap); override;
    5355    function GetDataSize: Integer; override;
    5456    constructor Create; override;
     
    148150end;
    149151
     152procedure TBPixmapGray2.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
     153begin
     154  Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.Gray2ToColor);
     155end;
     156
    150157procedure TBPixmapGray2.LoadFromCanvas(Canvas: TCanvas);
    151158begin
    152159  Pixmap.LoadFromCanvas(Canvas, Pixmap.ColorToGray2);
     160end;
     161
     162procedure TBPixmapGray2.LoadFromBitmap(Bitmap: TBitmap);
     163begin
     164  Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToGray2);
    153165end;
    154166
  • trunk/Packages/FastGraphics/ColorFormats/UColorGray4.pas

    r26 r30  
    1717  TColorGray4 = Byte;
    1818
     19  { TPixmapGray4 }
     20
    1921  TPixmapGray4 = class(TGPixmapBit<TColorGray4>)
    2022    function Gray4ToColor(Value: TColorGray4): TColor;
     23    function ColorToGray4(Value: TColor): TColorGray4;
     24  end;
     25
     26  { TBColorGray4 }
     27
     28  TBColorGray4 = class(TBColor)
     29    Value: TColorGray4;
     30    constructor Create(Color: TColorGray4);
     31    procedure SetColorName(ColorName: TColorName); override;
     32    procedure SetRandom; override;
     33  end;
     34
     35  { TBPixmapGray4 }
     36
     37  TBPixmapGray4 = class(TBImage)
     38  private
     39    FillCallBack: TGetColorPos;
     40    function FillGetColor(Position: TPoint): TColorGray4;
     41  protected
     42    procedure SetSize(AValue: TPoint); override;
     43    function GetPixel(X, Y: Integer): IBColor;  override;
     44    procedure SetPixel(X, Y: Integer; AValue: IBColor); override;
     45  public
     46    Pixmap: TPixmapGray4;
     47    procedure Fill(Color: IBColor); override;
     48    procedure Fill(Func: TGetColorPos); override;
     49    procedure Line(P1, P2: TPoint; Color: IBColor); override;
     50    procedure PaintToCanvas(Canvas: TCanvas); override;
     51    procedure PaintToCanvas(Canvas: TCanvas; Rect: TRect); override;
     52    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override;
     53    procedure LoadFromCanvas(Canvas: TCanvas); override;
     54    procedure LoadFromBitmap(Bitmap: TBitmap); override;
     55    function GetDataSize: Integer; override;
     56    constructor Create; override;
     57    destructor Destroy; override;
    2158  end;
    2259
     
    3269  Name := 'Gray 4-bit';
    3370  BitDepth := 4;
     71  BackendColorClass := TBColorGray4;
     72  BackendImageClass := TBPixmapGray4;
    3473  AddChannel('Gray', 0, 4);
    3574end;
     
    4382end;
    4483
     84function TPixmapGray4.ColorToGray4(Value: TColor): TColorGray4;
     85begin
     86  Result := Trunc((((Value shr 16) and $ff) + ((Value shr 8) and $ff) + ((Value shr 0) and $ff)) / $300 * 16);
     87end;
     88
     89{ TBColorGray2 }
     90
     91constructor TBColorGray4.Create(Color: TColorGray4);
     92begin
     93  Value := Color;
     94end;
     95
     96procedure TBColorGray4.SetColorName(ColorName: TColorName);
     97begin
     98  case ColorName of
     99    cnBlack: Value := 0;
     100    cnGray: Value := 6;
     101    cnSilver: Value := 10;
     102    cnWhite: Value := 15;
     103    else Value := 0;
     104  end;
     105end;
     106
     107procedure TBColorGray4.SetRandom;
     108begin
     109  Value := Random(16);
     110end;
     111
     112{ TBPixmapGray2 }
     113
     114function TBPixmapGray4.FillGetColor(Position: TPoint): TColorGray4;
     115begin
     116  Result := (FillCallBack(Position) as TBColorGray4).Value;
     117end;
     118
     119procedure TBPixmapGray4.SetSize(AValue: TPoint);
     120begin
     121  inherited;
     122  Pixmap.Size := AValue;
     123end;
     124
     125function TBPixmapGray4.GetPixel(X, Y: Integer): IBColor;
     126begin
     127  Result := TBColorGray4.Create(Pixmap.Pixels[X, Y]);
     128end;
     129
     130procedure TBPixmapGray4.SetPixel(X, Y: Integer; AValue: IBColor);
     131begin
     132  Pixmap.Pixels[X, Y] := (AValue as TBColorGray4).Value;
     133end;
     134
     135procedure TBPixmapGray4.Fill(Color: IBColor);
     136begin
     137  if Color is TBColorGray4 then
     138    Pixmap.Fill((Color as TBColorGray4).Value);
     139end;
     140
     141procedure TBPixmapGray4.Fill(Func: TGetColorPos);
     142begin
     143  FillCallBack := Func;
     144  Pixmap.Fill(FillGetColor);
     145end;
     146
     147procedure TBPixmapGray4.Line(P1, P2: TPoint; Color: IBColor);
     148begin
     149  Pixmap.Canvas.Pen.Color := (Color as TBColorGray4).Value;
     150  Pixmap.Canvas.Pen.MoveTo(P1);
     151  Pixmap.Canvas.Pen.LineTo(P2);
     152end;
     153
     154procedure TBPixmapGray4.PaintToCanvas(Canvas: TCanvas);
     155begin
     156  Pixmap.PaintToCanvas(Canvas, Pixmap.Gray4ToColor);
     157end;
     158
     159procedure TBPixmapGray4.PaintToCanvas(Canvas: TCanvas; Rect: TRect);
     160begin
     161  Pixmap.PaintToCanvas(Canvas, Rect, Pixmap.Gray4ToColor);
     162end;
     163
     164procedure TBPixmapGray4.PaintToBitmap(Bitmap: TBitmap; Rect: TRect);
     165begin
     166  Pixmap.PaintToBitmap(Bitmap, Rect, Pixmap.Gray4ToColor);
     167end;
     168
     169procedure TBPixmapGray4.LoadFromCanvas(Canvas: TCanvas);
     170begin
     171  Pixmap.LoadFromCanvas(Canvas, Pixmap.ColorToGray4);
     172end;
     173
     174procedure TBPixmapGray4.LoadFromBitmap(Bitmap: TBitmap);
     175begin
     176  Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToGray4);
     177end;
     178
     179function TBPixmapGray4.GetDataSize: Integer;
     180begin
     181  Result := Pixmap.GetDataSize;
     182end;
     183
     184constructor TBPixmapGray4.Create;
     185begin
     186  Pixmap := TPixmapGray4.Create;
     187  Pixmap.BitsPerPixel := 4;
     188end;
     189
     190destructor TBPixmapGray4.Destroy;
     191begin
     192  FreeAndNil(Pixmap);
     193  inherited;
     194end;
     195
     196
    45197end.
    46198
  • trunk/Packages/FastGraphics/UGGraphics.pas

    r29 r30  
    199199  PixelPtr: PInteger;
    200200  PixelPtrMax: PInteger;
     201  PixelPtrMin: PInteger;
    201202  PixelRowPtr: PInteger;
    202203  P: TPixelFormat;
     
    209210    PixelRowPtr := PInteger(RawImage.Data);
    210211    BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     212    PixelPtrMin := PixelRowPtr;
    211213    PixelPtrMax := PixelRowPtr + RawImage.Description.Width * RawImage.Description.Height * BytePerPixel;
    212214    for Y := Rect.Top to Rect.Bottom - 1 do begin
    213215      PixelPtr := PixelRowPtr;
    214216      for X := Rect.Left to Rect.Right - 1 do begin
    215         if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and (PixelPtr < PixelPtrMax) then
     217        if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and
     218        (PixelPtr < PixelPtrMax) and (PixelPtr > PixelPtrMin) then
    216219          PixelPtr^ := ColorConvertFunc(Pixels[X, Y]);
    217220        Inc(PByte(PixelPtr), BytePerPixel);
Note: See TracChangeset for help on using the changeset viewer.