diff options
| author | Jan D | 2015-04-11 15:37:45 +0200 |
|---|---|---|
| committer | Jan D | 2015-04-11 15:37:45 +0200 |
| commit | be008ff0c4ce6f88652d1a3c9ac1cedfba58a29a (patch) | |
| tree | 4fa8729eab696aabff8bac7a2a04a9072081a77a /src/image.c | |
| parent | 69a8655d7190b1dc28de9cbc786a86e8966a45a4 (diff) | |
| download | emacs-be008ff0c4ce6f88652d1a3c9ac1cedfba58a29a.tar.gz emacs-be008ff0c4ce6f88652d1a3c9ac1cedfba58a29a.zip | |
Support JPEG with USE_CAIRO.
* configure.ac: Allow jpeg with cairo.
* src/image.c (jpeg_load_body): Create cairo image surface if USE_CAIRO.
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/image.c b/src/image.c index 895021c4b41..83f9b38cfec 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -6564,6 +6564,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6564 | XImagePtr ximg = NULL; | 6564 | XImagePtr ximg = NULL; |
| 6565 | unsigned long *colors; | 6565 | unsigned long *colors; |
| 6566 | int width, height; | 6566 | int width, height; |
| 6567 | int i, ir, ig, ib; | ||
| 6567 | 6568 | ||
| 6568 | /* Open the JPEG file. */ | 6569 | /* Open the JPEG file. */ |
| 6569 | specified_file = image_spec_value (img->spec, QCfile, NULL); | 6570 | specified_file = image_spec_value (img->spec, QCfile, NULL); |
| @@ -6668,8 +6669,6 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6668 | No more than 255 colors will be generated. */ | 6669 | No more than 255 colors will be generated. */ |
| 6669 | USE_SAFE_ALLOCA; | 6670 | USE_SAFE_ALLOCA; |
| 6670 | { | 6671 | { |
| 6671 | int i, ir, ig, ib; | ||
| 6672 | |||
| 6673 | if (mgr->cinfo.out_color_components > 2) | 6672 | if (mgr->cinfo.out_color_components > 2) |
| 6674 | ir = 0, ig = 1, ib = 2; | 6673 | ir = 0, ig = 1, ib = 2; |
| 6675 | else if (mgr->cinfo.out_color_components > 1) | 6674 | else if (mgr->cinfo.out_color_components > 1) |
| @@ -6677,6 +6676,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6677 | else | 6676 | else |
| 6678 | ir = 0, ig = 0, ib = 0; | 6677 | ir = 0, ig = 0, ib = 0; |
| 6679 | 6678 | ||
| 6679 | #ifndef CAIRO | ||
| 6680 | /* Use the color table mechanism because it handles colors that | 6680 | /* Use the color table mechanism because it handles colors that |
| 6681 | cannot be allocated nicely. Such colors will be replaced with | 6681 | cannot be allocated nicely. Such colors will be replaced with |
| 6682 | a default color, and we don't have to care about which colors | 6682 | a default color, and we don't have to care about which colors |
| @@ -6693,6 +6693,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6693 | int b = mgr->cinfo.colormap[ib][i] << 8; | 6693 | int b = mgr->cinfo.colormap[ib][i] << 8; |
| 6694 | colors[i] = lookup_rgb_color (f, r, g, b); | 6694 | colors[i] = lookup_rgb_color (f, r, g, b); |
| 6695 | } | 6695 | } |
| 6696 | #endif | ||
| 6696 | 6697 | ||
| 6697 | #ifdef COLOR_TABLE_SUPPORT | 6698 | #ifdef COLOR_TABLE_SUPPORT |
| 6698 | /* Remember those colors actually allocated. */ | 6699 | /* Remember those colors actually allocated. */ |
| @@ -6705,12 +6706,49 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6705 | row_stride = width * mgr->cinfo.output_components; | 6706 | row_stride = width * mgr->cinfo.output_components; |
| 6706 | buffer = mgr->cinfo.mem->alloc_sarray ((j_common_ptr) &mgr->cinfo, | 6707 | buffer = mgr->cinfo.mem->alloc_sarray ((j_common_ptr) &mgr->cinfo, |
| 6707 | JPOOL_IMAGE, row_stride, 1); | 6708 | JPOOL_IMAGE, row_stride, 1); |
| 6709 | #ifdef USE_CAIRO | ||
| 6710 | { | ||
| 6711 | cairo_surface_t *surface; | ||
| 6712 | cairo_format_t format = CAIRO_FORMAT_ARGB32; | ||
| 6713 | int stride = cairo_format_stride_for_width (format, width); | ||
| 6714 | unsigned char *data = (unsigned char *) xmalloc (width*height*4); | ||
| 6715 | uint32_t *dataptr = (uint32_t *) data; | ||
| 6716 | int r, g, b; | ||
| 6717 | |||
| 6718 | for (y = 0; y < height; ++y) | ||
| 6719 | { | ||
| 6720 | jpeg_read_scanlines (&mgr->cinfo, buffer, 1); | ||
| 6721 | |||
| 6722 | for (x = 0; x < width; ++x) | ||
| 6723 | { | ||
| 6724 | i = buffer[0][x]; | ||
| 6725 | r = mgr->cinfo.colormap[ir][i]; | ||
| 6726 | g = mgr->cinfo.colormap[ig][i]; | ||
| 6727 | b = mgr->cinfo.colormap[ib][i]; | ||
| 6728 | *dataptr++ = (0xff << 24) | (r << 16) | (g << 8) | b; | ||
| 6729 | } | ||
| 6730 | } | ||
| 6731 | |||
| 6732 | surface = cairo_image_surface_create_for_data (data, | ||
| 6733 | format, | ||
| 6734 | width, | ||
| 6735 | height, | ||
| 6736 | stride); | ||
| 6737 | |||
| 6738 | img->width = width; | ||
| 6739 | img->height = height; | ||
| 6740 | img->cr_data = surface; | ||
| 6741 | img->cr_data2 = data; | ||
| 6742 | img->pixmap = 0; | ||
| 6743 | } | ||
| 6744 | #else | ||
| 6708 | for (y = 0; y < height; ++y) | 6745 | for (y = 0; y < height; ++y) |
| 6709 | { | 6746 | { |
| 6710 | jpeg_read_scanlines (&mgr->cinfo, buffer, 1); | 6747 | jpeg_read_scanlines (&mgr->cinfo, buffer, 1); |
| 6711 | for (x = 0; x < mgr->cinfo.output_width; ++x) | 6748 | for (x = 0; x < mgr->cinfo.output_width; ++x) |
| 6712 | XPutPixel (ximg, x, y, colors[buffer[0][x]]); | 6749 | XPutPixel (ximg, x, y, colors[buffer[0][x]]); |
| 6713 | } | 6750 | } |
| 6751 | #endif | ||
| 6714 | 6752 | ||
| 6715 | /* Clean up. */ | 6753 | /* Clean up. */ |
| 6716 | jpeg_finish_decompress (&mgr->cinfo); | 6754 | jpeg_finish_decompress (&mgr->cinfo); |
| @@ -6718,6 +6756,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6718 | if (fp) | 6756 | if (fp) |
| 6719 | fclose (fp); | 6757 | fclose (fp); |
| 6720 | 6758 | ||
| 6759 | #ifndef CAIRO | ||
| 6721 | /* Maybe fill in the background field while we have ximg handy. */ | 6760 | /* Maybe fill in the background field while we have ximg handy. */ |
| 6722 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) | 6761 | if (NILP (image_spec_value (img->spec, QCbackground, NULL))) |
| 6723 | /* Casting avoids a GCC warning. */ | 6762 | /* Casting avoids a GCC warning. */ |
| @@ -6725,6 +6764,7 @@ jpeg_load_body (struct frame *f, struct image *img, | |||
| 6725 | 6764 | ||
| 6726 | /* Put ximg into the image. */ | 6765 | /* Put ximg into the image. */ |
| 6727 | image_put_x_image (f, img, ximg, 0); | 6766 | image_put_x_image (f, img, ximg, 0); |
| 6767 | #endif | ||
| 6728 | SAFE_FREE (); | 6768 | SAFE_FREE (); |
| 6729 | return 1; | 6769 | return 1; |
| 6730 | } | 6770 | } |