summaryrefslogtreecommitdiff
path: root/src/gd_jpeg.c
diff options
context:
space:
mode:
authorpierre <none@none>2006-04-05 15:51:53 +0000
committerpierre <none@none>2006-04-05 15:51:53 +0000
commit0a3439a3e7f6be09b8a5b90ea1b19b3a6090ec53 (patch)
tree37fbdf92d74507ca5aa3491e753a8d3b86b2b4cc /src/gd_jpeg.c
parent480330b083f8e4e5f08d99510179482af6e5b829 (diff)
downloadlibgd-0a3439a3e7f6be09b8a5b90ea1b19b3a6090ec53.tar.gz
- sync to 2.0.23
Diffstat (limited to 'src/gd_jpeg.c')
-rw-r--r--src/gd_jpeg.c253
1 files changed, 137 insertions, 116 deletions
diff --git a/src/gd_jpeg.c b/src/gd_jpeg.c
index 77ec1f1..ca8ac3d 100644
--- a/src/gd_jpeg.c
+++ b/src/gd_jpeg.c
@@ -281,7 +281,7 @@ gdImageCreateFromJpegPtr (int size, void *data)
void jpeg_gdIOCtx_src (j_decompress_ptr cinfo, gdIOCtx * infile);
-static int CMYKToRGB(int c, int m, int y, int k, int inverted);
+static int CMYKToRGB (int c, int m, int y, int k, int inverted);
/*
* Create a gd-format image from the JPEG-format INFILE. Returns the
@@ -329,14 +329,14 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
jpeg_gdIOCtx_src (&cinfo, infile);
/* 2.0.22: save the APP14 marker to check for Adobe Photoshop CMYK
- files with inverted components. */
- jpeg_save_markers(&cinfo, JPEG_APP0 + 14, 256);
+ files with inverted components. */
+ jpeg_save_markers (&cinfo, JPEG_APP0 + 14, 256);
retval = jpeg_read_header (&cinfo, TRUE);
if (retval != JPEG_HEADER_OK)
fprintf (stderr, "gd-jpeg: warning: jpeg_read_header returns"
" %d, expected %d\n", retval, JPEG_HEADER_OK);
-
+
if (cinfo.image_height > INT_MAX)
fprintf (stderr, "gd-jpeg: warning: JPEG image height (%u) is"
" greater than INT_MAX (%d) (and thus greater than"
@@ -355,15 +355,17 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
goto error;
}
/* 2.0.22: very basic support for reading CMYK colorspace files. Nice for
- thumbnails but there's no support for fussy adjustment of the
- assumed properties of inks and paper. */
+ thumbnails but there's no support for fussy adjustment of the
+ assumed properties of inks and paper. */
if ((cinfo.jpeg_color_space == JCS_CMYK) ||
- (cinfo.jpeg_color_space == JCS_YCCK))
- {
- cinfo.out_color_space = JCS_CMYK;
- } else {
- cinfo.out_color_space = JCS_RGB;
- }
+ (cinfo.jpeg_color_space == JCS_YCCK))
+ {
+ cinfo.out_color_space = JCS_CMYK;
+ }
+ else
+ {
+ cinfo.out_color_space = JCS_RGB;
+ }
if (jpeg_start_decompress (&cinfo) != TRUE)
fprintf (stderr, "gd-jpeg: warning: jpeg_start_decompress"
@@ -426,41 +428,46 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
#if 0
gdImageInterlace (im, cinfo.progressive_mode != 0);
#endif
- if (cinfo.out_color_space == JCS_RGB)
- {
- if (cinfo.output_components != 3)
+ if (cinfo.out_color_space == JCS_RGB)
{
- fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
- " request resulted in output_components == %d"
- " (expected 3 for RGB)\n", cinfo.output_components);
- goto error;
+ if (cinfo.output_components != 3)
+ {
+ fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
+ " request resulted in output_components == %d"
+ " (expected 3 for RGB)\n", cinfo.output_components);
+ goto error;
+ }
+ channels = 3;
}
- channels = 3;
- } else if (cinfo.out_color_space == JCS_CMYK) {
- jpeg_saved_marker_ptr marker;
- if (cinfo.output_components != 4)
+ else if (cinfo.out_color_space == JCS_CMYK)
{
- fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
- " request resulted in output_components == %d"
- " (expected 4 for CMYK)\n", cinfo.output_components);
+ jpeg_saved_marker_ptr marker;
+ if (cinfo.output_components != 4)
+ {
+ fprintf (stderr, "gd-jpeg: error: JPEG color quantization"
+ " request resulted in output_components == %d"
+ " (expected 4 for CMYK)\n", cinfo.output_components);
+ goto error;
+ }
+ channels = 4;
+ marker = cinfo.marker_list;
+ while (marker)
+ {
+ if ((marker->marker == (JPEG_APP0 + 14)) &&
+ (marker->data_length >= 12)
+ && (!strncmp ((const char *) marker->data, "Adobe", 5)))
+ {
+ inverted = 1;
+ break;
+ }
+ marker = marker->next;
+ }
+ }
+ else
+ {
+ fprintf (stderr, "gd-jpeg: error: unexpected colorspace\n");
goto error;
}
- channels = 4;
- marker = cinfo.marker_list;
- while (marker) {
- if ((marker->marker == (JPEG_APP0 + 14)) &&
- (marker->data_length >= 12) && (!strncmp((const char *) marker->data,
- "Adobe", 5)))
- {
- inverted = 1;
- break;
- }
- marker = marker->next;
- }
- } else {
- fprintf (stderr, "gd-jpeg: error: unexpected colorspace\n");
- goto error;
- }
#if BITS_IN_JSAMPLE == 12
fprintf (stderr, "gd-jpeg: error: jpeg library was compiled for 12-bit\n"
"precision. This is mostly useless, because JPEGs on the web are\n"
@@ -479,47 +486,52 @@ gdImageCreateFromJpegCtx (gdIOCtx * infile)
goto error;
}
rowptr[0] = row;
- if (cinfo.out_color_space == JCS_CMYK) {
- for (i = 0; i < cinfo.output_height; i++)
- {
- register JSAMPROW currow = row;
- register int *tpix = im->tpixels[i];
- nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
- if (nrows != 1)
- {
- fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
- " returns %u, expected 1\n", nrows);
- goto error;
- }
- for (j = 0; j < cinfo.output_width; j++, currow += 4, tpix++)
- {
- *tpix = CMYKToRGB (currow[0], currow[1], currow[2], currow[3], inverted);
- }
- }
- } else {
- for (i = 0; i < cinfo.output_height; i++)
- {
- register JSAMPROW currow = row;
- register int *tpix = im->tpixels[i];
- nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
- if (nrows != 1)
- {
- fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
- " returns %u, expected 1\n", nrows);
- goto error;
- }
- for (j = 0; j < cinfo.output_width; j++, currow += 3, tpix++)
- {
- *tpix = gdTrueColor (currow[0], currow[1], currow[2]);
- }
- }
- }
+ if (cinfo.out_color_space == JCS_CMYK)
+ {
+ for (i = 0; i < cinfo.output_height; i++)
+ {
+ register JSAMPROW currow = row;
+ register int *tpix = im->tpixels[i];
+ nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
+ if (nrows != 1)
+ {
+ fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
+ " returns %u, expected 1\n", nrows);
+ goto error;
+ }
+ for (j = 0; j < cinfo.output_width; j++, currow += 4, tpix++)
+ {
+ *tpix =
+ CMYKToRGB (currow[0], currow[1], currow[2], currow[3],
+ inverted);
+ }
+ }
+ }
+ else
+ {
+ for (i = 0; i < cinfo.output_height; i++)
+ {
+ register JSAMPROW currow = row;
+ register int *tpix = im->tpixels[i];
+ nrows = jpeg_read_scanlines (&cinfo, rowptr, 1);
+ if (nrows != 1)
+ {
+ fprintf (stderr, "gd-jpeg: error: jpeg_read_scanlines"
+ " returns %u, expected 1\n", nrows);
+ goto error;
+ }
+ for (j = 0; j < cinfo.output_width; j++, currow += 3, tpix++)
+ {
+ *tpix = gdTrueColor (currow[0], currow[1], currow[2]);
+ }
+ }
+ }
if (jpeg_finish_decompress (&cinfo) != TRUE)
fprintf (stderr, "gd-jpeg: warning: jpeg_finish_decompress"
" reports suspended data source\n");
/* Thanks to Truxton Fulton */
- if(cinfo.err->num_warnings>0)
- goto error ;
+ if (cinfo.err->num_warnings > 0)
+ goto error;
jpeg_destroy_decompress (&cinfo);
gdFree (row);
@@ -535,50 +547,59 @@ error:
}
/* A very basic conversion approach, TBB */
-
-static int CMYKToRGB(int c, int m, int y, int k, int inverted)
+
+static int
+CMYKToRGB (int c, int m, int y, int k, int inverted)
{
- if (inverted) {
- c = 255 - c;
- m = 255 - m;
- y = 255 - y;
- k = 255 - k;
- }
- return gdTrueColor((255 - c) * (255 - k) / 255,
- (255 - m) * (255 - k) / 255,
- (255 - y) * (255 - k) / 255);
+ if (inverted)
+ {
+ c = 255 - c;
+ m = 255 - m;
+ y = 255 - y;
+ k = 255 - k;
+ }
+ return gdTrueColor ((255 - c) * (255 - k) / 255,
+ (255 - m) * (255 - k) / 255,
+ (255 - y) * (255 - k) / 255);
#if 0
- if (inverted) {
- c = 255 - c;
- m = 255 - m;
- y = 255 - y;
- k = 255 - k;
- }
+ if (inverted)
+ {
+ c = 255 - c;
+ m = 255 - m;
+ y = 255 - y;
+ k = 255 - k;
+ }
c = c * (255 - k) / 255 + k;
- if (c > 255) {
- c = 255;
- }
- if (c < 0) {
- c = 0;
- }
+ if (c > 255)
+ {
+ c = 255;
+ }
+ if (c < 0)
+ {
+ c = 0;
+ }
m = m * (255 - k) / 255 + k;
- if (m > 255) {
- m = 255;
- }
- if (m < 0) {
- m = 0;
- }
+ if (m > 255)
+ {
+ m = 255;
+ }
+ if (m < 0)
+ {
+ m = 0;
+ }
y = y * (255 - k) / 255 + k;
- if (y > 255) {
- y = 255;
- }
- if (y < 0) {
- y = 0;
- }
+ if (y > 255)
+ {
+ y = 255;
+ }
+ if (y < 0)
+ {
+ y = 0;
+ }
c = 255 - c;
m = 255 - m;
y = 255 - y;
- return gdTrueColor(c, m, y);
+ return gdTrueColor (c, m, y);
#endif
}
@@ -677,7 +698,7 @@ fill_input_buffer (j_decompress_ptr cinfo)
my_src_ptr src = (my_src_ptr) cinfo->src;
/* 2.0.12: signed size. Thanks to Geert Jansen */
/* 2.0.14: some platforms (mingw-msys) don't have ssize_t. Call
- an int an int. */
+ an int an int. */
int nbytes = 0;
memset (src->buffer, 0, INPUT_BUF_SIZE);