CAIRO2PIXBUF
Dec 14, 2022 13:03:18 GMT 1
Post by alexfish on Dec 14, 2022 13:03:18 GMT 1
Hi All
Converting 'cairo surface data' to pixbuf
on the surface the write format for rgba are the same But the read is not, I think says he
culprit here been
Hence have this in the HugImager and may find these bits useful
BR
Alex
Converting 'cairo surface data' to pixbuf
on the surface the write format for rgba are the same But the read is not, I think says he
culprit here been
gdk_pixbuf_new_from_data
+ the ENDIANHence have this in the HugImager and may find these bits useful
LibCairo$ = "libcairo.so.2"
GDK$ = "libgdk_pixbuf-2.0.so.0"
IMPORT "gdk_pixbuf_new (int,int,int ,int ,int)" FROM GDK$ TYPE long
IMPORT "gdk_pixbuf_get_pixels ( const long ) unsigned gdk_pixbuf_get_pixels_with_length const long , unsigned int* ) " FROM GDK$ TYPE unsigned char*
IMPORT "cairo_surface_flush(long)" FROM LibCairo$ TYPE void
IMPORT "cairo_image_surface_get_width (long)" FROM LibCairo$ TYPE int
IMPORT "cairo_image_surface_get_height (long)" FROM LibCairo$ TYPE int
IMPORT "cairo_image_surface_get_stride ()" FROM LibCairo$ TYPE int
IMPORT "cairo_image_surface_get_data (long)" FROM LibCairo$ TYPE unsigned char *
'=======================================================================
FUNCTION endian()
LOCAL x = 1 TYPE unsigned int
char *c = (char*) &x
RETURN (int)*c
END FUNCTION
'=======================================================================
CONST ENDIAN = endian()
'=======================================================================
FUNCTION CAIRO2PIXBUF(long csr)
LOCAL data , pixels,p,p2 TYPE unsigned char *
LOCAL wt,ht,xtt,yt,strid,pixy
cairo_surface_flush (csr)
wt = cairo_image_surface_get_width(csr)
ht = cairo_image_surface_get_height(csr)
strid = cairo_image_surface_get_stride (csr)
pixy = gdk_pixbuf_new(0,TRUE,8,wt,ht)
data = cairo_image_surface_get_data (csr)
pixels = gdk_pixbuf_get_pixels (pixy)
FOR yt = 0 TO ht
FOR xtt = 0 TO wt
p2 = pixels + yt * strid + xtt * 4
p = data + yt * strid + xtt * 4
IF ENDIAN THEN
p2[0] = p[2]
p2[1] = p[1]
p2[2] = p[0]
p2[3] = p[3]
ELSE
p2[0]= p[0]
p2[1]= p[1]
p2[2] = p[2]
p2[3] = p[3]
END IF
NEXT
NEXT
RETURN pixy
END FUNCTION
'=======================================================================
BR
Alex