Changeset 30


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
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r28 r30  
    1616  object PaintBox1: TPaintBox
    1717    Left = 0
    18     Height = 587
    19     Top = 0
     18    Height = 561
     19    Top = 26
    2020    Width = 920
    2121    Align = alClient
     
    3939      end>
    4040    SimplePanel = False
     41  end
     42  object ToolBar1: TToolBar
     43    Left = 0
     44    Height = 26
     45    Top = 0
     46    Width = 920
     47    Caption = 'ToolBar1'
     48    TabOrder = 1
     49    object ToolButton1: TToolButton
     50      Left = 1
     51      Top = 2
     52      Action = Core.AFileNew
     53    end
    4154  end
    4255  object MainMenu1: TMainMenu
  • trunk/Forms/UFormMain.pas

    r29 r30  
    4040    StatusBar1: TStatusBar;
    4141    Timer1: TTimer;
     42    ToolBar1: TToolBar;
     43    ToolButton1: TToolButton;
    4244    procedure FormActivate(Sender: TObject);
    4345    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     
    134136    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    135137    //Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect);
    136     //Bitmap.PaintToBitmap(TempBitmap, View.SrcRect);
     138    Bitmap.PaintToBitmap(TempBitmap, View.SrcRect);
    137139    //TempBitmap.EndUpdate(False);
    138140    PaintBox1.Canvas.StretchDraw(View.DestRect, TempBitmap);
  • trunk/Forms/UFormNew.pas

    r29 r30  
    7474
    7575  // Default
    76   SpinEditWidth.Value := 200;
    77   SpinEditHeight.Value := 100;
     76  if Assigned(Core.Project) then begin
     77    SpinEditWidth.Value := Core.Project.Bitmap.Size.X;
     78    SpinEditHeight.Value := Core.Project.Bitmap.Size.Y;
     79  end else begin
     80    SpinEditWidth.Value := 200;
     81    SpinEditHeight.Value := 100;
     82  end;
    7883  SpinEditDPI.Value := 72;
    7984end;
  • trunk/LibrePaint.lpi

    r28 r30  
    141141        <StackChecks Value="True"/>
    142142      </Checks>
     143      <VerifyObjMethodCallValidity Value="True"/>
    143144    </CodeGeneration>
    144145    <Linking>
    145       <Debugging>
    146         <UseHeaptrc Value="True"/>
    147       </Debugging>
    148146      <Options>
    149147        <Win32>
  • trunk/LibrePaint.lpr

    r28 r30  
    2222  // Heap trace
    2323  DeleteFile(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
    24   SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
     24  //SetHeapTraceOutput(ExtractFilePath(ParamStr(0)) + HeapTraceLog);
    2525  {$ENDIF}
    2626
  • 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);
  • trunk/UCore.lfm

    r28 r30  
    1111    left = 201
    1212    top = 160
    13     object AFileNew: TAction
    14       Category = 'File'
    15       Caption = 'New...'
    16       OnExecute = AFileNewExecute
    17     end
    1813    object AExit: TAction
    1914      Caption = 'Exit'
     
    4742      OnExecute = AZoomNormalExecute
    4843    end
     44    object AFileNew: TAction
     45      Category = 'File'
     46      Caption = 'New...'
     47      OnExecute = AFileNewExecute
     48      ShortCut = 16462
     49    end
    4950    object AFileOpen: TAction
    5051      Category = 'File'
    5152      Caption = 'Open...'
    5253      OnExecute = AFileOpenExecute
     54      ShortCut = 16463
    5355    end
    5456    object AFileClose: TAction
     
    6163      Caption = 'Save'
    6264      OnExecute = AFileSaveExecute
     65      ShortCut = 16467
    6366    end
    6467    object AFileSaveAs: TAction
  • trunk/UCore.pas

    r29 r30  
    4343    SavePictureDialog1: TSavePictureDialog;
    4444    procedure AExitExecute(Sender: TObject);
     45    procedure AFileNewExecute(Sender: TObject);
    4546    procedure AFileCloseExecute(Sender: TObject);
    4647    procedure AFileOpenExecute(Sender: TObject);
     
    5354    procedure AImageNegativeExecute(Sender: TObject);
    5455    procedure AImageRandomExecute(Sender: TObject);
    55     procedure AFileNewExecute(Sender: TObject);
    5656    procedure AZoomAllExecute(Sender: TObject);
    5757    procedure AZoomInExecute(Sender: TObject);
Note: See TracChangeset for help on using the changeset viewer.