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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.