ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CV/CV.xs
(Generate patch)

Comparing CV/CV.xs (file contents):
Revision 1.47 by root, Tue Jun 7 06:59:57 2016 UTC vs.
Revision 1.48 by root, Wed May 24 05:00:57 2017 UTC

38}; 38};
39 39
40static void 40static void
41cv_error_exit (j_common_ptr cinfo) 41cv_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
46static void 47static void
47cv_error_output (j_common_ptr cinfo) 48cv_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
52static void 58static void
53rgb_to_hsv (unsigned int r, unsigned int g, unsigned int b, 59rgb_to_hsv (unsigned int r, unsigned int g, unsigned int b,
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 data [0] = c * k / 255;
431 data [1] = m * k / 255;
432 data [2] = y * k / 255;
433 data [3] = 255;
434
435 data += 4;
436 }
405 } 437 }
406 438
407 jpeg_finish_decompress (&cinfo); 439 jpeg_finish_decompress (&cinfo);
408 fclose (fp); 440 fclose (fp);
409 jpeg_destroy_decompress (&cinfo); 441 jpeg_destroy_decompress (&cinfo);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines