aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorManuel Giraud2024-11-21 17:19:59 +0100
committerAlan Third2024-12-02 10:43:35 +0000
commit8cd4ab7abde87ac04e05442196b4646ab46df9a7 (patch)
tree6f7a08cb1f64e0b68141b3fc05743bbbeff47d43 /src
parentde98b5a24f2b2ad293b4298bb898842b8f23e5bc (diff)
downloademacs-8cd4ab7abde87ac04e05442196b4646ab46df9a7.tar.gz
emacs-8cd4ab7abde87ac04e05442196b4646ab46df9a7.zip
Do not use libjpeg quantization (bug#74476)
* src/image.c (jpeg_load_body): Remove libjpeg quantization.
Diffstat (limited to 'src')
-rw-r--r--src/image.c80
1 files changed, 31 insertions, 49 deletions
diff --git a/src/image.c b/src/image.c
index 88b0f91413e..43220758324 100644
--- a/src/image.c
+++ b/src/image.c
@@ -8949,9 +8949,8 @@ jpeg_load_body (struct frame *f, struct image *img,
8949 FILE *fp = NULL; 8949 FILE *fp = NULL;
8950 JSAMPARRAY buffer; 8950 JSAMPARRAY buffer;
8951 int row_stride, x, y; 8951 int row_stride, x, y;
8952 int width, height; 8952 int width, height, ncomp;
8953 int i, ir, ig, ib; 8953 int ir, ig, ib;
8954 unsigned long *colors;
8955 Emacs_Pix_Container volatile ximg_volatile = NULL; 8954 Emacs_Pix_Container volatile ximg_volatile = NULL;
8956 8955
8957 /* Open the JPEG file. */ 8956 /* Open the JPEG file. */
@@ -9049,12 +9048,17 @@ jpeg_load_body (struct frame *f, struct image *img,
9049 9048
9050 jpeg_read_header (&mgr->cinfo, 1); 9049 jpeg_read_header (&mgr->cinfo, 1);
9051 9050
9052 /* Customize decompression so that color quantization will be used. 9051 /* Start decompression. */
9053 Start decompression. */
9054 mgr->cinfo.quantize_colors = 1;
9055 jpeg_start_decompress (&mgr->cinfo); 9052 jpeg_start_decompress (&mgr->cinfo);
9056 width = img->width = mgr->cinfo.output_width; 9053 width = img->width = mgr->cinfo.output_width;
9057 height = img->height = mgr->cinfo.output_height; 9054 height = img->height = mgr->cinfo.output_height;
9055 ncomp = mgr->cinfo.output_components;
9056 if (ncomp > 2)
9057 ir = 0, ig = 1, ib = 2;
9058 else if (ncomp > 1)
9059 ir = 0, ig = 1, ib = 0;
9060 else
9061 ir = 0, ig = 0, ib = 0;
9058 9062
9059 if (!check_image_size (f, width, height)) 9063 if (!check_image_size (f, width, height))
9060 { 9064 {
@@ -9073,55 +9077,34 @@ jpeg_load_body (struct frame *f, struct image *img,
9073 sys_longjmp (mgr->setjmp_buffer, 1); 9077 sys_longjmp (mgr->setjmp_buffer, 1);
9074 } 9078 }
9075 9079
9076 /* Allocate colors. When color quantization is used, 9080 /* Allocate scanlines buffer and Emacs color table. */
9077 mgr->cinfo.actual_number_of_colors has been set with the number of 9081 row_stride = width * ncomp;
9078 colors generated, and mgr->cinfo.colormap is a two-dimensional array
9079 of color indices in the range 0..mgr->cinfo.actual_number_of_colors.
9080 No more than 255 colors will be generated. */
9081 USE_SAFE_ALLOCA;
9082 {
9083 if (mgr->cinfo.out_color_components > 2)
9084 ir = 0, ig = 1, ib = 2;
9085 else if (mgr->cinfo.out_color_components > 1)
9086 ir = 0, ig = 1, ib = 0;
9087 else
9088 ir = 0, ig = 0, ib = 0;
9089
9090 /* Use the color table mechanism because it handles colors that
9091 cannot be allocated nicely. Such colors will be replaced with
9092 a default color, and we don't have to care about which colors
9093 can be freed safely, and which can't. */
9094 init_color_table ();
9095 SAFE_NALLOCA (colors, 1, mgr->cinfo.actual_number_of_colors);
9096
9097 for (i = 0; i < mgr->cinfo.actual_number_of_colors; ++i)
9098 {
9099 /* Multiply RGB values with 255 because X expects RGB values
9100 in the range 0..0xffff. */
9101 int r = mgr->cinfo.colormap[ir][i] << 8;
9102 int g = mgr->cinfo.colormap[ig][i] << 8;
9103 int b = mgr->cinfo.colormap[ib][i] << 8;
9104 colors[i] = lookup_rgb_color (f, r, g, b);
9105 }
9106
9107#ifdef COLOR_TABLE_SUPPORT
9108 /* Remember those colors actually allocated. */
9109 img->colors = colors_in_color_table (&img->ncolors);
9110 free_color_table ();
9111#endif /* COLOR_TABLE_SUPPORT */
9112 }
9113
9114 /* Read pixels. */
9115 row_stride = width * mgr->cinfo.output_components;
9116 buffer = mgr->cinfo.mem->alloc_sarray ((j_common_ptr) &mgr->cinfo, 9082 buffer = mgr->cinfo.mem->alloc_sarray ((j_common_ptr) &mgr->cinfo,
9117 JPOOL_IMAGE, row_stride, 1); 9083 JPOOL_IMAGE, row_stride, 1);
9084 init_color_table ();
9085
9086 /* Fill the X image from JPEG data. */
9118 for (y = 0; y < height; ++y) 9087 for (y = 0; y < height; ++y)
9119 { 9088 {
9120 jpeg_read_scanlines (&mgr->cinfo, buffer, 1); 9089 jpeg_read_scanlines (&mgr->cinfo, buffer, 1);
9121 for (x = 0; x < mgr->cinfo.output_width; ++x) 9090 for (x = 0; x < width; ++x)
9122 PUT_PIXEL (ximg, x, y, colors[buffer[0][x]]); 9091 {
9092 int off = x * ncomp;
9093 /* Multiply RGB values with 255 because X expects RGB values
9094 in the range 0..0xffff. */
9095 int r = buffer[0][off + ir] << 8;
9096 int g = buffer[0][off + ig] << 8;
9097 int b = buffer[0][off + ib] << 8;
9098 PUT_PIXEL (ximg, x, y, lookup_rgb_color (f, r, g, b));
9099 }
9123 } 9100 }
9124 9101
9102#ifdef COLOR_TABLE_SUPPORT
9103 /* Remember those colors actually allocated. */
9104 img->colors = colors_in_color_table (&img->ncolors);
9105 free_color_table ();
9106#endif /* COLOR_TABLE_SUPPORT */
9107
9125 /* Clean up. */ 9108 /* Clean up. */
9126 jpeg_finish_decompress (&mgr->cinfo); 9109 jpeg_finish_decompress (&mgr->cinfo);
9127 jpeg_destroy_decompress (&mgr->cinfo); 9110 jpeg_destroy_decompress (&mgr->cinfo);
@@ -9135,7 +9118,6 @@ jpeg_load_body (struct frame *f, struct image *img,
9135 9118
9136 /* Put ximg into the image. */ 9119 /* Put ximg into the image. */
9137 image_put_x_image (f, img, ximg, 0); 9120 image_put_x_image (f, img, ximg, 0);
9138 SAFE_FREE ();
9139 return 1; 9121 return 1;
9140} 9122}
9141 9123