return PALETTERGB (r >> 8, g >> 8, b >> 8);
#elif defined HAVE_NS
return RGB_TO_ULONG (r >> 8, g >> 8, b >> 8);
+#elif defined USE_CAIRO
+ return (0xffu << 24) | (r << 16) | (g << 8) | b;
#else
xsignal1 (Qfile_error,
build_string ("This Emacs mishandles this image file type"));
FILE *volatile fp = NULL;
JSAMPARRAY buffer;
int row_stride, x, y;
- unsigned long *colors;
int width, height;
int i, ir, ig, ib;
#ifndef USE_CAIRO
+ unsigned long *colors;
XImagePtr ximg = NULL;
#endif
else
ir = 0, ig = 0, ib = 0;
-#ifndef CAIRO
+#ifndef USE_CAIRO
/* Use the color table mechanism because it handles colors that
cannot be allocated nicely. Such colors will be replaced with
a default color, and we don't have to care about which colors
int width, height;
size_t image_width, image_height;
MagickBooleanType status;
+#ifndef USE_CAIRO
XImagePtr ximg;
+#endif
int x, y;
MagickWand *image_wand;
PixelIterator *iterator;
double rotation;
char hint_buffer[MaxTextExtent];
char *filename_hint = NULL;
+#ifdef USE_CAIRO
+ void *data = NULL;
+#endif
/* Initialize the ImageMagick environment. */
static bool imagemagick_initialized;
/* Magicexportimage is normally faster than pixelpushing. This
method is also well tested. Some aspects of this method are
ad-hoc and needs to be more researched. */
+ void *dataptr;
+#ifdef USE_CAIRO
+ data = xmalloc (width * height * 4);
+ const char *exportdepth = "BGRA";
+ dataptr = data;
+#else
int imagedepth = 24; /*MagickGetImageDepth(image_wand);*/
const char *exportdepth = imagedepth <= 8 ? "I" : "BGRP"; /*"RGBP";*/
/* Try to create a x pixmap to hold the imagemagick pixmap. */
image_error ("Imagemagick X bitmap allocation failure");
goto imagemagick_error;
}
+ dataptr = ximg->data;
+#endif /* not USE_CAIRO */
/* Oddly, the below code doesn't seem to work:*/
/* switch(ximg->bitmap_unit){ */
*/
int pixelwidth = CharPixel; /*??? TODO figure out*/
MagickExportImagePixels (image_wand, 0, 0, width, height,
- exportdepth, pixelwidth, ximg->data);
+ exportdepth, pixelwidth, dataptr);
}
else
#endif /* HAVE_MAGICKEXPORTIMAGEPIXELS */
{
size_t image_height;
MagickRealType color_scale = 65535.0 / QuantumRange;
-
+#ifdef USE_CAIRO
+ data = xmalloc (width * height * 4);
+ color_scale /= 256;
+#else
/* Try to create a x pixmap to hold the imagemagick pixmap. */
if (!image_create_x_image_and_pixmap (f, img, width, height, 0,
&ximg, 0))
image_error ("Imagemagick X bitmap allocation failure");
goto imagemagick_error;
}
+#endif
/* Copy imagemagick image to x with primitive yet robust pixel
pusher loop. This has been tested a lot with many different
#ifdef COLOR_TABLE_SUPPORT
free_color_table ();
#endif
+#ifndef USE_CAIRO
x_destroy_x_image (ximg);
+#endif
image_error ("Imagemagick pixel iterator creation failed");
goto imagemagick_error;
}
for (x = 0; x < xlim; x++)
{
PixelGetMagickColor (pixels[x], &pixel);
+#ifdef USE_CAIRO
+ ((uint32_t *)data)[width * y + x] =
+ lookup_rgb_color (f,
+ color_scale * pixel.red,
+ color_scale * pixel.green,
+ color_scale * pixel.blue);
+#else
XPutPixel (ximg, x, y,
lookup_rgb_color (f,
color_scale * pixel.red,
color_scale * pixel.green,
color_scale * pixel.blue));
+#endif
}
}
DestroyPixelIterator (iterator);
}
+#ifdef USE_CAIRO
+ create_cairo_image_surface (img, data, width, height);
+#else
#ifdef COLOR_TABLE_SUPPORT
/* Remember colors allocated for this image. */
img->colors = colors_in_color_table (&img->ncolors);
/* Put ximg into the image. */
image_put_x_image (f, img, ximg, 0);
+#endif
/* Final cleanup. image_wand should be the only resource left. */
DestroyMagickWand (image_wand);
if (! FRAME_CR_SURFACE (f))
{
- cairo_surface_t *surface;
- surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
- FRAME_X_DRAWABLE (f),
- FRAME_DISPLAY_INFO (f)->visual,
- FRAME_PIXEL_WIDTH (f),
- FRAME_PIXEL_HEIGHT (f));
- cr = cairo_create (surface);
- cairo_surface_destroy (surface);
- }
- else
- cr = cairo_create (FRAME_CR_SURFACE (f));
+ FRAME_CR_SURFACE (f) =
+ cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ FRAME_PIXEL_WIDTH (f),
+ FRAME_PIXEL_HEIGHT (f));
+ }
+ cr = cairo_create (FRAME_CR_SURFACE (f));
FRAME_CR_CONTEXT (f) = cr;
}
cairo_save (cr);
#ifdef USE_CAIRO
if (FRAME_CR_SURFACE (f))
{
- cairo_t *cr = 0;
- block_input();
-#if defined (USE_GTK) && defined (HAVE_GTK3)
- if (FRAME_GTK_WIDGET (f))
- {
- GdkWindow *w = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
- cr = gdk_cairo_create (w);
- }
- else
-#endif
- {
- cairo_surface_t *surface;
- int width = FRAME_PIXEL_WIDTH (f);
- int height = FRAME_PIXEL_HEIGHT (f);
- if (! FRAME_EXTERNAL_TOOL_BAR (f))
- height += FRAME_TOOL_BAR_HEIGHT (f);
- if (! FRAME_EXTERNAL_MENU_BAR (f))
- height += FRAME_MENU_BAR_HEIGHT (f);
- surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
- FRAME_X_DRAWABLE (f),
- FRAME_DISPLAY_INFO (f)->visual,
- width,
- height);
- cr = cairo_create (surface);
- cairo_surface_destroy (surface);
- }
+ cairo_t *cr;
+ cairo_surface_t *surface;
+ int width, height;
+
+ block_input ();
+ width = FRAME_PIXEL_WIDTH (f);
+ height = FRAME_PIXEL_HEIGHT (f);
+ if (! FRAME_EXTERNAL_TOOL_BAR (f))
+ height += FRAME_TOOL_BAR_HEIGHT (f);
+ if (! FRAME_EXTERNAL_MENU_BAR (f))
+ height += FRAME_MENU_BAR_HEIGHT (f);
+ surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
+ FRAME_X_DRAWABLE (f),
+ FRAME_DISPLAY_INFO (f)->visual,
+ width,
+ height);
+ cr = cairo_create (surface);
+ cairo_surface_destroy (surface);
cairo_set_source_surface (cr, FRAME_CR_SURFACE (f), 0, 0);
cairo_paint (cr);
x_clear_cursor (w);
#ifdef USE_CAIRO
- SET_FRAME_GARBAGED (f);
+ if (FRAME_CR_CONTEXT (f))
+ {
+ cairo_surface_t *s = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ width, height);
+ cairo_t *cr = cairo_create (s);
+ cairo_set_source_surface (cr, cairo_get_target (FRAME_CR_CONTEXT (f)),
+ -x, -from_y);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+
+ cr = FRAME_CR_CONTEXT (f);
+ cairo_save (cr);
+ cairo_set_source_surface (cr, s, 0, to_y);
+ cairo_rectangle (cr, x, to_y, width, height);
+ cairo_fill (cr);
+ cairo_restore (cr);
+ cairo_surface_destroy (s);
+ }
+ else
+ {
+ SET_FRAME_GARBAGED (f);
+ }
#else
XCopyArea (FRAME_X_DISPLAY (f),
FRAME_X_DRAWABLE (f), FRAME_X_DRAWABLE (f),