… | |
… | |
38 | }; |
38 | }; |
39 | |
39 | |
40 | static void |
40 | static void |
41 | cv_error_exit (j_common_ptr cinfo) |
41 | cv_error_exit (j_common_ptr cinfo) |
42 | { |
42 | { |
|
|
43 | cinfo->err->output_message (cinfo); |
43 | longjmp (((struct jpg_err_mgr *)cinfo->err)->setjmp_buffer, 99); |
44 | longjmp (((struct jpg_err_mgr *)cinfo->err)->setjmp_buffer, 99); |
44 | } |
45 | } |
45 | |
46 | |
46 | static void |
47 | static void |
47 | cv_error_output (j_common_ptr cinfo) |
48 | cv_error_output (j_common_ptr cinfo) |
48 | { |
49 | { |
|
|
50 | char msg[JMSG_LENGTH_MAX]; |
|
|
51 | |
|
|
52 | cinfo->err->format_message (cinfo, msg); |
|
|
53 | |
|
|
54 | fprintf (stderr, "JPEG decoding error: %s\n", msg); |
49 | return; |
55 | return; |
50 | } |
56 | } |
51 | |
57 | |
52 | static void |
58 | static void |
53 | rgb_to_hsv (unsigned int r, unsigned int g, unsigned int b, |
59 | rgb_to_hsv (unsigned int r, unsigned int g, unsigned int b, |
… | |
… | |
150 | if (!--a85_cnt) |
156 | if (!--a85_cnt) |
151 | { |
157 | { |
152 | a85_cnt = 4; |
158 | a85_cnt = 4; |
153 | if (a85_val) |
159 | if (a85_val) |
154 | { |
160 | { |
155 | a85_ptr[4] = (a85_val % 85) + 33; a85_val /= 85; |
161 | a85_ptr[4] = (a85_val % 85) + 33; a85_val /= 85; |
156 | a85_ptr[3] = (a85_val % 85) + 33; a85_val /= 85; |
162 | a85_ptr[3] = (a85_val % 85) + 33; a85_val /= 85; |
157 | a85_ptr[2] = (a85_val % 85) + 33; a85_val /= 85; |
163 | a85_ptr[2] = (a85_val % 85) + 33; a85_val /= 85; |
158 | a85_ptr[1] = (a85_val % 85) + 33; a85_val /= 85; |
164 | a85_ptr[1] = (a85_val % 85) + 33; a85_val /= 85; |
159 | a85_ptr[0] = (a85_val ) + 33; |
165 | a85_ptr[0] = (a85_val ) + 33; |
160 | |
166 | |
161 | a85_ptr += 5; |
167 | a85_ptr += 5; |
162 | } |
168 | } |
… | |
… | |
377 | cinfo.scale_denom <<= 1; |
383 | cinfo.scale_denom <<= 1; |
378 | jpeg_calc_output_dimensions (&cinfo); |
384 | jpeg_calc_output_dimensions (&cinfo); |
379 | } |
385 | } |
380 | } |
386 | } |
381 | |
387 | |
|
|
388 | if (cinfo.output_components != 3) |
|
|
389 | longjmp (jerr.setjmp_buffer, 3); |
|
|
390 | |
|
|
391 | if (cinfo.jpeg_color_space == JCS_YCCK || cinfo.jpeg_color_space == JCS_CMYK) |
|
|
392 | { |
|
|
393 | cinfo.out_color_space = JCS_CMYK; |
|
|
394 | cinfo.output_components = 4; |
|
|
395 | } |
|
|
396 | |
382 | pb = RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, 0, 8, cinfo.output_width, cinfo.output_height); |
397 | pb = RETVAL = gdk_pixbuf_new (GDK_COLORSPACE_RGB, cinfo.output_components == 4, 8, cinfo.output_width, cinfo.output_height); |
383 | if (!RETVAL) |
398 | if (!RETVAL) |
384 | longjmp (jerr.setjmp_buffer, 2); |
399 | longjmp (jerr.setjmp_buffer, 2); |
385 | |
400 | |
386 | data = gdk_pixbuf_get_pixels (RETVAL); |
401 | data = gdk_pixbuf_get_pixels (RETVAL); |
387 | rs = gdk_pixbuf_get_rowstride (RETVAL); |
402 | rs = gdk_pixbuf_get_rowstride (RETVAL); |
388 | |
|
|
389 | if (cinfo.output_components != 3) |
|
|
390 | longjmp (jerr.setjmp_buffer, 3); |
|
|
391 | |
403 | |
392 | jpeg_start_decompress (&cinfo); |
404 | jpeg_start_decompress (&cinfo); |
393 | |
405 | |
394 | while (cinfo.output_scanline < cinfo.output_height) |
406 | while (cinfo.output_scanline < cinfo.output_height) |
395 | { |
407 | { |
… | |
… | |
400 | rp [1] = (guchar *)rp [0] + rs; |
412 | rp [1] = (guchar *)rp [0] + rs; |
401 | rp [2] = (guchar *)rp [1] + rs; |
413 | rp [2] = (guchar *)rp [1] + rs; |
402 | rp [3] = (guchar *)rp [2] + rs; |
414 | rp [3] = (guchar *)rp [2] + rs; |
403 | |
415 | |
404 | jpeg_read_scanlines (&cinfo, rp, remaining < 4 ? remaining : 4); |
416 | jpeg_read_scanlines (&cinfo, rp, remaining < 4 ? remaining : 4); |
|
|
417 | } |
|
|
418 | |
|
|
419 | if (cinfo.out_color_space == JCS_CMYK) |
|
|
420 | { |
|
|
421 | guchar *end = data + cinfo.output_height * rs; |
|
|
422 | |
|
|
423 | while (data < end) |
|
|
424 | { |
|
|
425 | U32 c = data [0]; |
|
|
426 | U32 m = data [1]; |
|
|
427 | U32 y = data [2]; |
|
|
428 | U32 k = data [3]; |
|
|
429 | |
|
|
430 | if (0) |
|
|
431 | if (cinfo.Adobe_transform == 2) |
|
|
432 | { |
|
|
433 | c ^= 0xff; |
|
|
434 | m ^= 0xff; |
|
|
435 | y ^= 0xff; |
|
|
436 | k ^= 0xff; |
|
|
437 | } |
|
|
438 | |
|
|
439 | data [0] = (c * k + 0x80) / 0xff; |
|
|
440 | data [1] = (m * k + 0x80) / 0xff; |
|
|
441 | data [2] = (y * k + 0x80) / 0xff; |
|
|
442 | data [3] = 0xff; |
|
|
443 | |
|
|
444 | data += 4; |
|
|
445 | } |
405 | } |
446 | } |
406 | |
447 | |
407 | jpeg_finish_decompress (&cinfo); |
448 | jpeg_finish_decompress (&cinfo); |
408 | fclose (fp); |
449 | fclose (fp); |
409 | jpeg_destroy_decompress (&cinfo); |
450 | jpeg_destroy_decompress (&cinfo); |