gtk3: use cairo_image_surface_create_for_data() when setting an image into tgtk3devicecontext. issue #27224

git-svn-id: trunk@47269 -
This commit is contained in:
zeljko 2014-12-30 20:30:34 +00:00
parent 342c235c66
commit 5b2895110f

View File

@ -1748,12 +1748,18 @@ end;
procedure TGtk3DeviceContext.SetImage(AImage: TGtk3Image); procedure TGtk3DeviceContext.SetImage(AImage: TGtk3Image);
var var
APixBuf: PGdkPixbuf; APixBuf: PGdkPixbuf;
// AFormat : cairo_format_t;
// Stride : integer;
w,h : integer;
begin begin
FCurrentImage := AImage; FCurrentImage := AImage;
cairo_destroy(Widget); cairo_destroy(Widget);
APixBuf := AImage.Handle; APixBuf := AImage.Handle;
if not Gtk3IsGdkPixbuf(APixBuf) then if not Gtk3IsGdkPixbuf(APixBuf) then
begin
DebugLn('ERROR: TGtk3DeviceContext.SetImage image handle isn''t PGdkPixbuf.'); DebugLn('ERROR: TGtk3DeviceContext.SetImage image handle isn''t PGdkPixbuf.');
exit;
end;
(* (*
DebugLn('TGtk3DeviceContext.SetImage w=',dbgs(APixBuf^.width),' h=',dbgs(APixBuf^.height), DebugLn('TGtk3DeviceContext.SetImage w=',dbgs(APixBuf^.width),' h=',dbgs(APixBuf^.height),
' RowStride ',dbgs(APixBuf^.rowstride),' BPS=',dbgs(APixBuf^.get_bits_per_sample), ' RowStride ',dbgs(APixBuf^.rowstride),' BPS=',dbgs(APixBuf^.get_bits_per_sample),
@ -1762,12 +1768,19 @@ begin
*) *)
if FOwnsSurface and (CairoSurface <> nil) then if FOwnsSurface and (CairoSurface <> nil) then
cairo_surface_destroy(CairoSurface); cairo_surface_destroy(CairoSurface);
if APixBuf^.get_has_alpha then w:=APixBuf^.get_width;
CairoSurface := cairo_image_surface_create(CAIRO_FORMAT_ARGB32, APixBuf^.get_width, APixBuf^.get_height) h:=APixBuf^.get_height;
else
CairoSurface := cairo_image_surface_create(CAIRO_FORMAT_RGB24, APixBuf^.get_width, APixBuf^.get_height); // AFormat := AImage.getFormat;
// Stride := cairo_format_stride_for_width(AFormat,w);
CairoSurface := cairo_image_surface_create_for_data(APixBuf^.pixels,
AImage.getFormat,
w,
h,
APixBuf^.rowstride);
Widget := cairo_create(CairoSurface); Widget := cairo_create(CairoSurface);
// gdk_cairo_set_source_pixbuf(Widget, APixBuf, 0, 0); FOwnsSurface := true;
end; end;
function TGtk3DeviceContext.ResetClip: Integer; function TGtk3DeviceContext.ResetClip: Integer;