In libjpeg-turbo 2.1.x and prior, the WITH_12BIT CMake variable was used to enable 12-bit JPEG support at compile time, because the libjpeg API library could not handle multiple JPEG data precisions at run time. The initial approach to handling multiple JPEG data precisions at run time (7fec5074f9) created a whole new API, library, and applications for 12-bit data precision, so it made sense to repurpose WITH_12BIT to allow 12-bit data precision to be disabled.e8b40f3c2bmade it so that the libjpeg API library can handle multiple JPEG data precisions at run time via a handful of straightforward API extensions. Referring to6c2bc901e2, it hasn't been possible to build libjpeg-turbo with both forward and backward libjpeg API/ABI compatibility since libjpeg-turbo 1.4.x. Thus, whereas we retain full backward API/ABI compatibility with libjpeg v6b-v8, forward libjpeg API/ABI compatibility ceased being realistic years ago, so it no longer makes sense to provide compile-time options that give a false sense of forward API/ABI compatibility by allowing some (but not all) of our libjpeg API extensions to be disabled. Such options are difficult to maintain and clutter the code with #ifdefs.
170 lines
6.2 KiB
C
170 lines
6.2 KiB
C
/*
|
|
* cdjpeg.h
|
|
*
|
|
* This file was part of the Independent JPEG Group's software:
|
|
* Copyright (C) 1994-1997, Thomas G. Lane.
|
|
* Modified 2019 by Guido Vollbeding.
|
|
* libjpeg-turbo Modifications:
|
|
* Copyright (C) 2017, 2019, 2021-2022, D. R. Commander.
|
|
* For conditions of distribution and use, see the accompanying README.ijg
|
|
* file.
|
|
*
|
|
* This file contains common declarations for the sample applications
|
|
* cjpeg and djpeg. It is NOT used by the core JPEG library.
|
|
*/
|
|
|
|
#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
|
|
#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
|
|
#include "jinclude.h"
|
|
#include "jpeglib.h"
|
|
#include "jerror.h" /* get library error codes too */
|
|
#include "cderror.h" /* get application-specific error codes */
|
|
|
|
|
|
/*
|
|
* Object interface for cjpeg's source file decoding modules
|
|
*/
|
|
|
|
typedef struct cjpeg_source_struct *cjpeg_source_ptr;
|
|
|
|
struct cjpeg_source_struct {
|
|
void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
|
|
JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
|
|
void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
|
|
|
|
FILE *input_file;
|
|
|
|
JSAMPARRAY buffer;
|
|
J12SAMPARRAY buffer12;
|
|
JDIMENSION buffer_height;
|
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
|
JDIMENSION max_pixels;
|
|
#endif
|
|
};
|
|
|
|
|
|
/*
|
|
* Object interface for djpeg's output file encoding modules
|
|
*/
|
|
|
|
typedef struct djpeg_dest_struct *djpeg_dest_ptr;
|
|
|
|
struct djpeg_dest_struct {
|
|
/* start_output is called after jpeg_start_decompress finishes.
|
|
* The color map will be ready at this time, if one is needed.
|
|
*/
|
|
void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
|
|
/* Emit the specified number of pixel rows from the buffer. */
|
|
void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
|
|
JDIMENSION rows_supplied);
|
|
/* Finish up at the end of the image. */
|
|
void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
|
|
/* Re-calculate buffer dimensions based on output dimensions (for use with
|
|
partial image decompression.) If this is NULL, then the output format
|
|
does not support partial image decompression (BMP, in particular, cannot
|
|
support partial decompression because it uses an inversion buffer to write
|
|
the image in bottom-up order.) */
|
|
void (*calc_buffer_dimensions) (j_decompress_ptr cinfo,
|
|
djpeg_dest_ptr dinfo);
|
|
|
|
|
|
/* Target file spec; filled in by djpeg.c after object is created. */
|
|
FILE *output_file;
|
|
|
|
/* Output pixel-row buffer. Created by module init or start_output.
|
|
* Width is cinfo->output_width * cinfo->output_components;
|
|
* height is buffer_height.
|
|
*/
|
|
JSAMPARRAY buffer;
|
|
J12SAMPARRAY buffer12;
|
|
JDIMENSION buffer_height;
|
|
};
|
|
|
|
|
|
/*
|
|
* cjpeg/djpeg may need to perform extra passes to convert to or from
|
|
* the source/destination file format. The JPEG library does not know
|
|
* about these passes, but we'd like them to be counted by the progress
|
|
* monitor. We use an expanded progress monitor object to hold the
|
|
* additional pass count.
|
|
*/
|
|
|
|
struct cdjpeg_progress_mgr {
|
|
struct jpeg_progress_mgr pub; /* fields known to JPEG library */
|
|
int completed_extra_passes; /* extra passes completed */
|
|
int total_extra_passes; /* total extra */
|
|
JDIMENSION max_scans; /* abort if the number of scans exceeds this
|
|
value and the value is non-zero */
|
|
boolean report; /* whether or not to report progress */
|
|
/* last printed percentage stored here to avoid multiple printouts */
|
|
int percent_done;
|
|
};
|
|
|
|
typedef struct cdjpeg_progress_mgr *cd_progress_ptr;
|
|
|
|
|
|
/* Module selection routines for I/O modules. */
|
|
|
|
EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
|
|
boolean use_inversion_array);
|
|
EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
|
|
boolean use_inversion_array);
|
|
EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
|
|
EXTERN(cjpeg_source_ptr) j12init_read_gif(j_compress_ptr cinfo);
|
|
EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw);
|
|
EXTERN(djpeg_dest_ptr) j12init_write_gif(j_decompress_ptr cinfo,
|
|
boolean is_lzw);
|
|
EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
|
|
EXTERN(cjpeg_source_ptr) j12init_read_ppm(j_compress_ptr cinfo);
|
|
EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
|
|
EXTERN(djpeg_dest_ptr) j12init_write_ppm(j_decompress_ptr cinfo);
|
|
EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
|
|
EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
|
|
|
|
/* cjpeg support routines (in rdswitch.c) */
|
|
|
|
EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
|
|
boolean force_baseline);
|
|
EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
|
|
EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
|
|
boolean force_baseline);
|
|
EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
|
|
EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
|
|
|
|
/* djpeg support routines (in rdcolmap.c) */
|
|
|
|
EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
|
|
EXTERN(void) read_color_map_12(j_decompress_ptr cinfo, FILE *infile);
|
|
|
|
/* common support routines (in cdjpeg.c) */
|
|
|
|
EXTERN(void) start_progress_monitor(j_common_ptr cinfo,
|
|
cd_progress_ptr progress);
|
|
EXTERN(void) end_progress_monitor(j_common_ptr cinfo);
|
|
EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars);
|
|
EXTERN(FILE *) read_stdin(void);
|
|
EXTERN(FILE *) write_stdout(void);
|
|
|
|
/* miscellaneous useful macros */
|
|
|
|
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
|
|
#define READ_BINARY "r"
|
|
#define WRITE_BINARY "w"
|
|
#else
|
|
#define READ_BINARY "rb"
|
|
#define WRITE_BINARY "wb"
|
|
#endif
|
|
|
|
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
|
|
#define EXIT_FAILURE 1
|
|
#endif
|
|
#ifndef EXIT_SUCCESS
|
|
#define EXIT_SUCCESS 0
|
|
#endif
|
|
#ifndef EXIT_WARNING
|
|
#define EXIT_WARNING 2
|
|
#endif
|
|
|
|
#define IsExtRGB(cs) \
|
|
(cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB))
|