diff options
| author | Jason Rumney | 2007-08-24 00:28:53 +0000 |
|---|---|---|
| committer | Jason Rumney | 2007-08-24 00:28:53 +0000 |
| commit | 5fc9fdeb310edda5cf48bb3d19c103cb7a5017eb (patch) | |
| tree | cb176dfea5ea69e4431b744871748752a3fd1e90 /src/image.c | |
| parent | 68a4a27a03da595dc3f2e88b319650267b0f9945 (diff) | |
| download | emacs-5fc9fdeb310edda5cf48bb3d19c103cb7a5017eb.tar.gz emacs-5fc9fdeb310edda5cf48bb3d19c103cb7a5017eb.zip | |
[HAVE_NTGUI]: Define dynamic loaded functions.
(Qgdk_pixbuf, Qglib) [HAVE_NTGUI]: New symbols.
(syms_of_image) [HAVE_NTGUI]: Intern and staticpro them.
(init_svg_functions) [HAVE_NTGUI]: New function.
(fn_g_type_init, fn_g_object_unref, fn_g_error_free): New #defines.
(svg_load_image): Use them.
(svg_load_image) [HAVE_NTGUI]: Implement background.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 139 |
1 files changed, 107 insertions, 32 deletions
diff --git a/src/image.c b/src/image.c index 9f6a3b02ce5..48c6cdcd4de 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -1318,8 +1318,8 @@ image_ascent (img, face, slice) | |||
| 1318 | { | 1318 | { |
| 1319 | #ifdef HAVE_NTGUI | 1319 | #ifdef HAVE_NTGUI |
| 1320 | /* W32 specific version. Why?. ++kfs */ | 1320 | /* W32 specific version. Why?. ++kfs */ |
| 1321 | ascent = height / 2 - (FONT_DESCENT(face->font) | 1321 | ascent = height / 2 - (FONT_DESCENT (face->font) |
| 1322 | - FONT_BASE(face->font)) / 2; | 1322 | - FONT_BASE (face->font)) / 2; |
| 1323 | #else | 1323 | #else |
| 1324 | /* This expression is arranged so that if the image can't be | 1324 | /* This expression is arranged so that if the image can't be |
| 1325 | exactly centered, it will be moved slightly up. This is | 1325 | exactly centered, it will be moved slightly up. This is |
| @@ -2252,7 +2252,7 @@ x_create_x_image_and_pixmap (f, width, height, depth, ximg, pixmap) | |||
| 2252 | 2252 | ||
| 2253 | if (*pixmap == NULL) | 2253 | if (*pixmap == NULL) |
| 2254 | { | 2254 | { |
| 2255 | DWORD err = GetLastError(); | 2255 | DWORD err = GetLastError (); |
| 2256 | Lisp_Object errcode; | 2256 | Lisp_Object errcode; |
| 2257 | /* All system errors are < 10000, so the following is safe. */ | 2257 | /* All system errors are < 10000, so the following is safe. */ |
| 2258 | XSETINT (errcode, (int) err); | 2258 | XSETINT (errcode, (int) err); |
| @@ -6711,7 +6711,7 @@ init_jpeg_functions (Lisp_Object libraries) | |||
| 6711 | /* Wrapper since we can't directly assign the function pointer | 6711 | /* Wrapper since we can't directly assign the function pointer |
| 6712 | to another function pointer that was declared more completely easily. */ | 6712 | to another function pointer that was declared more completely easily. */ |
| 6713 | static boolean | 6713 | static boolean |
| 6714 | jpeg_resync_to_restart_wrapper(cinfo, desired) | 6714 | jpeg_resync_to_restart_wrapper (cinfo, desired) |
| 6715 | j_decompress_ptr cinfo; | 6715 | j_decompress_ptr cinfo; |
| 6716 | int desired; | 6716 | int desired; |
| 6717 | { | 6717 | { |
| @@ -7805,7 +7805,7 @@ gif_load (f, img) | |||
| 7805 | memsrc.index = 0; | 7805 | memsrc.index = 0; |
| 7806 | 7806 | ||
| 7807 | /* Casting return value avoids a GCC warning on W32. */ | 7807 | /* Casting return value avoids a GCC warning on W32. */ |
| 7808 | gif = (GifFileType *)fn_DGifOpen(&memsrc, gif_read_from_memory); | 7808 | gif = (GifFileType *) fn_DGifOpen (&memsrc, gif_read_from_memory); |
| 7809 | if (!gif) | 7809 | if (!gif) |
| 7810 | { | 7810 | { |
| 7811 | image_error ("Cannot open memory source `%s'", img->spec, Qnil); | 7811 | image_error ("Cannot open memory source `%s'", img->spec, Qnil); |
| @@ -8297,13 +8297,66 @@ svg_image_p (object) | |||
| 8297 | 8297 | ||
| 8298 | #include <librsvg/rsvg.h> | 8298 | #include <librsvg/rsvg.h> |
| 8299 | 8299 | ||
| 8300 | /* TO DO: define DEF_IMGLIB_FN here. This macro is used to handle | 8300 | #ifdef HAVE_NTGUI |
| 8301 | loading of dynamic link library functions for various OS:es. | 8301 | |
| 8302 | Currently only librsvg2 is supported, which is only available for X, | 8302 | /* SVG library functions. */ |
| 8303 | so its not strictly necessary yet. The current code is thought to be | 8303 | DEF_IMGLIB_FN (rsvg_handle_new); |
| 8304 | compatible with this scheme because of the defines below, should | 8304 | DEF_IMGLIB_FN (rsvg_handle_set_size_callback); |
| 8305 | librsvg2 become available on more plattforms. */ | 8305 | DEF_IMGLIB_FN (rsvg_handle_write); |
| 8306 | DEF_IMGLIB_FN (rsvg_handle_close); | ||
| 8307 | DEF_IMGLIB_FN (rsvg_handle_get_pixbuf); | ||
| 8308 | DEF_IMGLIB_FN (rsvg_handle_free); | ||
| 8309 | |||
| 8310 | DEF_IMGLIB_FN (gdk_pixbuf_get_width); | ||
| 8311 | DEF_IMGLIB_FN (gdk_pixbuf_get_height); | ||
| 8312 | DEF_IMGLIB_FN (gdk_pixbuf_get_pixels); | ||
| 8313 | DEF_IMGLIB_FN (gdk_pixbuf_get_rowstride); | ||
| 8314 | DEF_IMGLIB_FN (gdk_pixbuf_get_colorspace); | ||
| 8315 | DEF_IMGLIB_FN (gdk_pixbuf_get_n_channels); | ||
| 8316 | DEF_IMGLIB_FN (gdk_pixbuf_get_has_alpha); | ||
| 8317 | DEF_IMGLIB_FN (gdk_pixbuf_get_bits_per_sample); | ||
| 8318 | |||
| 8319 | DEF_IMGLIB_FN (g_type_init); | ||
| 8320 | DEF_IMGLIB_FN (g_object_unref); | ||
| 8321 | DEF_IMGLIB_FN (g_error_free); | ||
| 8322 | |||
| 8323 | Lisp_Object Qgdk_pixbuf, Qglib; | ||
| 8324 | |||
| 8325 | static int | ||
| 8326 | init_svg_functions (Lisp_Object libraries) | ||
| 8327 | { | ||
| 8328 | HMODULE library, gdklib, glib; | ||
| 8329 | |||
| 8330 | if (!(glib = w32_delayed_load (libraries, Qglib)) | ||
| 8331 | || !(gdklib = w32_delayed_load (libraries, Qgdk_pixbuf)) | ||
| 8332 | || !(library = w32_delayed_load (libraries, Qsvg))) | ||
| 8333 | return 0; | ||
| 8334 | |||
| 8335 | LOAD_IMGLIB_FN (library, rsvg_handle_new); | ||
| 8336 | LOAD_IMGLIB_FN (library, rsvg_handle_set_size_callback); | ||
| 8337 | LOAD_IMGLIB_FN (library, rsvg_handle_write); | ||
| 8338 | LOAD_IMGLIB_FN (library, rsvg_handle_close); | ||
| 8339 | LOAD_IMGLIB_FN (library, rsvg_handle_get_pixbuf); | ||
| 8340 | LOAD_IMGLIB_FN (library, rsvg_handle_free); | ||
| 8341 | |||
| 8342 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_width); | ||
| 8343 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_height); | ||
| 8344 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_pixels); | ||
| 8345 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_rowstride); | ||
| 8346 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_colorspace); | ||
| 8347 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_n_channels); | ||
| 8348 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_has_alpha); | ||
| 8349 | LOAD_IMGLIB_FN (gdklib, gdk_pixbuf_get_bits_per_sample); | ||
| 8350 | |||
| 8351 | LOAD_IMGLIB_FN (glib, g_type_init); | ||
| 8352 | LOAD_IMGLIB_FN (glib, g_object_unref); | ||
| 8353 | LOAD_IMGLIB_FN (glib, g_error_free); | ||
| 8354 | return 1; | ||
| 8355 | } | ||
| 8306 | 8356 | ||
| 8357 | #else | ||
| 8358 | /* The following aliases for library functions allow dynamic loading | ||
| 8359 | to be used on some platforms. */ | ||
| 8307 | #define fn_rsvg_handle_new rsvg_handle_new | 8360 | #define fn_rsvg_handle_new rsvg_handle_new |
| 8308 | #define fn_rsvg_handle_set_size_callback rsvg_handle_set_size_callback | 8361 | #define fn_rsvg_handle_set_size_callback rsvg_handle_set_size_callback |
| 8309 | #define fn_rsvg_handle_write rsvg_handle_write | 8362 | #define fn_rsvg_handle_write rsvg_handle_write |
| @@ -8311,15 +8364,19 @@ librsvg2 become available on more plattforms. */ | |||
| 8311 | #define fn_rsvg_handle_get_pixbuf rsvg_handle_get_pixbuf | 8364 | #define fn_rsvg_handle_get_pixbuf rsvg_handle_get_pixbuf |
| 8312 | #define fn_rsvg_handle_free rsvg_handle_free | 8365 | #define fn_rsvg_handle_free rsvg_handle_free |
| 8313 | 8366 | ||
| 8314 | #define fn_gdk_pixbuf_get_width gdk_pixbuf_get_width | 8367 | #define fn_gdk_pixbuf_get_width gdk_pixbuf_get_width |
| 8315 | #define fn_gdk_pixbuf_get_height gdk_pixbuf_get_height | 8368 | #define fn_gdk_pixbuf_get_height gdk_pixbuf_get_height |
| 8316 | #define fn_gdk_pixbuf_get_pixels gdk_pixbuf_get_pixels | 8369 | #define fn_gdk_pixbuf_get_pixels gdk_pixbuf_get_pixels |
| 8317 | #define fn_gdk_pixbuf_get_rowstride gdk_pixbuf_get_rowstride | 8370 | #define fn_gdk_pixbuf_get_rowstride gdk_pixbuf_get_rowstride |
| 8318 | #define fn_gdk_pixbuf_get_colorspace gdk_pixbuf_get_colorspace | 8371 | #define fn_gdk_pixbuf_get_colorspace gdk_pixbuf_get_colorspace |
| 8319 | #define fn_gdk_pixbuf_get_n_channels gdk_pixbuf_get_n_channels | 8372 | #define fn_gdk_pixbuf_get_n_channels gdk_pixbuf_get_n_channels |
| 8320 | #define fn_gdk_pixbuf_get_has_alpha gdk_pixbuf_get_has_alpha | 8373 | #define fn_gdk_pixbuf_get_has_alpha gdk_pixbuf_get_has_alpha |
| 8321 | #define fn_gdk_pixbuf_get_bits_per_sample gdk_pixbuf_get_bits_per_sample | 8374 | #define fn_gdk_pixbuf_get_bits_per_sample gdk_pixbuf_get_bits_per_sample |
| 8322 | 8375 | ||
| 8376 | #define fn_g_type_init g_type_init | ||
| 8377 | #define fn_g_object_unref g_object_unref | ||
| 8378 | #define fn_g_error_free g_error_free | ||
| 8379 | #endif /* !HAVE_NTGUI */ | ||
| 8323 | 8380 | ||
| 8324 | /* Load SVG image IMG for use on frame F. Value is non-zero if | 8381 | /* Load SVG image IMG for use on frame F. Value is non-zero if |
| 8325 | successful. this function will go into the svg_type structure, and | 8382 | successful. this function will go into the svg_type structure, and |
| @@ -8410,7 +8467,7 @@ svg_load_image (f, img, contents, size) | |||
| 8410 | 8467 | ||
| 8411 | /* g_type_init is a glib function that must be called prior to using | 8468 | /* g_type_init is a glib function that must be called prior to using |
| 8412 | gnome type library functions. */ | 8469 | gnome type library functions. */ |
| 8413 | g_type_init (); | 8470 | fn_g_type_init (); |
| 8414 | /* Make a handle to a new rsvg object. */ | 8471 | /* Make a handle to a new rsvg object. */ |
| 8415 | rsvg_handle = fn_rsvg_handle_new (); | 8472 | rsvg_handle = fn_rsvg_handle_new (); |
| 8416 | 8473 | ||
| @@ -8444,7 +8501,7 @@ svg_load_image (f, img, contents, size) | |||
| 8444 | /* Try to create a x pixmap to hold the svg pixmap. */ | 8501 | /* Try to create a x pixmap to hold the svg pixmap. */ |
| 8445 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) | 8502 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) |
| 8446 | { | 8503 | { |
| 8447 | g_object_unref (pixbuf); | 8504 | fn_g_object_unref (pixbuf); |
| 8448 | return 0; | 8505 | return 0; |
| 8449 | } | 8506 | } |
| 8450 | 8507 | ||
| @@ -8477,6 +8534,18 @@ svg_load_image (f, img, contents, size) | |||
| 8477 | background.red = RED_FROM_ULONG (background.pixel); | 8534 | background.red = RED_FROM_ULONG (background.pixel); |
| 8478 | background.green = GREEN_FROM_ULONG (background.pixel); | 8535 | background.green = GREEN_FROM_ULONG (background.pixel); |
| 8479 | background.blue = BLUE_FROM_ULONG (background.pixel); | 8536 | background.blue = BLUE_FROM_ULONG (background.pixel); |
| 8537 | #elif defined (HAVE_NTGUI) | ||
| 8538 | background.pixel = FRAME_BACKGROUND_PIXEL (f); | ||
| 8539 | #if 0 /* W32 TODO : Colormap support. */ | ||
| 8540 | x_query_color (f, &background); | ||
| 8541 | #endif | ||
| 8542 | |||
| 8543 | /* SVG pixmaps specify transparency in the last byte, so right | ||
| 8544 | shift 8 bits to get rid of it, since emacs doesnt support | ||
| 8545 | transparency. */ | ||
| 8546 | background.red >>= 8; | ||
| 8547 | background.green >>= 8; | ||
| 8548 | background.blue >>= 8; | ||
| 8480 | #else /* not HAVE_X_WINDOWS && not MAC_OS*/ | 8549 | #else /* not HAVE_X_WINDOWS && not MAC_OS*/ |
| 8481 | #error FIXME | 8550 | #error FIXME |
| 8482 | #endif | 8551 | #endif |
| @@ -8519,7 +8588,7 @@ svg_load_image (f, img, contents, size) | |||
| 8519 | free_color_table (); | 8588 | free_color_table (); |
| 8520 | #endif /* COLOR_TABLE_SUPPORT */ | 8589 | #endif /* COLOR_TABLE_SUPPORT */ |
| 8521 | 8590 | ||
| 8522 | g_object_unref (pixbuf); | 8591 | fn_g_object_unref (pixbuf); |
| 8523 | 8592 | ||
| 8524 | img->width = width; | 8593 | img->width = width; |
| 8525 | img->height = height; | 8594 | img->height = height; |
| @@ -8539,7 +8608,7 @@ svg_load_image (f, img, contents, size) | |||
| 8539 | /* FIXME: Use error->message so the user knows what is the actual | 8608 | /* FIXME: Use error->message so the user knows what is the actual |
| 8540 | problem with the image. */ | 8609 | problem with the image. */ |
| 8541 | image_error ("Error parsing SVG image `%s'", img->spec, Qnil); | 8610 | image_error ("Error parsing SVG image `%s'", img->spec, Qnil); |
| 8542 | g_error_free (error); | 8611 | fn_g_error_free (error); |
| 8543 | return 0; | 8612 | return 0; |
| 8544 | } | 8613 | } |
| 8545 | 8614 | ||
| @@ -9003,11 +9072,11 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 9003 | 9072 | ||
| 9004 | Qpbm = intern ("pbm"); | 9073 | Qpbm = intern ("pbm"); |
| 9005 | staticpro (&Qpbm); | 9074 | staticpro (&Qpbm); |
| 9006 | ADD_IMAGE_TYPE(Qpbm); | 9075 | ADD_IMAGE_TYPE (Qpbm); |
| 9007 | 9076 | ||
| 9008 | Qxbm = intern ("xbm"); | 9077 | Qxbm = intern ("xbm"); |
| 9009 | staticpro (&Qxbm); | 9078 | staticpro (&Qxbm); |
| 9010 | ADD_IMAGE_TYPE(Qxbm); | 9079 | ADD_IMAGE_TYPE (Qxbm); |
| 9011 | 9080 | ||
| 9012 | define_image_type (&xbm_type, 1); | 9081 | define_image_type (&xbm_type, 1); |
| 9013 | define_image_type (&pbm_type, 1); | 9082 | define_image_type (&pbm_type, 1); |
| @@ -9045,7 +9114,7 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 9045 | Qpostscript = intern ("postscript"); | 9114 | Qpostscript = intern ("postscript"); |
| 9046 | staticpro (&Qpostscript); | 9115 | staticpro (&Qpostscript); |
| 9047 | #ifdef HAVE_GHOSTSCRIPT | 9116 | #ifdef HAVE_GHOSTSCRIPT |
| 9048 | ADD_IMAGE_TYPE(Qpostscript); | 9117 | ADD_IMAGE_TYPE (Qpostscript); |
| 9049 | QCloader = intern (":loader"); | 9118 | QCloader = intern (":loader"); |
| 9050 | staticpro (&QCloader); | 9119 | staticpro (&QCloader); |
| 9051 | QCbounding_box = intern (":bounding-box"); | 9120 | QCbounding_box = intern (":bounding-box"); |
| @@ -9059,38 +9128,44 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 9059 | #if defined (HAVE_XPM) || defined (MAC_OS) | 9128 | #if defined (HAVE_XPM) || defined (MAC_OS) |
| 9060 | Qxpm = intern ("xpm"); | 9129 | Qxpm = intern ("xpm"); |
| 9061 | staticpro (&Qxpm); | 9130 | staticpro (&Qxpm); |
| 9062 | ADD_IMAGE_TYPE(Qxpm); | 9131 | ADD_IMAGE_TYPE (Qxpm); |
| 9063 | #endif | 9132 | #endif |
| 9064 | 9133 | ||
| 9065 | #if defined (HAVE_JPEG) || defined (MAC_OS) | 9134 | #if defined (HAVE_JPEG) || defined (MAC_OS) |
| 9066 | Qjpeg = intern ("jpeg"); | 9135 | Qjpeg = intern ("jpeg"); |
| 9067 | staticpro (&Qjpeg); | 9136 | staticpro (&Qjpeg); |
| 9068 | ADD_IMAGE_TYPE(Qjpeg); | 9137 | ADD_IMAGE_TYPE (Qjpeg); |
| 9069 | #endif | 9138 | #endif |
| 9070 | 9139 | ||
| 9071 | #if defined (HAVE_TIFF) || defined (MAC_OS) | 9140 | #if defined (HAVE_TIFF) || defined (MAC_OS) |
| 9072 | Qtiff = intern ("tiff"); | 9141 | Qtiff = intern ("tiff"); |
| 9073 | staticpro (&Qtiff); | 9142 | staticpro (&Qtiff); |
| 9074 | ADD_IMAGE_TYPE(Qtiff); | 9143 | ADD_IMAGE_TYPE (Qtiff); |
| 9075 | #endif | 9144 | #endif |
| 9076 | 9145 | ||
| 9077 | #if defined (HAVE_GIF) || defined (MAC_OS) | 9146 | #if defined (HAVE_GIF) || defined (MAC_OS) |
| 9078 | Qgif = intern ("gif"); | 9147 | Qgif = intern ("gif"); |
| 9079 | staticpro (&Qgif); | 9148 | staticpro (&Qgif); |
| 9080 | ADD_IMAGE_TYPE(Qgif); | 9149 | ADD_IMAGE_TYPE (Qgif); |
| 9081 | #endif | 9150 | #endif |
| 9082 | 9151 | ||
| 9083 | #if defined (HAVE_PNG) || defined (MAC_OS) | 9152 | #if defined (HAVE_PNG) || defined (MAC_OS) |
| 9084 | Qpng = intern ("png"); | 9153 | Qpng = intern ("png"); |
| 9085 | staticpro (&Qpng); | 9154 | staticpro (&Qpng); |
| 9086 | ADD_IMAGE_TYPE(Qpng); | 9155 | ADD_IMAGE_TYPE (Qpng); |
| 9087 | #endif | 9156 | #endif |
| 9088 | 9157 | ||
| 9089 | #if defined (HAVE_RSVG) | 9158 | #if defined (HAVE_RSVG) |
| 9090 | Qsvg = intern ("svg"); | 9159 | Qsvg = intern ("svg"); |
| 9091 | staticpro (&Qsvg); | 9160 | staticpro (&Qsvg); |
| 9092 | ADD_IMAGE_TYPE(Qsvg); | 9161 | ADD_IMAGE_TYPE (Qsvg); |
| 9093 | #endif | 9162 | #ifdef HAVE_NTGUI |
| 9163 | Qgdk_pixbuf = intern ("gdk-pixbuf"); | ||
| 9164 | staticpro (&Qgdk_pixbuf); | ||
| 9165 | Qglib = intern ("glib"); | ||
| 9166 | staticpro (&Qglib); | ||
| 9167 | #endif /* HAVE_NTGUI */ | ||
| 9168 | #endif /* HAVE_RSVG */ | ||
| 9094 | 9169 | ||
| 9095 | defsubr (&Sinit_image_library); | 9170 | defsubr (&Sinit_image_library); |
| 9096 | defsubr (&Sclear_image_cache); | 9171 | defsubr (&Sclear_image_cache); |