Changeset 29 for trunk


Ignore:
Timestamp:
Dec 22, 2016, 9:46:17 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Load image data from file quickly using Bitmap RawImage.
  • Modified: Remember last selected color format.
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.pas

    r28 r29  
    129129    TempBitmap.SetSize(View.SrcRect.Right - View.SrcRect.Left,
    130130      View.SrcRect.Bottom - View.SrcRect.Top);
    131     TempBitmap.BeginUpdate(True);
     131    //TempBitmap.BeginUpdate(True);
    132132    TempBitmap.Canvas.Brush.Color := clBlack;
    133133    TempBitmap.Canvas.FillRect(0, 0, TempBitmap.Width, TempBitmap.Height);
    134134    View.DestRect := Bounds(0, 0, PaintBox1.Width, PaintBox1.Height);
    135     Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect);
     135    //Bitmap.PaintToCanvas(TempBitmap.Canvas, View.SrcRect);
    136136    //Bitmap.PaintToBitmap(TempBitmap, View.SrcRect);
    137     TempBitmap.EndUpdate(False);
     137    //TempBitmap.EndUpdate(False);
    138138    PaintBox1.Canvas.StretchDraw(View.DestRect, TempBitmap);
    139139    //PaintBox1.Canvas.Draw(0, 0, TempBitmap);
  • trunk/Forms/UFormNew.pas

    r28 r29  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Spin,
    9   StdCtrls, ActnList, UFGraphics;
     9  StdCtrls, ActnList, UFGraphics, URegistry;
    1010
    1111type
     
    3232    { private declarations }
    3333  public
    34     { public declarations }
    3534  end;
    3635
     
    7170    ComboBoxColorFormat.ItemIndex := 0;
    7271
     72  if ComboBoxColorFormat.Items.IndexOf(Core.LastColorFormat) <> -1 then
     73    ComboBoxColorFormat.ItemIndex := ComboBoxColorFormat.Items.IndexOf(Core.LastColorFormat);
     74
    7375  // Default
    7476  SpinEditWidth.Value := 200;
     
    7981procedure TFormNew.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    8082begin
     83  Core.LastColorFormat := ComboBoxColorFormat.Items[ComboBoxColorFormat.ItemIndex];
    8184  Core.PersistentForm1.Save(Self);
    8285end;
  • trunk/Packages/Common/Languages/UJobProgressView.cs.po

    r28 r29  
    3939msgid "Total estimated time: %s"
    4040msgstr "CelkovÜ odhadovanÜ čas: %s"
     41
  • trunk/Packages/FastGraphics/ColorFormats/UColorRGB8.pas

    r28 r29  
    5656    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); override;
    5757    procedure LoadFromCanvas(Canvas: TCanvas); override;
     58    procedure LoadFromBitmap(Bitmap: TBitmap); override;
    5859    function GetDataSize: Integer; override;
    5960    constructor Create; override;
     
    170171end;
    171172
     173procedure TBPixmapRGB8.LoadFromBitmap(Bitmap: TBitmap);
     174begin
     175  Pixmap.LoadFromBitmap(Bitmap, Pixmap.ColorToRGB8);
     176end;
     177
    172178function TBPixmapRGB8.GetDataSize: Integer;
    173179begin
  • trunk/Packages/FastGraphics/UFGraphics.pas

    r27 r29  
    4545    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); virtual;
    4646    procedure LoadFromCanvas(Canvas: TCanvas); virtual;
     47    procedure LoadFromBitmap(Bitmap: TBitmap); virtual;
    4748    function GetDataSize: Integer; virtual;
    4849    constructor Create; virtual;
     
    174175    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect); overload;
    175176    procedure LoadFromCanvas(Canvas: TCanvas);
     177    procedure LoadFromBitmap(Bitmap: TBitmap);
    176178    function GetDataSize: Integer;
    177179    constructor Create(AOwner: TComponent); override;
     
    383385end;
    384386
     387procedure TBImage.LoadFromBitmap(Bitmap: TBitmap);
     388begin
     389end;
     390
    385391function TBImage.GetDataSize: Integer;
    386392begin
     
    495501begin
    496502  Backend.LoadFromCanvas(Canvas);
     503end;
     504
     505procedure TFPixmap.LoadFromBitmap(Bitmap: TBitmap);
     506begin
     507  Backend.LoadFromBitmap(Bitmap);
    497508end;
    498509
  • trunk/Packages/FastGraphics/UGGraphics.pas

    r27 r29  
    6868    procedure PaintToBitmap(Bitmap: TBitmap; Rect: TRect; ColorConvertFunc: TGConvertColor);
    6969    procedure LoadFromCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertFromColor); overload;
     70    procedure LoadFromBitmap(Bitmap: TBitmap; ColorConvertFunc: TGConvertFromColor);
    7071    procedure Fill(Color: TGColor); overload;
    7172    procedure Fill(Func: TGGetColor); overload;
     
    224225end;
    225226
    226 procedure TGPixmap<TGColor>.LoadFromCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertFromColor); overload;
     227procedure TGPixmap<TGColor>.LoadFromCanvas(Canvas: TCanvas; ColorConvertFunc: TGConvertFromColor);
    227228var
    228229  X, Y: Integer;
     
    236237  finally
    237238    Canvas.Unlock;
     239  end;
     240end;
     241
     242procedure TGPixmap<TGColor>.LoadFromBitmap(Bitmap: TBitmap; ColorConvertFunc: TGConvertFromColor);
     243var
     244  X, Y: Integer;
     245  PixelPtr: PInteger;
     246  PixelPtrMax: PInteger;
     247  PixelRowPtr: PInteger;
     248  P: TPixelFormat;
     249  RawImage: TRawImage;
     250  BytePerPixel: Integer;
     251begin
     252  try
     253    Bitmap.BeginUpdate(False);
     254    RawImage := Bitmap.RawImage;
     255    PixelRowPtr := PInteger(RawImage.Data);
     256    BytePerPixel := RawImage.Description.BitsPerPixel div 8;
     257    PixelPtrMax := PixelRowPtr + RawImage.Description.Width * RawImage.Description.Height * BytePerPixel;
     258    for Y := 0 to FSize.Y - 1 do begin
     259      PixelPtr := PixelRowPtr;
     260      for X := 0 to FSize.X - 1 do begin
     261        if (X >= 0) and (X < FSize.X) and (Y >= 0) and (Y < FSize.Y) and (PixelPtr < PixelPtrMax) then
     262          Pixels[X, Y] := ColorConvertFunc(PixelPtr^);
     263        Inc(PByte(PixelPtr), BytePerPixel);
     264      end;
     265      Inc(PByte(PixelRowPtr), RawImage.Description.BytesPerLine);
     266    end;
     267  finally
     268    Bitmap.EndUpdate(False);
    238269  end;
    239270end;
  • trunk/UCore.pas

    r28 r29  
    77uses
    88  Classes, SysUtils, FileUtil, ActnList, UProject, UFGraphics, UPersistentForm,
    9   Controls, Graphics, ExtDlgs, ExtCtrls, UREgistry, UApplicationInfo, Registry;
     9  Controls, Graphics, ExtDlgs, ExtCtrls, URegistry, UApplicationInfo, Registry;
    1010
    1111const
     
    6262  private
    6363  public
     64    LastColorFormat: string;
    6465    Project: TProject;
     66    RegistryContext: TRegistryContext;
    6567    procedure ProjectOpen(FileName: string);
    6668    procedure Init;
     69    procedure LoadConfig;
     70    procedure SaveConfig;
    6771  end;
    6872
     
    8892procedure TCore.DataModuleCreate(Sender: TObject);
    8993begin
     94  RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
     95    ApplicationInfo1.RegistryKey);
    9096  Project := TProject.Create;
    9197end;
     
    9399procedure TCore.DataModuleDestroy(Sender: TObject);
    94100begin
    95   Project.Free;
     101  FreeAndNil(Project);
     102  SaveConfig;
    96103end;
    97104
     
    103110  Image := TImage.Create(nil);
    104111  Image.Picture.LoadFromFile(FileName);
    105   Image.Picture.Bitmap.BeginUpdate(True);
     112  //Image.Picture.Bitmap.BeginUpdate(True);
    106113  Project.Bitmap.Size := Point(Image.Picture.Bitmap.Width, Image.Picture.Bitmap.Height);
    107   Project.Bitmap.LoadFromCanvas(Image.Picture.Bitmap.Canvas);
    108   Image.Picture.Bitmap.EndUpdate;
     114  //Project.Bitmap.LoadFromCanvas(Image.Picture.Bitmap.Canvas);
     115  Project.Bitmap.LoadFromBitmap(Image.Picture.Bitmap);
     116  //Image.Picture.Bitmap.EndUpdate;
    109117  Image.Free;
    110118  AZoomAll.Execute;
     
    115123procedure TCore.Init;
    116124begin
    117   PersistentForm1.RegistryContext := RegContext(HKEY(ApplicationInfo1.RegistryRoot),
    118     ApplicationInfo1.RegistryKey);
     125  PersistentForm1.RegistryContext := RegistryContext;
     126  LoadConfig;
    119127
    120128  // Set default
     
    123131  Project.View.DestRect := Bounds(0, 0, FormMain.PaintBox1.Width, FormMain.PaintBox1.Height);
    124132  Core.AZoomAll.Execute;
     133end;
     134
     135procedure TCore.LoadConfig;
     136begin
     137  with TRegistryEx.Create do
     138  try
     139    RootKey := RegistryContext.RootKey;
     140    OpenKey(RegistryContext.Key, True);
     141
     142    LastColorFormat := ReadStringWithDefault('LastColorFormat', '');
     143  finally
     144    Free;
     145  end;
     146end;
     147
     148procedure TCore.SaveConfig;
     149begin
     150  with TRegistryEx.Create do
     151  try
     152    RootKey := RegistryContext.RootKey;
     153    OpenKey(RegistryContext.Key, True);
     154
     155    WriteString('LastColorFormat', LastColorFormat);
     156  finally
     157    Free;
     158  end;
    125159end;
    126160
Note: See TracChangeset for help on using the changeset viewer.