diff options
| author | YAMAMOTO Mitsuharu | 2007-08-23 08:44:57 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2007-08-23 08:44:57 +0000 |
| commit | c21e6151312b5d0016599f319d3bf5a6b320ea3a (patch) | |
| tree | 94ab9e091598b34153260cda629971c7887e9c01 /src | |
| parent | a1b7773a927a4cff2c15e637e94519c89d75bc1f (diff) | |
| download | emacs-c21e6151312b5d0016599f319d3bf5a6b320ea3a.tar.gz emacs-c21e6151312b5d0016599f319d3bf5a6b320ea3a.zip | |
(svg_load_image): Blend with specified background if exists.
Use IMAGE_BACKGROUND. Add Mac OS Support.
Diffstat (limited to 'src')
| -rw-r--r-- | src/image.c | 95 |
1 files changed, 57 insertions, 38 deletions
diff --git a/src/image.c b/src/image.c index 72f8a7ba47b..9f6a3b02ce5 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -8204,7 +8204,7 @@ gif_load (f, img) | |||
| 8204 | #endif /* HAVE_GIF */ | 8204 | #endif /* HAVE_GIF */ |
| 8205 | 8205 | ||
| 8206 | 8206 | ||
| 8207 | 8207 | ||
| 8208 | /*********************************************************************** | 8208 | /*********************************************************************** |
| 8209 | SVG | 8209 | SVG |
| 8210 | ***********************************************************************/ | 8210 | ***********************************************************************/ |
| @@ -8273,7 +8273,7 @@ static struct image_type svg_type = | |||
| 8273 | x_clear_image, | 8273 | x_clear_image, |
| 8274 | /* An internal field to link to the next image type in a list of | 8274 | /* An internal field to link to the next image type in a list of |
| 8275 | image types, will be filled in when registering the format. */ | 8275 | image types, will be filled in when registering the format. */ |
| 8276 | NULL | 8276 | NULL |
| 8277 | }; | 8277 | }; |
| 8278 | 8278 | ||
| 8279 | 8279 | ||
| @@ -8345,22 +8345,22 @@ svg_load (f, img) | |||
| 8345 | file = x_find_image_file (file_name); | 8345 | file = x_find_image_file (file_name); |
| 8346 | GCPRO1 (file); | 8346 | GCPRO1 (file); |
| 8347 | if (!STRINGP (file)) | 8347 | if (!STRINGP (file)) |
| 8348 | { | 8348 | { |
| 8349 | image_error ("Cannot find image file `%s'", file_name, Qnil); | 8349 | image_error ("Cannot find image file `%s'", file_name, Qnil); |
| 8350 | UNGCPRO; | 8350 | UNGCPRO; |
| 8351 | return 0; | 8351 | return 0; |
| 8352 | } | 8352 | } |
| 8353 | 8353 | ||
| 8354 | /* Read the entire file into memory. */ | 8354 | /* Read the entire file into memory. */ |
| 8355 | contents = slurp_file (SDATA (file), &size); | 8355 | contents = slurp_file (SDATA (file), &size); |
| 8356 | if (contents == NULL) | 8356 | if (contents == NULL) |
| 8357 | { | 8357 | { |
| 8358 | image_error ("Error loading SVG image `%s'", img->spec, Qnil); | 8358 | image_error ("Error loading SVG image `%s'", img->spec, Qnil); |
| 8359 | UNGCPRO; | 8359 | UNGCPRO; |
| 8360 | return 0; | 8360 | return 0; |
| 8361 | } | 8361 | } |
| 8362 | /* If the file was slurped into memory properly, parse it. */ | 8362 | /* If the file was slurped into memory properly, parse it. */ |
| 8363 | success_p = svg_load_image (f, img, contents, size); | 8363 | success_p = svg_load_image (f, img, contents, size); |
| 8364 | xfree (contents); | 8364 | xfree (contents); |
| 8365 | UNGCPRO; | 8365 | UNGCPRO; |
| 8366 | } | 8366 | } |
| @@ -8382,7 +8382,7 @@ svg_load (f, img) | |||
| 8382 | structures, passed from svg_load. | 8382 | structures, passed from svg_load. |
| 8383 | 8383 | ||
| 8384 | Uses librsvg to do most of the image processing. | 8384 | Uses librsvg to do most of the image processing. |
| 8385 | 8385 | ||
| 8386 | Returns non-zero when sucessful. */ | 8386 | Returns non-zero when sucessful. */ |
| 8387 | static int | 8387 | static int |
| 8388 | svg_load_image (f, img, contents, size) | 8388 | svg_load_image (f, img, contents, size) |
| @@ -8403,6 +8403,7 @@ svg_load_image (f, img, contents, size) | |||
| 8403 | const guint8 *pixels; | 8403 | const guint8 *pixels; |
| 8404 | int rowstride; | 8404 | int rowstride; |
| 8405 | XImagePtr ximg; | 8405 | XImagePtr ximg; |
| 8406 | Lisp_Object specified_bg; | ||
| 8406 | XColor background; | 8407 | XColor background; |
| 8407 | int x; | 8408 | int x; |
| 8408 | int y; | 8409 | int y; |
| @@ -8441,30 +8442,45 @@ svg_load_image (f, img, contents, size) | |||
| 8441 | eassert (fn_gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); | 8442 | eassert (fn_gdk_pixbuf_get_bits_per_sample (pixbuf) == 8); |
| 8442 | 8443 | ||
| 8443 | /* Try to create a x pixmap to hold the svg pixmap. */ | 8444 | /* Try to create a x pixmap to hold the svg pixmap. */ |
| 8444 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) { | 8445 | if (!x_create_x_image_and_pixmap (f, width, height, 0, &ximg, &img->pixmap)) |
| 8445 | g_object_unref (pixbuf); | 8446 | { |
| 8446 | return 0; | 8447 | g_object_unref (pixbuf); |
| 8447 | } | 8448 | return 0; |
| 8449 | } | ||
| 8448 | 8450 | ||
| 8449 | init_color_table (); | 8451 | init_color_table (); |
| 8450 | 8452 | ||
| 8451 | /* TODO: The code is somewhat prepared for other environments than | 8453 | /* Handle alpha channel by combining the image with a background |
| 8452 | X, but is far from done. */ | 8454 | color. */ |
| 8455 | specified_bg = image_spec_value (img->spec, QCbackground, NULL); | ||
| 8456 | if (STRINGP (specified_bg) | ||
| 8457 | && x_defined_color (f, SDATA (specified_bg), &background, 0)) | ||
| 8458 | { | ||
| 8459 | background.red >>= 8; | ||
| 8460 | background.green >>= 8; | ||
| 8461 | background.blue >>= 8; | ||
| 8462 | } | ||
| 8463 | else | ||
| 8464 | { | ||
| 8453 | #ifdef HAVE_X_WINDOWS | 8465 | #ifdef HAVE_X_WINDOWS |
| 8454 | 8466 | background.pixel = FRAME_BACKGROUND_PIXEL (f); | |
| 8455 | background.pixel = FRAME_BACKGROUND_PIXEL (f); | 8467 | x_query_color (f, &background); |
| 8456 | x_query_color (f, &background); | 8468 | |
| 8457 | 8469 | /* SVG pixmaps specify transparency in the last byte, so right | |
| 8458 | /* SVG pixmaps specify transparency in the last byte, so right shift | 8470 | shift 8 bits to get rid of it, since emacs doesnt support |
| 8459 | 8 bits to get rid of it, since emacs doesnt support | 8471 | transparency. */ |
| 8460 | transparency. */ | 8472 | background.red >>= 8; |
| 8461 | background.red >>= 8; | 8473 | background.green >>= 8; |
| 8462 | background.green >>= 8; | 8474 | background.blue >>= 8; |
| 8463 | background.blue >>= 8; | 8475 | #elif defined (MAC_OS) |
| 8464 | 8476 | background.pixel = FRAME_BACKGROUND_PIXEL (f); | |
| 8465 | #else /* not HAVE_X_WINDOWS */ | 8477 | background.red = RED_FROM_ULONG (background.pixel); |
| 8478 | background.green = GREEN_FROM_ULONG (background.pixel); | ||
| 8479 | background.blue = BLUE_FROM_ULONG (background.pixel); | ||
| 8480 | #else /* not HAVE_X_WINDOWS && not MAC_OS*/ | ||
| 8466 | #error FIXME | 8481 | #error FIXME |
| 8467 | #endif | 8482 | #endif |
| 8483 | } | ||
| 8468 | 8484 | ||
| 8469 | /* This loop handles opacity values, since Emacs assumes | 8485 | /* This loop handles opacity values, since Emacs assumes |
| 8470 | non-transparent images. Each pixel must be "flattened" by | 8486 | non-transparent images. Each pixel must be "flattened" by |
| @@ -8505,14 +8521,18 @@ svg_load_image (f, img, contents, size) | |||
| 8505 | 8521 | ||
| 8506 | g_object_unref (pixbuf); | 8522 | g_object_unref (pixbuf); |
| 8507 | 8523 | ||
| 8524 | img->width = width; | ||
| 8525 | img->height = height; | ||
| 8526 | |||
| 8527 | /* Maybe fill in the background field while we have ximg handy. | ||
| 8528 | Casting avoids a GCC warning. */ | ||
| 8529 | IMAGE_BACKGROUND (img, f, (XImagePtr_or_DC)ximg); | ||
| 8530 | |||
| 8508 | /* Put the image into the pixmap, then free the X image and its | 8531 | /* Put the image into the pixmap, then free the X image and its |
| 8509 | buffer. */ | 8532 | buffer. */ |
| 8510 | x_put_x_image (f, ximg, img->pixmap, width, height); | 8533 | x_put_x_image (f, ximg, img->pixmap, width, height); |
| 8511 | x_destroy_x_image (ximg); | 8534 | x_destroy_x_image (ximg); |
| 8512 | 8535 | ||
| 8513 | img->width = width; | ||
| 8514 | img->height = height; | ||
| 8515 | |||
| 8516 | return 1; | 8536 | return 1; |
| 8517 | 8537 | ||
| 8518 | rsvg_error: | 8538 | rsvg_error: |
| @@ -8923,7 +8943,7 @@ of `image-library-alist', which see). */) | |||
| 8923 | if (EQ (type, Qsvg)) | 8943 | if (EQ (type, Qsvg)) |
| 8924 | return CHECK_LIB_AVAILABLE (&svg_type, init_svg_functions, libraries); | 8944 | return CHECK_LIB_AVAILABLE (&svg_type, init_svg_functions, libraries); |
| 8925 | #endif | 8945 | #endif |
| 8926 | 8946 | ||
| 8927 | #ifdef HAVE_GHOSTSCRIPT | 8947 | #ifdef HAVE_GHOSTSCRIPT |
| 8928 | if (EQ (type, Qpostscript)) | 8948 | if (EQ (type, Qpostscript)) |
| 8929 | return CHECK_LIB_AVAILABLE (&gs_type, init_gs_functions, libraries); | 8949 | return CHECK_LIB_AVAILABLE (&gs_type, init_gs_functions, libraries); |
| @@ -9072,7 +9092,6 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 9072 | ADD_IMAGE_TYPE(Qsvg); | 9092 | ADD_IMAGE_TYPE(Qsvg); |
| 9073 | #endif | 9093 | #endif |
| 9074 | 9094 | ||
| 9075 | |||
| 9076 | defsubr (&Sinit_image_library); | 9095 | defsubr (&Sinit_image_library); |
| 9077 | defsubr (&Sclear_image_cache); | 9096 | defsubr (&Sclear_image_cache); |
| 9078 | defsubr (&Simage_refresh); | 9097 | defsubr (&Simage_refresh); |