Ignore:
Timestamp:
Feb 1, 2012, 3:02:33 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package to version 5.5.
  • Modified: Removed draw method ComboBox and reorganized method list to single listview with using ownerdraw facility.
  • Added: New draw method TBitmap.RawImage.Data Move which use fast Move operation. It requires same pixel format.
  • Added: New draw method Dummy for comparion of empty method and to determine possibily max frame rate limit.
Location:
GraphicTest/BGRABitmap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/BGRABitmap

    • Property svn:ignore set to
      lib
  • GraphicTest/BGRABitmap/bgragtkbitmap.pas

    r210 r317  
    3737  private
    3838    FPixBuf: Pointer;
    39     procedure SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;
    40       ACanvas: TCanvas; ARect: TRect);
     39{    procedure SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;
     40      ACanvas: TCanvas; ARect: TRect);}
     41    procedure DrawTransparent(ACanvas: TCanvas; Rect: TRect);
     42    procedure DrawOpaque(ACanvas: TCanvas; Rect: TRect);
    4143  protected
    4244    procedure ReallocData; override;
    4345    procedure FreeData; override;
    44     procedure DrawOpaque(ACanvas: TCanvas; Rect: TRect);
    4546  public
    4647    procedure DataDrawTransparent(ACanvas: TCanvas; Rect: TRect;
     
    5051    procedure Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean = True); override;
    5152    procedure DataDrawOpaque(ACanvas: TCanvas; Rect: TRect; AData: Pointer;
    52       ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
    53       override;
     53      ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer); override;
    5454    procedure GetImageFromCanvas(CanvasSource: TCanvas; x, y: integer); override;
    5555  end;
     
    7171{$ENDIF}
    7272
    73 procedure TBGRAGtkBitmap.SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;
     73{procedure TBGRAGtkBitmap.SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;
    7474  ACanvas: TCanvas; ARect: TRect);
    7575var
    76   background, temp: TBGRADefaultBitmap;
     76  background, temp: TBGRACustomBitmap;
    7777  w, h: integer;
    7878
     
    9292  background.Draw(ACanvas, ARect.Left, ARect.Top, True);
    9393  background.Free;
    94 end;
     94end;}
    9595
    9696procedure TBGRAGtkBitmap.ReallocData;
    9797begin
     98  {$IFDEF LCLgtk2}
     99  If FPixBuf <> nil then g_object_unref(FPixBuf);
     100  {$ELSE}
     101  If FPixBuf <> nil then gdk_pixbuf_unref(FPixBuf);
     102  {$ENDIF}
     103  FPixBuf := nil; 
    98104  inherited ReallocData;
    99   FPixbuf := gdk_pixbuf_new_from_data(pguchar(FData),
    100     GDK_COLORSPACE_RGB, True, 8, Width, Height, Width*Sizeof(TBGRAPixel), nil, nil);
    101   if FPixbuf = nil then
    102     raise Exception.Create('Error initializing Pixbuf');
     105  if (FWidth <> 0) and (FHeight <> 0) then
     106  begin 
     107    FPixbuf := gdk_pixbuf_new_from_data(pguchar(FData),
     108      GDK_COLORSPACE_RGB, True, 8, Width, Height, Width*Sizeof(TBGRAPixel), nil, nil);
     109    if FPixbuf = nil then
     110      raise Exception.Create('Error initializing Pixbuf');
     111  end;
    103112end;
    104113
     
    114123end;
    115124
    116 procedure TBGRAGtkBitmap.DrawOpaque(ACanvas: TCanvas; Rect: TRect);
     125procedure TBGRAGtkBitmap.DrawTransparent(ACanvas: TCanvas; Rect: TRect);
    117126var DrawWidth,DrawHeight: integer;
    118127    stretched: TBGRAGtkBitmap;
     
    126135  begin
    127136    stretched := Resample(DrawWidth,DrawHeight,rmSimpleStretch) as TBGRAGtkBitmap;
    128     stretched.DrawOpaque(ACanvas,Rect);
     137    stretched.DrawTransparent(ACanvas,Rect);
    129138    stretched.Free;
    130139    exit;
    131140  end;
    132141
    133   //SwapRedBlue;
     142  SwapRedBlue;
    134143  gdk_pixbuf_render_to_drawable(FPixBuf,
    135144    TGtkDeviceContext(ACanvas.Handle).Drawable,
     
    140149    Width,Height,
    141150    GDK_RGB_DITHER_NORMAL,0,0);
    142   //SwapRedBlue;
     151  SwapRedBlue;
     152end;
     153
     154procedure TBGRAGtkBitmap.DrawOpaque(ACanvas: TCanvas; Rect: TRect);
     155begin
     156  DataDrawOpaque(ACanvas,Rect,Data,LineOrder,Width,Height);
    143157end;
    144158
     
    146160  AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
    147161var
    148   Temp: TBGRAPtrBitmap;
    149 begin
    150   Temp := TBGRAPtrBitmap.Create(AWidth, AHeight, AData);
    151   Temp.LineOrder := ALineOrder;
    152   SlowDrawTransparent(Temp, ACanvas, Rect);
    153   Temp.Free;
     162  TempGtk: TBGRAGtkBitmap;
     163  temp: integer;
     164begin
     165  if (AHeight = 0) or (AWidth = 0) or (Rect.Left = Rect.Right) or
     166    (Rect.Top = Rect.Bottom) then
     167    exit;
     168
     169  if Rect.Right < Rect.Left then
     170  begin
     171    temp := Rect.Left;
     172    Rect.Left := Rect.Right;
     173    Rect.Right := temp;
     174  end;
     175
     176  if Rect.Bottom < Rect.Top then
     177  begin
     178    temp := Rect.Top;
     179    Rect.Top := Rect.Bottom;
     180    Rect.Bottom := temp;
     181  end;
     182
     183  TempGtk := TBGRAGtkBitmap.Create(AWidth, AHeight);
     184  Move(AData^,TempGtk.Data^,TempGtk.NbPixels*sizeof(TBGRAPixel));
     185  if ALineOrder <> TempGtk.LineOrder then TempGtk.VerticalFlip;
     186  TempGtk.DrawTransparent(ACanvas,Rect);
     187  TempGtk.Free;
    154188end;
    155189
     
    161195    DrawOpaque(ACanvas, Rect(X, Y, X + Width, Y + Height))
    162196  else
    163     SlowDrawTransparent(Self, ACanvas, Rect(X, Y, X + Width, Y + Height));
     197    DrawTransparent(ACanvas, Rect(X, Y, X + Width, Y + Height));
    164198end;
    165199
     
    171205    DrawOpaque(ACanvas, Rect)
    172206  else
    173     SlowDrawTransparent(Self, ACanvas, Rect);
     207    DrawTransparent(ACanvas, Rect);
    174208end;
    175209
    176210procedure TBGRAGtkBitmap.DataDrawOpaque(ACanvas: TCanvas; Rect: TRect;
    177211  AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer);
    178 var stretched: TBGRADefaultBitmap;
    179 begin
    180   if (AHeight = 0) or (AWidth = 0) then
    181     exit;
    182 
    183   if (AWidth <> Width) or (AHeight <> Height) then
    184   begin
    185     stretched := Resample(AWidth,AHeight,rmSimpleStretch);
    186     stretched.DataDrawOpaque(ACanvas,Rect,AData,stretched.LineOrder,AWidth,AHeight)
    187   end;
    188 
     212var ptr: TBGRAPtrBitmap;
     213    stretched: TBGRACustomBitmap;
     214    temp: integer;
     215    pos: TPoint;
     216    dest: HDC;
     217begin
     218  if (AHeight = 0) or (AWidth = 0) or (Rect.Left = Rect.Right) or
     219    (Rect.Top = Rect.Bottom) then
     220    exit;
     221
     222  if Rect.Right < Rect.Left then
     223  begin
     224    temp := Rect.Left;
     225    Rect.Left := Rect.Right;
     226    Rect.Right := temp;
     227  end;
     228
     229  if Rect.Bottom < Rect.Top then
     230  begin
     231    temp := Rect.Top;
     232    Rect.Top := Rect.Bottom;
     233    Rect.Bottom := temp;
     234  end;
     235
     236  if (AWidth <> Rect.Right-Rect.Left) or (AHeight <> Rect.Bottom-Rect.Top) then
     237  begin
     238    ptr := TBGRAPtrBitmap.Create(AWidth,AHeight,AData);
     239    ptr.LineOrder := ALineOrder;
     240    stretched := ptr.Resample(Rect.Right-Rect.Left,Rect.Bottom-Rect.Top);
     241    ptr.free;
     242    DataDrawOpaque(ACanvas,Rect,AData,stretched.LineOrder,stretched.Width,stretched.Height);
     243    stretched.Free;
     244    exit;
     245  end;
     246
     247  dest := ACanvas.Handle;
     248  pos := TGtkDeviceContext(dest).Offset;
     249  pos.X += rect.Left;
     250  pos.Y += rect.Top;
    189251  If ALineOrder = riloBottomToTop then VerticalFlip;
    190252  SwapRedBlue;
    191   gdk_pixbuf_render_to_drawable(FPixBuf,
    192     TGtkDeviceContext(ACanvas.Handle).Drawable,
    193     TGtkDeviceContext(ACanvas.Handle).GC,
    194     0,0,Rect.Left,Rect.Top,AWidth,AHeight,
    195     GDK_RGB_DITHER_NORMAL,0,0);
     253  gdk_draw_rgb_32_image(TGtkDeviceContext(dest).Drawable,
     254    TGtkDeviceContext(Dest).GC, pos.X,pos.Y,
     255    AWidth,AHeight, GDK_RGB_DITHER_NORMAL,
     256    AData, AWidth*sizeof(TBGRAPixel));
    196257  SwapRedBlue;
    197258  If ALineOrder = riloBottomToTop then VerticalFlip;
     
    200261procedure TBGRAGtkBitmap.GetImageFromCanvas(CanvasSource: TCanvas; x, y: integer);
    201262var
    202   subBmp: TBGRADefaultBitmap;
     263  subBmp: TBGRACustomBitmap;
    203264  subRect: TRect;
    204265  cw,ch: integer;
     
    240301end.
    241302
     303
Note: See TracChangeset for help on using the changeset viewer.