(ChangeLog update forthcoming)
- Prefix all function names with "tj3" and remove version suffixes from
function names. (Future API overhauls will increment the prefix to
"tj4", etc., thus retaining backward API/ABI compatibility without
versioning each individual function.)
- Replace stateless boolean flags (including TJ*FLAG_ARITHMETIC and
TJ*FLAG_LOSSLESS, which were never released) with stateful integer
parameters, the value of which persists between function calls.
* Use parameters for the JPEG quality and subsampling as well, in
order to eliminate the awkwardness of specifying function arguments
that weren't relevant for lossless compression.
* tj3DecompressHeader() now stores all relevant information about the
JPEG image, including the width, height, subsampling type, entropy
coding type, etc. in parameters rather than returning that
information in its arguments.
* TJ*FLAG_LIMITSCANS has been reimplemented as an integer parameter
(TJ*PARAM_SCANLIMIT) that allows the number of scans to be
specified.
- Use the const keyword for all pointer arguments to unmodified
buffers, as well as for both dimensions of 2D pointers. Addresses
#395.
- Use size_t rather than unsigned long to represent buffer sizes, since
unsigned long is a 32-bit type on Windows. Addresses #24.
- Return 0 from all buffer size functions if an error occurs, rather
than awkwardly trying to return -1 in an unsigned data type.
- Implement 12-bit and 16-bit data precision using dedicated
compression, decompression, and image I/O functions/methods.
* Suffix the names of all data-precision-specific functions with 8,
12, or 16.
* Because the YUV functions are intended to be used for video, they
are currently only implemented with 8-bit data precision, but they
can be expanded to 12-bit data precision in the future, if
necessary.
* Extend TJUnitTest and TJBench to test 12-bit and 16-bit data
precision, using a new -precision option.
* Add appropriate regression tests for all of the above to the 'test'
target.
* Extend tjbenchtest to test 12-bit and 16-bit data precision, and
add separate 'tjtest12' and 'tjtest16' targets.
* BufferedImage I/O in the Java API is currently limited to 8-bit
data precision, since the BufferedImage class does not
straightforwardly support higher data precisions.
* Extend the PPM reader to convert 12-bit and 16-bit PBMPLUS files
to grayscale or CMYK pixels, as it already does for 8-bit files.
- Properly accommodate lossless JPEG using dedicated parameters
(TJ*PARAM_LOSSLESS, TJ*PARAM_LOSSLESSPSV, and TJ*PARAM_LOSSLESSPT),
rather than using a flag and awkwardly repurposing the JPEG quality.
Update TJBench to properly reflect whether a JPEG image is lossless.
- Re-organize the TJBench usage screen.
- Update the Java docs using Java 11, to improve the formatting and
eliminate HTML frames.
- Use the accurate integer DCT algorithm by default for both
compression and decompression, since the "fast" algorithm is a legacy
feature, it does not pass the ISO compliance tests, and it is not
actually faster on modern x86 CPUs.
* Remove the -accuratedct option from TJBench and TJExample.
- Re-implement the 'tjtest' target using a CMake script that enables
the appropriate tests, depending on the data precision and whether or
not the Java API is part of the build.
- Consolidate the C and Java versions of tjbenchtest into one script.
- Consolidate the C and Java versions of tjexampletest into one script.
- Combine all initialization functions into a single function
(tj3Init()) that accepts an integer parameter specifying the
subsystems to initialize.
- Enable decompression scaling explicitly, using a new function/method
(tj3SetScalingFactor()/TJDecompressor.setScalingFactor()), rather
than implicitly using awkward "desired width"/"desired height"
parameters.
- Introduce a new macro/constant (TJUNSCALED/TJ.UNSCALED) that maps to
a scaling factor of 1/1.
- Implement partial image decompression, using a new function/method
(tj3SetCroppingRegion()/TJDecompressor.setCroppingRegion()) and
TJBench option (-crop). Extend tjbenchtest to test the new feature.
Addresses #1.
- Allow the JPEG colorspace to be specified explicitly when
compressing, using a new parameter (TJ*PARAM_COLORSPACE). This
allows JPEG images with the RGB and CMYK colorspaces to be created.
- Remove the error/difference image feature from TJBench. Identical
images to the ones that TJBench created can be generated using
ImageMagick with
'magick composite <original_image> <output_image> -compose difference <diff_image>'
- Handle JPEG images with unknown subsampling types. TJ*PARAM_SUBSAMP
is set to TJ*SAMP_UNKNOWN (== -1) for such images, but they can still
be decompressed fully into packed-pixel images or losslessly
transformed (with the exception of lossless cropping.) They cannot
be partially decompressed or decompressed into planar YUV images.
Note also that TJBench, due to its lack of support for imperfect
transforms, requires that the subsampling type be known when
rotating, flipping, or transversely transposing an image. Addresses
#436
- The Java version of TJBench now has identical functionality to the C
version. This was accomplished by (somewhat hackishly) calling the
TurboJPEG C image I/O functions through JNI and copying the pixels
between the C heap and the Java heap.
- Add parameters (TJ*PARAM_RESTARTROWS and TJ*PARAM_RESTARTBLOCKS) and
a TJBench option (-restart) to allow the restart marker interval to
be specified when compressing. Eliminate the undocumented TJ_RESTART
environment variable.
- Add a parameter (TJ*PARAM_OPTIMIZE), a transform option
(TJ*OPT_OPTIMIZE), and a TJBench option (-optimize) to allow
optimized baseline Huffman coding to be specified when compressing.
Eliminate the undocumented TJ_OPTIMIZE environment variable.
- Add parameters (TJ*PARAM_XDENSITY, TJ*PARAM_DENSITY, and
TJ*DENSITYUNITS) to allow the pixel density to be specified when
compressing or saving a Windows BMP image and to be queried when
decompressing or loading a Windows BMP image. Addresses #77.
- Refactor the fuzz targets to use the new API.
* Extend decompression coverage to 12-bit and 16-bit data precision.
* Replace the awkward cjpeg12 and cjpeg16 targets with proper
TurboJPEG-based compress12, compress12-lossless, and
compress16-lossless targets
- Fix innocuous UBSan warnings uncovered by the new fuzzers.
- Implement previous versions of the TurboJPEG API by wrapping the new
functions (tested by running the 2.1.x versions of TJBench, via
tjbenchtest, and TJUnitTest against the new implementation.)
* Remove all JNI functions for deprecated Java methods and implement
the deprecated methods using pure Java wrappers. It should be
understood that backward API compatibility in Java applies only to
the Java classes and that one cannot mix and match a JAR file from
one version of libjpeg-turbo with a JNI library from another
version.
- tj3Destroy() now silently accepts a NULL handle.
- tj3Alloc() and tj3Free() now return/accept void pointers, as malloc()
and free() do.
- The image I/O functions now accept a TurboJPEG instance handle, which
is used to transmit/receive parameters and to receive error
information.
Closes #517
895 lines
29 KiB
C
895 lines
29 KiB
C
/*
|
|
* rdppm.c
|
|
*
|
|
* This file was part of the Independent JPEG Group's software:
|
|
* Copyright (C) 1991-1997, Thomas G. Lane.
|
|
* Modified 2009 by Bill Allombert, Guido Vollbeding.
|
|
* libjpeg-turbo Modifications:
|
|
* Copyright (C) 2015-2017, 2020-2023, D. R. Commander.
|
|
* For conditions of distribution and use, see the accompanying README.ijg
|
|
* file.
|
|
*
|
|
* This file contains routines to read input images in PPM/PGM format.
|
|
* The extended 2-byte-per-sample raw PPM/PGM formats are supported.
|
|
* The PBMPLUS library is NOT required to compile this software
|
|
* (but it is highly useful as a set of PPM image manipulation programs).
|
|
*
|
|
* These routines may need modification for non-Unix environments or
|
|
* specialized applications. As they stand, they assume input from
|
|
* an ordinary stdio stream. They further assume that reading begins
|
|
* at the start of the file; start_input may need work if the
|
|
* user interface has already read some data (e.g., to determine that
|
|
* the file is indeed PPM format).
|
|
*/
|
|
|
|
#include "cmyk.h"
|
|
#include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */
|
|
|
|
#if defined(PPM_SUPPORTED) && \
|
|
(BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED))
|
|
|
|
|
|
/* Portions of this code are based on the PBMPLUS library, which is:
|
|
**
|
|
** Copyright (C) 1988 by Jef Poskanzer.
|
|
**
|
|
** Permission to use, copy, modify, and distribute this software and its
|
|
** documentation for any purpose and without fee is hereby granted, provided
|
|
** that the above copyright notice appear in all copies and that both that
|
|
** copyright notice and this permission notice appear in supporting
|
|
** documentation. This software is provided "as is" without express or
|
|
** implied warranty.
|
|
*/
|
|
|
|
|
|
/* Macros to deal with unsigned chars as efficiently as compiler allows */
|
|
|
|
typedef unsigned char U_CHAR;
|
|
#define UCH(x) ((int)(x))
|
|
|
|
|
|
#define ReadOK(file, buffer, len) \
|
|
(fread(buffer, 1, len, file) == ((size_t)(len)))
|
|
|
|
static int alpha_index[JPEG_NUMCS] = {
|
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
|
|
};
|
|
|
|
|
|
/* Private version of data source object */
|
|
|
|
typedef struct {
|
|
struct cjpeg_source_struct pub; /* public fields */
|
|
|
|
/* Usually these two pointers point to the same place: */
|
|
U_CHAR *iobuffer; /* fread's I/O buffer */
|
|
_JSAMPROW pixrow; /* compressor input buffer */
|
|
size_t buffer_width; /* width of I/O buffer */
|
|
_JSAMPLE *rescale; /* => maxval-remapping array, or NULL */
|
|
unsigned int maxval;
|
|
} ppm_source_struct;
|
|
|
|
typedef ppm_source_struct *ppm_source_ptr;
|
|
|
|
|
|
LOCAL(int)
|
|
pbm_getc(FILE *infile)
|
|
/* Read next char, skipping over any comments */
|
|
/* A comment/newline sequence is returned as a newline */
|
|
{
|
|
register int ch;
|
|
|
|
ch = getc(infile);
|
|
if (ch == '#') {
|
|
do {
|
|
ch = getc(infile);
|
|
} while (ch != '\n' && ch != EOF);
|
|
}
|
|
return ch;
|
|
}
|
|
|
|
|
|
LOCAL(unsigned int)
|
|
read_pbm_integer(j_compress_ptr cinfo, FILE *infile, unsigned int maxval)
|
|
/* Read an unsigned decimal integer from the PPM file */
|
|
/* Swallows one trailing character after the integer */
|
|
/* Note that on a 16-bit-int machine, only values up to 64k can be read. */
|
|
/* This should not be a problem in practice. */
|
|
{
|
|
register int ch;
|
|
register unsigned int val;
|
|
|
|
/* Skip any leading whitespace */
|
|
do {
|
|
ch = pbm_getc(infile);
|
|
if (ch == EOF)
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
} while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
|
|
|
|
if (ch < '0' || ch > '9')
|
|
ERREXIT(cinfo, JERR_PPM_NONNUMERIC);
|
|
|
|
val = ch - '0';
|
|
while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
|
|
val *= 10;
|
|
val += ch - '0';
|
|
if (val > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
}
|
|
|
|
return val;
|
|
}
|
|
|
|
|
|
/*
|
|
* Read one row of pixels.
|
|
*
|
|
* We provide several different versions depending on input file format.
|
|
* In all cases, input is scaled to the size of _JSAMPLE.
|
|
*
|
|
* A really fast path is provided for reading byte/sample raw files with
|
|
* maxval = _MAXJSAMPLE, which is the normal case for 8-bit data.
|
|
*/
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_text_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading text-format PGM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
FILE *infile = source->pub.input_file;
|
|
register _JSAMPROW ptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
ptr = source->pub._buffer[0];
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
*ptr++ = rescale[read_pbm_integer(cinfo, infile, maxval)];
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
#define GRAY_RGB_READ_LOOP(read_op, alpha_set_op) { \
|
|
for (col = cinfo->image_width; col > 0; col--) { \
|
|
ptr[rindex] = ptr[gindex] = ptr[bindex] = read_op; \
|
|
alpha_set_op \
|
|
ptr += ps; \
|
|
} \
|
|
}
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_text_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading text-format PGM files with any maxval and
|
|
converting to extended RGB */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
FILE *infile = source->pub.input_file;
|
|
register _JSAMPROW ptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
register int rindex = rgb_red[cinfo->in_color_space];
|
|
register int gindex = rgb_green[cinfo->in_color_space];
|
|
register int bindex = rgb_blue[cinfo->in_color_space];
|
|
register int aindex = alpha_index[cinfo->in_color_space];
|
|
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
|
|
|
ptr = source->pub._buffer[0];
|
|
if (maxval == _MAXJSAMPLE) {
|
|
if (aindex >= 0)
|
|
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
|
|
ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
GRAY_RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
|
|
} else {
|
|
if (aindex >= 0)
|
|
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
|
|
ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
GRAY_RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_text_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading text-format PGM files with any maxval and
|
|
converting to CMYK */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
FILE *infile = source->pub.input_file;
|
|
register _JSAMPROW ptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
ptr = source->pub._buffer[0];
|
|
if (maxval == _MAXJSAMPLE) {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE gray = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
|
|
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
} else {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE gray = rescale[read_pbm_integer(cinfo, infile, maxval)];
|
|
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
#define RGB_READ_LOOP(read_op, alpha_set_op) { \
|
|
for (col = cinfo->image_width; col > 0; col--) { \
|
|
ptr[rindex] = read_op; \
|
|
ptr[gindex] = read_op; \
|
|
ptr[bindex] = read_op; \
|
|
alpha_set_op \
|
|
ptr += ps; \
|
|
} \
|
|
}
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_text_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading text-format PPM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
FILE *infile = source->pub.input_file;
|
|
register _JSAMPROW ptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
register int rindex = rgb_red[cinfo->in_color_space];
|
|
register int gindex = rgb_green[cinfo->in_color_space];
|
|
register int bindex = rgb_blue[cinfo->in_color_space];
|
|
register int aindex = alpha_index[cinfo->in_color_space];
|
|
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
|
|
|
ptr = source->pub._buffer[0];
|
|
if (maxval == _MAXJSAMPLE) {
|
|
if (aindex >= 0)
|
|
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval),
|
|
ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
RGB_READ_LOOP((_JSAMPLE)read_pbm_integer(cinfo, infile, maxval), {})
|
|
} else {
|
|
if (aindex >= 0)
|
|
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)],
|
|
ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
RGB_READ_LOOP(rescale[read_pbm_integer(cinfo, infile, maxval)], {})
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_text_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading text-format PPM files with any maxval and
|
|
converting to CMYK */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
FILE *infile = source->pub.input_file;
|
|
register _JSAMPROW ptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
ptr = source->pub._buffer[0];
|
|
if (maxval == _MAXJSAMPLE) {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE r = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
|
|
_JSAMPLE g = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
|
|
_JSAMPLE b = (_JSAMPLE)read_pbm_integer(cinfo, infile, maxval);
|
|
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
} else {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE r = rescale[read_pbm_integer(cinfo, infile, maxval)];
|
|
_JSAMPLE g = rescale[read_pbm_integer(cinfo, infile, maxval)];
|
|
_JSAMPLE b = rescale[read_pbm_integer(cinfo, infile, maxval)];
|
|
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_scaled_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-byte-format PGM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
*ptr++ = rescale[UCH(*bufferptr++)];
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-byte-format PGM files with any maxval
|
|
and converting to extended RGB */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
register int rindex = rgb_red[cinfo->in_color_space];
|
|
register int gindex = rgb_green[cinfo->in_color_space];
|
|
register int bindex = rgb_blue[cinfo->in_color_space];
|
|
register int aindex = alpha_index[cinfo->in_color_space];
|
|
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
if (maxval == _MAXJSAMPLE) {
|
|
if (aindex >= 0)
|
|
GRAY_RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
GRAY_RGB_READ_LOOP(*bufferptr++, {})
|
|
} else {
|
|
if (aindex >= 0)
|
|
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)],
|
|
ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
GRAY_RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-byte-format PGM files with any maxval
|
|
and converting to CMYK */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
if (maxval == _MAXJSAMPLE) {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE gray = *bufferptr++;
|
|
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
} else {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE gray = rescale[UCH(*bufferptr++)];
|
|
rgb_to_cmyk(gray, gray, gray, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-byte-format PPM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
register int rindex = rgb_red[cinfo->in_color_space];
|
|
register int gindex = rgb_green[cinfo->in_color_space];
|
|
register int bindex = rgb_blue[cinfo->in_color_space];
|
|
register int aindex = alpha_index[cinfo->in_color_space];
|
|
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
if (maxval == _MAXJSAMPLE) {
|
|
if (aindex >= 0)
|
|
RGB_READ_LOOP(*bufferptr++, ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
RGB_READ_LOOP(*bufferptr++, {})
|
|
} else {
|
|
if (aindex >= 0)
|
|
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], ptr[aindex] = _MAXJSAMPLE;)
|
|
else
|
|
RGB_READ_LOOP(rescale[UCH(*bufferptr++)], {})
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-byte-format PPM files with any maxval and
|
|
converting to CMYK */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
if (maxval == _MAXJSAMPLE) {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE r = *bufferptr++;
|
|
_JSAMPLE g = *bufferptr++;
|
|
_JSAMPLE b = *bufferptr++;
|
|
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
} else {
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
_JSAMPLE r = rescale[UCH(*bufferptr++)];
|
|
_JSAMPLE g = rescale[UCH(*bufferptr++)];
|
|
_JSAMPLE b = rescale[UCH(*bufferptr++)];
|
|
rgb_to_cmyk(r, g, b, ptr, ptr + 1, ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_raw_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-byte-format files with maxval = _MAXJSAMPLE.
|
|
* In this case we just read right into the _JSAMPLE buffer!
|
|
* Note that same code works for PPM and PGM files.
|
|
*/
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_word_gray_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-word-format PGM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
register unsigned int temp;
|
|
temp = UCH(*bufferptr++) << 8;
|
|
temp |= UCH(*bufferptr++);
|
|
if (temp > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
*ptr++ = rescale[temp];
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_word_gray_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-word-format PGM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
register int rindex = rgb_red[cinfo->in_color_space];
|
|
register int gindex = rgb_green[cinfo->in_color_space];
|
|
register int bindex = rgb_blue[cinfo->in_color_space];
|
|
register int aindex = alpha_index[cinfo->in_color_space];
|
|
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
register unsigned int temp;
|
|
temp = UCH(*bufferptr++) << 8;
|
|
temp |= UCH(*bufferptr++);
|
|
if (temp > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
ptr[rindex] = ptr[gindex] = ptr[bindex] = rescale[temp];
|
|
if (aindex >= 0)
|
|
ptr[aindex] = _MAXJSAMPLE;
|
|
ptr += ps;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_word_gray_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-word-format PGM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
register unsigned int gray;
|
|
gray = UCH(*bufferptr++) << 8;
|
|
gray |= UCH(*bufferptr++);
|
|
if (gray > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
rgb_to_cmyk(rescale[gray], rescale[gray], rescale[gray], ptr, ptr + 1,
|
|
ptr + 2, ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_word_rgb_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-word-format PPM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
register int rindex = rgb_red[cinfo->in_color_space];
|
|
register int gindex = rgb_green[cinfo->in_color_space];
|
|
register int bindex = rgb_blue[cinfo->in_color_space];
|
|
register int aindex = alpha_index[cinfo->in_color_space];
|
|
register int ps = rgb_pixelsize[cinfo->in_color_space];
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
register unsigned int temp;
|
|
temp = UCH(*bufferptr++) << 8;
|
|
temp |= UCH(*bufferptr++);
|
|
if (temp > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
ptr[rindex] = rescale[temp];
|
|
temp = UCH(*bufferptr++) << 8;
|
|
temp |= UCH(*bufferptr++);
|
|
if (temp > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
ptr[gindex] = rescale[temp];
|
|
temp = UCH(*bufferptr++) << 8;
|
|
temp |= UCH(*bufferptr++);
|
|
if (temp > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
ptr[bindex] = rescale[temp];
|
|
if (aindex >= 0)
|
|
ptr[aindex] = _MAXJSAMPLE;
|
|
ptr += ps;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
METHODDEF(JDIMENSION)
|
|
get_word_rgb_cmyk_row(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
/* This version is for reading raw-word-format PPM files with any maxval */
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
register _JSAMPROW ptr;
|
|
register U_CHAR *bufferptr;
|
|
register _JSAMPLE *rescale = source->rescale;
|
|
JDIMENSION col;
|
|
unsigned int maxval = source->maxval;
|
|
|
|
if (!ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))
|
|
ERREXIT(cinfo, JERR_INPUT_EOF);
|
|
ptr = source->pub._buffer[0];
|
|
bufferptr = source->iobuffer;
|
|
for (col = cinfo->image_width; col > 0; col--) {
|
|
register unsigned int r, g, b;
|
|
r = UCH(*bufferptr++) << 8;
|
|
r |= UCH(*bufferptr++);
|
|
if (r > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
g = UCH(*bufferptr++) << 8;
|
|
g |= UCH(*bufferptr++);
|
|
if (g > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
b = UCH(*bufferptr++) << 8;
|
|
b |= UCH(*bufferptr++);
|
|
if (b > maxval)
|
|
ERREXIT(cinfo, JERR_PPM_OUTOFRANGE);
|
|
rgb_to_cmyk(rescale[r], rescale[g], rescale[b], ptr, ptr + 1, ptr + 2,
|
|
ptr + 3);
|
|
ptr += 4;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
|
|
/*
|
|
* Read the file header; return image size and component count.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
start_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
{
|
|
ppm_source_ptr source = (ppm_source_ptr)sinfo;
|
|
int c;
|
|
unsigned int w, h, maxval;
|
|
boolean need_iobuffer, use_raw_buffer, need_rescale;
|
|
|
|
if (getc(source->pub.input_file) != 'P')
|
|
ERREXIT(cinfo, JERR_PPM_NOT);
|
|
|
|
c = getc(source->pub.input_file); /* subformat discriminator character */
|
|
|
|
/* detect unsupported variants (ie, PBM) before trying to read header */
|
|
switch (c) {
|
|
case '2': /* it's a text-format PGM file */
|
|
case '3': /* it's a text-format PPM file */
|
|
case '5': /* it's a raw-format PGM file */
|
|
case '6': /* it's a raw-format PPM file */
|
|
break;
|
|
default:
|
|
ERREXIT(cinfo, JERR_PPM_NOT);
|
|
break;
|
|
}
|
|
|
|
/* fetch the remaining header info */
|
|
w = read_pbm_integer(cinfo, source->pub.input_file, 65535);
|
|
h = read_pbm_integer(cinfo, source->pub.input_file, 65535);
|
|
maxval = read_pbm_integer(cinfo, source->pub.input_file, 65535);
|
|
|
|
if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
|
|
ERREXIT(cinfo, JERR_PPM_NOT);
|
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
|
if (sinfo->max_pixels && (unsigned long long)w * h > sinfo->max_pixels)
|
|
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
|
|
#endif
|
|
|
|
cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */
|
|
cinfo->image_width = (JDIMENSION)w;
|
|
cinfo->image_height = (JDIMENSION)h;
|
|
source->maxval = maxval;
|
|
|
|
/* initialize flags to most common settings */
|
|
need_iobuffer = TRUE; /* do we need an I/O buffer? */
|
|
use_raw_buffer = FALSE; /* do we map input buffer onto I/O buffer? */
|
|
need_rescale = TRUE; /* do we need a rescale array? */
|
|
|
|
switch (c) {
|
|
case '2': /* it's a text-format PGM file */
|
|
if (cinfo->in_color_space == JCS_UNKNOWN ||
|
|
cinfo->in_color_space == JCS_RGB)
|
|
cinfo->in_color_space = JCS_GRAYSCALE;
|
|
TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);
|
|
if (cinfo->in_color_space == JCS_GRAYSCALE)
|
|
source->pub.get_pixel_rows = get_text_gray_row;
|
|
else if (IsExtRGB(cinfo->in_color_space))
|
|
source->pub.get_pixel_rows = get_text_gray_rgb_row;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
source->pub.get_pixel_rows = get_text_gray_cmyk_row;
|
|
else
|
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
|
need_iobuffer = FALSE;
|
|
break;
|
|
|
|
case '3': /* it's a text-format PPM file */
|
|
if (cinfo->in_color_space == JCS_UNKNOWN)
|
|
cinfo->in_color_space = JCS_EXT_RGB;
|
|
TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);
|
|
if (IsExtRGB(cinfo->in_color_space))
|
|
source->pub.get_pixel_rows = get_text_rgb_row;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
source->pub.get_pixel_rows = get_text_rgb_cmyk_row;
|
|
else
|
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
|
need_iobuffer = FALSE;
|
|
break;
|
|
|
|
case '5': /* it's a raw-format PGM file */
|
|
if (cinfo->in_color_space == JCS_UNKNOWN ||
|
|
cinfo->in_color_space == JCS_RGB)
|
|
cinfo->in_color_space = JCS_GRAYSCALE;
|
|
TRACEMS2(cinfo, 1, JTRC_PGM, w, h);
|
|
if (maxval > 255) {
|
|
if (cinfo->in_color_space == JCS_GRAYSCALE)
|
|
source->pub.get_pixel_rows = get_word_gray_row;
|
|
else if (IsExtRGB(cinfo->in_color_space))
|
|
source->pub.get_pixel_rows = get_word_gray_rgb_row;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
source->pub.get_pixel_rows = get_word_gray_cmyk_row;
|
|
else
|
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
|
} else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
|
|
cinfo->in_color_space == JCS_GRAYSCALE) {
|
|
source->pub.get_pixel_rows = get_raw_row;
|
|
use_raw_buffer = TRUE;
|
|
need_rescale = FALSE;
|
|
} else {
|
|
if (cinfo->in_color_space == JCS_GRAYSCALE)
|
|
source->pub.get_pixel_rows = get_scaled_gray_row;
|
|
else if (IsExtRGB(cinfo->in_color_space))
|
|
source->pub.get_pixel_rows = get_gray_rgb_row;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
source->pub.get_pixel_rows = get_gray_cmyk_row;
|
|
else
|
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
|
}
|
|
break;
|
|
|
|
case '6': /* it's a raw-format PPM file */
|
|
if (cinfo->in_color_space == JCS_UNKNOWN)
|
|
cinfo->in_color_space = JCS_EXT_RGB;
|
|
TRACEMS2(cinfo, 1, JTRC_PPM, w, h);
|
|
if (maxval > 255) {
|
|
if (IsExtRGB(cinfo->in_color_space))
|
|
source->pub.get_pixel_rows = get_word_rgb_row;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
source->pub.get_pixel_rows = get_word_rgb_cmyk_row;
|
|
else
|
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
|
} else if (maxval == _MAXJSAMPLE && sizeof(_JSAMPLE) == sizeof(U_CHAR) &&
|
|
#if RGB_RED == 0 && RGB_GREEN == 1 && RGB_BLUE == 2 && RGB_PIXELSIZE == 3
|
|
(cinfo->in_color_space == JCS_EXT_RGB ||
|
|
cinfo->in_color_space == JCS_RGB)) {
|
|
#else
|
|
cinfo->in_color_space == JCS_EXT_RGB) {
|
|
#endif
|
|
source->pub.get_pixel_rows = get_raw_row;
|
|
use_raw_buffer = TRUE;
|
|
need_rescale = FALSE;
|
|
} else {
|
|
if (IsExtRGB(cinfo->in_color_space))
|
|
source->pub.get_pixel_rows = get_rgb_row;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
source->pub.get_pixel_rows = get_rgb_cmyk_row;
|
|
else
|
|
ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (IsExtRGB(cinfo->in_color_space))
|
|
cinfo->input_components = rgb_pixelsize[cinfo->in_color_space];
|
|
else if (cinfo->in_color_space == JCS_GRAYSCALE)
|
|
cinfo->input_components = 1;
|
|
else if (cinfo->in_color_space == JCS_CMYK)
|
|
cinfo->input_components = 4;
|
|
|
|
/* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */
|
|
if (need_iobuffer) {
|
|
if (c == '6')
|
|
source->buffer_width = (size_t)w * 3 *
|
|
((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
|
|
else
|
|
source->buffer_width = (size_t)w *
|
|
((maxval <= 255) ? sizeof(U_CHAR) : (2 * sizeof(U_CHAR)));
|
|
source->iobuffer = (U_CHAR *)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
source->buffer_width);
|
|
}
|
|
|
|
/* Create compressor input buffer. */
|
|
if (use_raw_buffer) {
|
|
/* For unscaled raw-input case, we can just map it onto the I/O buffer. */
|
|
/* Synthesize a _JSAMPARRAY pointer structure */
|
|
source->pixrow = (_JSAMPROW)source->iobuffer;
|
|
source->pub._buffer = &source->pixrow;
|
|
source->pub.buffer_height = 1;
|
|
} else {
|
|
/* Need to translate anyway, so make a separate sample buffer. */
|
|
source->pub._buffer = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
|
|
((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
(JDIMENSION)w * cinfo->input_components, (JDIMENSION)1);
|
|
source->pub.buffer_height = 1;
|
|
}
|
|
|
|
/* Compute the rescaling array if required. */
|
|
if (need_rescale) {
|
|
long val, half_maxval;
|
|
|
|
/* On 16-bit-int machines we have to be careful of maxval = 65535 */
|
|
source->rescale = (_JSAMPLE *)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
(size_t)(((long)MAX(maxval, 255) + 1L) *
|
|
sizeof(_JSAMPLE)));
|
|
memset(source->rescale, 0, (size_t)(((long)MAX(maxval, 255) + 1L) *
|
|
sizeof(_JSAMPLE)));
|
|
half_maxval = maxval / 2;
|
|
for (val = 0; val <= (long)maxval; val++) {
|
|
/* The multiplication here must be done in 32 bits to avoid overflow */
|
|
source->rescale[val] = (_JSAMPLE)((val * _MAXJSAMPLE + half_maxval) /
|
|
maxval);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
* Finish up at the end of the file.
|
|
*/
|
|
|
|
METHODDEF(void)
|
|
finish_input_ppm(j_compress_ptr cinfo, cjpeg_source_ptr sinfo)
|
|
{
|
|
/* no work */
|
|
}
|
|
|
|
|
|
/*
|
|
* The module selection routine for PPM format input.
|
|
*/
|
|
|
|
GLOBAL(cjpeg_source_ptr)
|
|
_jinit_read_ppm(j_compress_ptr cinfo)
|
|
{
|
|
ppm_source_ptr source;
|
|
|
|
if (cinfo->data_precision != BITS_IN_JSAMPLE)
|
|
ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
|
|
|
|
/* Create module interface object */
|
|
source = (ppm_source_ptr)
|
|
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
|
|
sizeof(ppm_source_struct));
|
|
/* Fill in method ptrs, except get_pixel_rows which start_input sets */
|
|
source->pub.start_input = start_input_ppm;
|
|
source->pub.finish_input = finish_input_ppm;
|
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
|
source->pub.max_pixels = 0;
|
|
#endif
|
|
|
|
return (cjpeg_source_ptr)source;
|
|
}
|
|
|
|
#endif /* defined(PPM_SUPPORTED) &&
|
|
(BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)) */
|