blob: 9868a0b308b259c2c34daf710b141577509ae957 [file] [log] [blame]
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00001/*
2 * cdjpeg.h
3 *
DRC5033f3e2014-05-18 18:33:44 +00004 * This file was part of the Independent JPEG Group's software:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00005 * Copyright (C) 1994-1997, Thomas G. Lane.
Leon Scroggins IIIbd7903e2018-02-28 14:05:04 -05006 * libjpeg-turbo Modifications:
7 * Copyright (C) 2017, D. R. Commander.
Alex Naidis6eb7d372016-10-16 23:10:08 +02008 * For conditions of distribution and use, see the accompanying README.ijg
9 * file.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000010 *
11 * This file contains common declarations for the sample applications
12 * cjpeg and djpeg. It is NOT used by the core JPEG library.
13 */
14
DRCe5eaf372014-05-09 18:00:32 +000015#define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
16#define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000017#include "jinclude.h"
18#include "jpeglib.h"
DRCe5eaf372014-05-09 18:00:32 +000019#include "jerror.h" /* get library error codes too */
20#include "cderror.h" /* get application-specific error codes */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000021
22
23/*
24 * Object interface for cjpeg's source file decoding modules
25 */
26
Alex Naidis6eb7d372016-10-16 23:10:08 +020027typedef struct cjpeg_source_struct *cjpeg_source_ptr;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000028
29struct cjpeg_source_struct {
DRCbc56b752014-05-16 10:43:44 +000030 void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
31 JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
32 void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000033
34 FILE *input_file;
35
36 JSAMPARRAY buffer;
37 JDIMENSION buffer_height;
38};
39
40
41/*
42 * Object interface for djpeg's output file encoding modules
43 */
44
Alex Naidis6eb7d372016-10-16 23:10:08 +020045typedef struct djpeg_dest_struct *djpeg_dest_ptr;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000046
47struct djpeg_dest_struct {
48 /* start_output is called after jpeg_start_decompress finishes.
49 * The color map will be ready at this time, if one is needed.
50 */
DRCbc56b752014-05-16 10:43:44 +000051 void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000052 /* Emit the specified number of pixel rows from the buffer. */
DRCbc56b752014-05-16 10:43:44 +000053 void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
54 JDIMENSION rows_supplied);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000055 /* Finish up at the end of the image. */
DRCbc56b752014-05-16 10:43:44 +000056 void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
Leon Scroggins IIIbd7903e2018-02-28 14:05:04 -050057 /* Re-calculate buffer dimensions based on output dimensions (for use with
58 partial image decompression.) If this is NULL, then the output format
59 does not support partial image decompression (BMP and RLE, in particular,
60 cannot support partial decompression because they use an inversion buffer
61 to write the image in bottom-up order.) */
62 void (*calc_buffer_dimensions) (j_decompress_ptr cinfo,
63 djpeg_dest_ptr dinfo);
64
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000065
66 /* Target file spec; filled in by djpeg.c after object is created. */
Alex Naidis6eb7d372016-10-16 23:10:08 +020067 FILE *output_file;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000068
69 /* Output pixel-row buffer. Created by module init or start_output.
70 * Width is cinfo->output_width * cinfo->output_components;
71 * height is buffer_height.
72 */
73 JSAMPARRAY buffer;
74 JDIMENSION buffer_height;
75};
76
77
78/*
79 * cjpeg/djpeg may need to perform extra passes to convert to or from
80 * the source/destination file format. The JPEG library does not know
81 * about these passes, but we'd like them to be counted by the progress
82 * monitor. We use an expanded progress monitor object to hold the
83 * additional pass count.
84 */
85
86struct cdjpeg_progress_mgr {
DRCe5eaf372014-05-09 18:00:32 +000087 struct jpeg_progress_mgr pub; /* fields known to JPEG library */
88 int completed_extra_passes; /* extra passes completed */
89 int total_extra_passes; /* total extra */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000090 /* last printed percentage stored here to avoid multiple printouts */
91 int percent_done;
92};
93
Alex Naidis6eb7d372016-10-16 23:10:08 +020094typedef struct cdjpeg_progress_mgr *cd_progress_ptr;
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000095
96
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000097/* Module selection routines for I/O modules. */
98
Leon Scroggins III3993b372018-07-16 10:43:45 -040099EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
100 boolean use_inversion_array);
101EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
102 boolean use_inversion_array);
103EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
104EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo);
105EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
106EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
107EXTERN(cjpeg_source_ptr) jinit_read_rle(j_compress_ptr cinfo);
108EXTERN(djpeg_dest_ptr) jinit_write_rle(j_decompress_ptr cinfo);
109EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
110EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000111
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000112/* cjpeg support routines (in rdswitch.c) */
113
Leon Scroggins III3993b372018-07-16 10:43:45 -0400114EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
115 boolean force_baseline);
116EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
117EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
118 boolean force_baseline);
119EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
120EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000121
122/* djpeg support routines (in rdcolmap.c) */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000123
Leon Scroggins III3993b372018-07-16 10:43:45 -0400124EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000125
126/* common support routines (in cdjpeg.c) */
127
Leon Scroggins III3993b372018-07-16 10:43:45 -0400128EXTERN(void) enable_signal_catcher(j_common_ptr cinfo);
129EXTERN(void) start_progress_monitor(j_common_ptr cinfo,
130 cd_progress_ptr progress);
131EXTERN(void) end_progress_monitor(j_common_ptr cinfo);
132EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars);
133EXTERN(FILE *) read_stdin(void);
134EXTERN(FILE *) write_stdout(void);
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000135
136/* miscellaneous useful macros */
137
DRCe5eaf372014-05-09 18:00:32 +0000138#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
139#define READ_BINARY "r"
140#define WRITE_BINARY "w"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000141#else
DRCe5eaf372014-05-09 18:00:32 +0000142#define READ_BINARY "rb"
143#define WRITE_BINARY "wb"
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000144#endif
145
DRCe5eaf372014-05-09 18:00:32 +0000146#ifndef EXIT_FAILURE /* define exit() codes if not provided */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000147#define EXIT_FAILURE 1
148#endif
149#ifndef EXIT_SUCCESS
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000150#define EXIT_SUCCESS 0
151#endif
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000152#ifndef EXIT_WARNING
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000153#define EXIT_WARNING 2
154#endif
Leon Scroggins III3993b372018-07-16 10:43:45 -0400155
156#define IsExtRGB(cs) \
157 (cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB))