diff options
author | Thomas Deutschmann <whissi@gentoo.org> | 2021-09-27 11:19:24 +0200 |
---|---|---|
committer | Thomas Deutschmann <whissi@gentoo.org> | 2021-10-20 18:22:47 +0200 |
commit | cc6be9c3577168805ec34b2d396e63361012282b (patch) | |
tree | 7dc794b08a1a6a786d540516c623cb1eebfb1863 /jpeg/rdbmp.c | |
parent | Import Ghostscript 9.54 (diff) | |
download | ghostscript-gpl-patches-cc6be9c3577168805ec34b2d396e63361012282b.tar.gz ghostscript-gpl-patches-cc6be9c3577168805ec34b2d396e63361012282b.tar.bz2 ghostscript-gpl-patches-cc6be9c3577168805ec34b2d396e63361012282b.zip |
Import Ghostscript 9.55ghostscript-9.55
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'jpeg/rdbmp.c')
-rw-r--r-- | jpeg/rdbmp.c | 97 |
1 files changed, 38 insertions, 59 deletions
diff --git a/jpeg/rdbmp.c b/jpeg/rdbmp.c index 6639ad06..6749ea01 100644 --- a/jpeg/rdbmp.c +++ b/jpeg/rdbmp.c @@ -2,7 +2,7 @@ * rdbmp.c * * Copyright (C) 1994-1996, Thomas G. Lane. - * Modified 2009-2017 by Guido Vollbeding. + * Modified 2009-2019 by Guido Vollbeding. * This file is part of the Independent JPEG Group's software. * For conditions of distribution and use, see the accompanying README file. * @@ -33,11 +33,10 @@ typedef unsigned char U_CHAR; #define UCH(x) ((int) (x)) #else /* !HAVE_UNSIGNED_CHAR */ -#ifdef CHAR_IS_UNSIGNED typedef char U_CHAR; +#ifdef CHAR_IS_UNSIGNED #define UCH(x) ((int) (x)) #else -typedef char U_CHAR; #define UCH(x) ((int) (x) & 0xFF) #endif #endif /* HAVE_UNSIGNED_CHAR */ @@ -105,7 +104,6 @@ read_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize) break; default: ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP); - break; } } @@ -122,7 +120,6 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* This version is for reading 8-bit colormap indexes */ { bmp_source_ptr source = (bmp_source_ptr) sinfo; - JSAMPARRAY image_ptr; register JSAMPROW inptr, outptr; register JSAMPARRAY colormap; register JDIMENSION col; @@ -131,12 +128,10 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* Fetch next row from virtual array */ source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source->source_row, (JDIMENSION) 1, FALSE); + inptr = * (*cinfo->mem->access_virt_sarray) ((j_common_ptr) cinfo, + source->whole_image, source->source_row, (JDIMENSION) 1, FALSE); /* Expand the colormap indexes to real data */ - inptr = image_ptr[0]; outptr = source->pub.buffer[0]; colormap = source->colormap; cmaplen = source->cmap_length; @@ -152,26 +147,22 @@ get_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) return 1; } - METHODDEF(JDIMENSION) get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* This version is for reading 24-bit pixels */ { bmp_source_ptr source = (bmp_source_ptr) sinfo; - JSAMPARRAY image_ptr; register JSAMPROW inptr, outptr; register JDIMENSION col; /* Fetch next row from virtual array */ source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source->source_row, (JDIMENSION) 1, FALSE); + inptr = * (*cinfo->mem->access_virt_sarray) ((j_common_ptr) cinfo, + source->whole_image, source->source_row, (JDIMENSION) 1, FALSE); /* Transfer data. Note source values are in BGR order * (even though Microsoft's own documents say the opposite). */ - inptr = image_ptr[0]; outptr = source->pub.buffer[0]; for (col = cinfo->image_width; col > 0; col--) { outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ @@ -183,26 +174,22 @@ get_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) return 1; } - METHODDEF(JDIMENSION) get_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* This version is for reading 32-bit pixels */ { bmp_source_ptr source = (bmp_source_ptr) sinfo; - JSAMPARRAY image_ptr; register JSAMPROW inptr, outptr; register JDIMENSION col; /* Fetch next row from virtual array */ source->source_row--; - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - source->source_row, (JDIMENSION) 1, FALSE); + inptr = * (*cinfo->mem->access_virt_sarray) ((j_common_ptr) cinfo, + source->whole_image, source->source_row, (JDIMENSION) 1, FALSE); /* Transfer data. Note source values are in BGR order * (even though Microsoft's own documents say the opposite). */ - inptr = image_ptr[0]; outptr = source->pub.buffer[0]; for (col = cinfo->image_width; col > 0; col--) { outptr[2] = *inptr++; /* can omit GETJSAMPLE() safely */ @@ -229,7 +216,6 @@ preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) register FILE *infile = source->pub.input_file; register int c; register JSAMPROW out_ptr; - JSAMPARRAY image_ptr; JDIMENSION row, col; cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress; @@ -240,10 +226,8 @@ preload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) progress->pub.pass_limit = (long) cinfo->image_height; (*progress->pub.progress_monitor) ((j_common_ptr) cinfo); } - image_ptr = (*cinfo->mem->access_virt_sarray) - ((j_common_ptr) cinfo, source->whole_image, - row, (JDIMENSION) 1, TRUE); - out_ptr = image_ptr[0]; + out_ptr = * (*cinfo->mem->access_virt_sarray) ((j_common_ptr) cinfo, + source->whole_image, row, (JDIMENSION) 1, TRUE); for (col = source->row_width; col > 0; col--) { /* inline copy of read_byte() for speed */ if ((c = getc(infile)) == EOF) @@ -285,12 +269,12 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) bmp_source_ptr source = (bmp_source_ptr) sinfo; U_CHAR bmpfileheader[14]; U_CHAR bmpinfoheader[64]; -#define GET_2B(array,offset) ((unsigned int) UCH(array[offset]) + \ - (((unsigned int) UCH(array[offset+1])) << 8)) -#define GET_4B(array,offset) ((INT32) UCH(array[offset]) + \ - (((INT32) UCH(array[offset+1])) << 8) + \ - (((INT32) UCH(array[offset+2])) << 16) + \ - (((INT32) UCH(array[offset+3])) << 24)) +#define GET_2B(array, offset) ((unsigned int) UCH(array[offset]) + \ + (((unsigned int) UCH(array[offset+1])) << 8)) +#define GET_4B(array, offset) ((INT32) UCH(array[offset]) + \ + (((INT32) UCH(array[offset+1])) << 8) + \ + (((INT32) UCH(array[offset+2])) << 16) + \ + (((INT32) UCH(array[offset+3])) << 24)) INT32 bfOffBits; INT32 headerSize; INT32 biWidth; @@ -306,9 +290,9 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) /* Read and verify the bitmap file header */ if (! ReadOK(source->pub.input_file, bmpfileheader, 14)) ERREXIT(cinfo, JERR_INPUT_EOF); - if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */ + if (GET_2B(bmpfileheader, 0) != 0x4D42) /* 'BM' */ ERREXIT(cinfo, JERR_BMP_NOT); - bfOffBits = GET_4B(bmpfileheader,10); + bfOffBits = GET_4B(bmpfileheader, 10); /* We ignore the remaining fileheader fields */ /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows), @@ -316,19 +300,19 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) */ if (! ReadOK(source->pub.input_file, bmpinfoheader, 4)) ERREXIT(cinfo, JERR_INPUT_EOF); - headerSize = GET_4B(bmpinfoheader,0); + headerSize = GET_4B(bmpinfoheader, 0); if (headerSize < 12 || headerSize > 64) ERREXIT(cinfo, JERR_BMP_BADHEADER); - if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4)) + if (! ReadOK(source->pub.input_file, bmpinfoheader + 4, headerSize - 4)) ERREXIT(cinfo, JERR_INPUT_EOF); switch ((int) headerSize) { case 12: /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */ - biWidth = (INT32) GET_2B(bmpinfoheader,4); - biHeight = (INT32) GET_2B(bmpinfoheader,6); - biPlanes = GET_2B(bmpinfoheader,8); - source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10); + biWidth = (INT32) GET_2B(bmpinfoheader, 4); + biHeight = (INT32) GET_2B(bmpinfoheader, 6); + biPlanes = GET_2B(bmpinfoheader, 8); + source->bits_per_pixel = (int) GET_2B(bmpinfoheader, 10); switch (source->bits_per_pixel) { case 8: /* colormapped image */ @@ -342,21 +326,20 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) break; default: ERREXIT(cinfo, JERR_BMP_BADDEPTH); - break; } break; case 40: case 64: /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */ /* or OS/2 2.x header, which has additional fields that we ignore */ - biWidth = GET_4B(bmpinfoheader,4); - biHeight = GET_4B(bmpinfoheader,8); - biPlanes = GET_2B(bmpinfoheader,12); - source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14); - biCompression = GET_4B(bmpinfoheader,16); - biXPelsPerMeter = GET_4B(bmpinfoheader,24); - biYPelsPerMeter = GET_4B(bmpinfoheader,28); - biClrUsed = GET_4B(bmpinfoheader,32); + biWidth = GET_4B(bmpinfoheader, 4); + biHeight = GET_4B(bmpinfoheader, 8); + biPlanes = GET_2B(bmpinfoheader, 12); + source->bits_per_pixel = (int) GET_2B(bmpinfoheader, 14); + biCompression = GET_4B(bmpinfoheader, 16); + biXPelsPerMeter = GET_4B(bmpinfoheader, 24); + biYPelsPerMeter = GET_4B(bmpinfoheader, 28); + biClrUsed = GET_4B(bmpinfoheader, 32); /* biSizeImage, biClrImportant fields are ignored */ switch (source->bits_per_pixel) { @@ -371,7 +354,6 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) break; default: ERREXIT(cinfo, JERR_BMP_BADDEPTH); - break; } if (biCompression != 0) ERREXIT(cinfo, JERR_BMP_COMPRESSED); @@ -404,9 +386,8 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) else if (biClrUsed > 256) ERREXIT(cinfo, JERR_BMP_BADCMAP); /* Allocate space to store the colormap */ - source->colormap = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) biClrUsed, (JDIMENSION) 3); + source->colormap = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, + JPOOL_IMAGE, (JDIMENSION) biClrUsed, (JDIMENSION) 3); source->cmap_length = (int) biClrUsed; /* and read it from the file */ read_colormap(source, (int) biClrUsed, mapentrysize); @@ -442,9 +423,8 @@ start_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo) } /* Allocate one-row buffer for returned data */ - source->pub.buffer = (*cinfo->mem->alloc_sarray) - ((j_common_ptr) cinfo, JPOOL_IMAGE, - (JDIMENSION) (biWidth * 3), (JDIMENSION) 1); + source->pub.buffer = (*cinfo->mem->alloc_sarray) ((j_common_ptr) cinfo, + JPOOL_IMAGE, (JDIMENSION) (biWidth * 3), (JDIMENSION) 1); source->pub.buffer_height = 1; cinfo->in_color_space = JCS_RGB; @@ -476,9 +456,8 @@ jinit_read_bmp (j_compress_ptr cinfo) bmp_source_ptr source; /* Create module interface object */ - source = (bmp_source_ptr) - (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, - SIZEOF(bmp_source_struct)); + source = (bmp_source_ptr) (*cinfo->mem->alloc_small) + ((j_common_ptr) cinfo, JPOOL_IMAGE, SIZEOF(bmp_source_struct)); source->cinfo = cinfo; /* make back link for subroutines */ /* Fill in method ptrs, except get_pixel_rows which start_input sets */ source->pub.start_input = start_input_bmp; |