Changeset 317 for GraphicTest/BGRABitmap/bgragtkbitmap.pas
- Timestamp:
- Feb 1, 2012, 3:02:33 PM (13 years ago)
- Location:
- GraphicTest/BGRABitmap
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/BGRABitmap
-
Property svn:ignore
set to
lib
-
Property svn:ignore
set to
-
GraphicTest/BGRABitmap/bgragtkbitmap.pas
r210 r317 37 37 private 38 38 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); 41 43 protected 42 44 procedure ReallocData; override; 43 45 procedure FreeData; override; 44 procedure DrawOpaque(ACanvas: TCanvas; Rect: TRect);45 46 public 46 47 procedure DataDrawTransparent(ACanvas: TCanvas; Rect: TRect; … … 50 51 procedure Draw(ACanvas: TCanvas; Rect: TRect; Opaque: boolean = True); override; 51 52 procedure DataDrawOpaque(ACanvas: TCanvas; Rect: TRect; AData: Pointer; 52 ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer); 53 override; 53 ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer); override; 54 54 procedure GetImageFromCanvas(CanvasSource: TCanvas; x, y: integer); override; 55 55 end; … … 71 71 {$ENDIF} 72 72 73 procedure TBGRAGtkBitmap.SlowDrawTransparent(ABitmap: TBGRADefaultBitmap;73 {procedure TBGRAGtkBitmap.SlowDrawTransparent(ABitmap: TBGRADefaultBitmap; 74 74 ACanvas: TCanvas; ARect: TRect); 75 75 var 76 background, temp: TBGRA DefaultBitmap;76 background, temp: TBGRACustomBitmap; 77 77 w, h: integer; 78 78 … … 92 92 background.Draw(ACanvas, ARect.Left, ARect.Top, True); 93 93 background.Free; 94 end; 94 end;} 95 95 96 96 procedure TBGRAGtkBitmap.ReallocData; 97 97 begin 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; 98 104 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; 103 112 end; 104 113 … … 114 123 end; 115 124 116 procedure TBGRAGtkBitmap.Draw Opaque(ACanvas: TCanvas; Rect: TRect);125 procedure TBGRAGtkBitmap.DrawTransparent(ACanvas: TCanvas; Rect: TRect); 117 126 var DrawWidth,DrawHeight: integer; 118 127 stretched: TBGRAGtkBitmap; … … 126 135 begin 127 136 stretched := Resample(DrawWidth,DrawHeight,rmSimpleStretch) as TBGRAGtkBitmap; 128 stretched.Draw Opaque(ACanvas,Rect);137 stretched.DrawTransparent(ACanvas,Rect); 129 138 stretched.Free; 130 139 exit; 131 140 end; 132 141 133 //SwapRedBlue;142 SwapRedBlue; 134 143 gdk_pixbuf_render_to_drawable(FPixBuf, 135 144 TGtkDeviceContext(ACanvas.Handle).Drawable, … … 140 149 Width,Height, 141 150 GDK_RGB_DITHER_NORMAL,0,0); 142 //SwapRedBlue; 151 SwapRedBlue; 152 end; 153 154 procedure TBGRAGtkBitmap.DrawOpaque(ACanvas: TCanvas; Rect: TRect); 155 begin 156 DataDrawOpaque(ACanvas,Rect,Data,LineOrder,Width,Height); 143 157 end; 144 158 … … 146 160 AData: Pointer; ALineOrder: TRawImageLineOrder; AWidth, AHeight: integer); 147 161 var 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; 164 begin 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; 154 188 end; 155 189 … … 161 195 DrawOpaque(ACanvas, Rect(X, Y, X + Width, Y + Height)) 162 196 else 163 SlowDrawTransparent(Self,ACanvas, Rect(X, Y, X + Width, Y + Height));197 DrawTransparent(ACanvas, Rect(X, Y, X + Width, Y + Height)); 164 198 end; 165 199 … … 171 205 DrawOpaque(ACanvas, Rect) 172 206 else 173 SlowDrawTransparent(Self,ACanvas, Rect);207 DrawTransparent(ACanvas, Rect); 174 208 end; 175 209 176 210 procedure TBGRAGtkBitmap.DataDrawOpaque(ACanvas: TCanvas; Rect: TRect; 177 211 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 212 var ptr: TBGRAPtrBitmap; 213 stretched: TBGRACustomBitmap; 214 temp: integer; 215 pos: TPoint; 216 dest: HDC; 217 begin 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; 189 251 If ALineOrder = riloBottomToTop then VerticalFlip; 190 252 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)); 196 257 SwapRedBlue; 197 258 If ALineOrder = riloBottomToTop then VerticalFlip; … … 200 261 procedure TBGRAGtkBitmap.GetImageFromCanvas(CanvasSource: TCanvas; x, y: integer); 201 262 var 202 subBmp: TBGRA DefaultBitmap;263 subBmp: TBGRACustomBitmap; 203 264 subRect: TRect; 204 265 cw,ch: integer; … … 240 301 end. 241 302 303
Note:
See TracChangeset
for help on using the changeset viewer.