| 6 |
| * libjpeg-turbo Modifications: |
| 7 | * Copyright (C) 2017, D. R. Commander. |
| 8 | * mozjpeg Modifications: |
| 9 | * Copyright (C) 2014, Mozilla Corporation. |
| 10 | * For conditions of distribution and use, see the accompanying README.ijg file. |
| 11 | * |
| 12 | * This file contains common declarations for the sample applications |
| 13 | * cjpeg and djpeg. It is NOT used by the core JPEG library. |
| 14 | */ |
| 15 |
| 16 | #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */ |
| 17 | #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */ |
| 18 | #include "jinclude.h" |
| 19 | #include "jpeglib.h" |
| 20 | #include "jerror.h" /* get library error codes too */ |
| 21 | #include "cderror.h" /* get application-specific error codes */ |
| 22 |
| 23 | #define JPEG_RAW_READER 0 |
| 24 |
| 25 | /* |
| 26 | * Object interface for cjpeg's source file decoding modules |
| 27 | */ |
| 28 |
| 29 | typedef struct cjpeg_source_struct *cjpeg_source_ptr; |
| 30 |
| 31 | struct cjpeg_source_struct { |
| 32 | void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo); |
| 33 | JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo); |
| 34 | void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo); |
| 35 |
| 36 | FILE *input_file; |
| 37 |
| 38 | JSAMPARRAY buffer; |
| 39 | JDIMENSION buffer_height; |
| 40 |
| 41 | #if JPEG_RAW_READER |
| 42 | // For reading JPEG |
| 43 | JSAMPARRAY plane_pointer[4]; |
| 44 | #endif |
| 45 |
| 46 | jpeg_saved_marker_ptr marker_list; |
| 47 | }; |
| 48 |
| 49 |
| 50 | /* |
| 51 | * Object interface for djpeg's output file encoding modules |
| 52 | */ |
| 53 |
| 54 | typedef struct djpeg_dest_struct *djpeg_dest_ptr; |
| 55 |
| 56 | struct djpeg_dest_struct { |
| 57 | /* start_output is called after jpeg_start_decompress finishes. |
| 58 | * The color map will be ready at this time, if one is needed. |
| 59 | */ |
| 60 | void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo); |
| 61 | /* Emit the specified number of pixel rows from the buffer. */ |
| 62 | void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, |
| 63 | JDIMENSION rows_supplied); |
| 64 | /* Finish up at the end of the image. */ |
| 65 | void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo); |
| 66 | /* Re-calculate buffer dimensions based on output dimensions (for use with |
| 67 | partial image decompression.) If this is NULL, then the output format |
| 68 | does not support partial image decompression (BMP and RLE, in particular, |
| 69 | cannot support partial decompression because they use an inversion buffer |
| 70 | to write the image in bottom-up order.) */ |
| 71 | void (*calc_buffer_dimensions) (j_decompress_ptr cinfo, |
| 72 | djpeg_dest_ptr dinfo); |
| 73 |
| 74 |
| 75 | /* Target file spec; filled in by djpeg.c after object is created. */ |
| 76 | FILE *output_file; |
| 77 |
| 78 | /* Output pixel-row buffer. Created by module init or start_output. |
| 79 | * Width is cinfo->output_width * cinfo->output_components; |
| 80 | * height is buffer_height. |
| 81 | */ |
| 82 | JSAMPARRAY buffer; |
| 83 | JDIMENSION buffer_height; |
| 84 | }; |
| 85 |
| 86 |
| 87 | /* |
| 88 | * cjpeg/djpeg may need to perform extra passes to convert to or from |
| 89 | * the source/destination file format. The JPEG library does not know |
| 90 | * about these passes, but we'd like them to be counted by the progress |
| 91 | * monitor. We use an expanded progress monitor object to hold the |
| 92 | * additional pass count. |
| 93 | */ |
| 94 |
| 95 | struct cdjpeg_progress_mgr { |
| 96 | struct jpeg_progress_mgr pub; /* fields known to JPEG library */ |
| 97 | int completed_extra_passes; /* extra passes completed */ |
| 98 | int total_extra_passes; /* total extra */ |
| 99 | /* last printed percentage stored here to avoid multiple printouts */ |
| 100 | int percent_done; |
| 101 | }; |
| 102 |
| 103 | typedef struct cdjpeg_progress_mgr *cd_progress_ptr; |
| 104 |
| 105 |
| 106 | /* Module selection routines for I/O modules. */ |
| 107 |
| 108 | EXTERN(cjpeg_source_ptr) jinit_read_jpeg (j_compress_ptr cinfo); |
| 109 | EXTERN(cjpeg_source_ptr) jinit_read_png (j_compress_ptr cinfo); |
| 110 | EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo, |
| 111 | boolean use_inversion_array); |
| 112 | EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2, |
| 113 | boolean use_inversion_array); |
| 114 | EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo); |
| 115 | EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo); |
| 116 | EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo); |
| 117 | EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo); |
| 118 | EXTERN(cjpeg_source_ptr) jinit_read_rle(j_compress_ptr cinfo); |
| 119 | EXTERN(djpeg_dest_ptr) jinit_write_rle(j_decompress_ptr cinfo); |
| 120 | EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo); |
| 121 | EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo); |
| 122 |
| 123 | /* cjpeg support routines (in rdswitch.c) */ |
| 124 |
| 125 | EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename, |
| 126 | boolean force_baseline); |
| 127 | EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename); |
| 128 | EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg, |
| 129 | boolean force_baseline); |
| 130 | EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg); |
| 131 | EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg); |
| 132 |
| 133 | /* djpeg support routines (in rdcolmap.c) */ |
| 134 |
| 135 | EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile); |
| 136 |
| 137 | /* common support routines (in cdjpeg.c) */ |
| 138 |
| 139 | EXTERN(void) enable_signal_catcher(j_common_ptr cinfo); |
| 140 | EXTERN(void) start_progress_monitor(j_common_ptr cinfo, |
| 141 | cd_progress_ptr progress); |
| 142 | EXTERN(void) end_progress_monitor(j_common_ptr cinfo); |
| 143 | EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars); |
| 144 | EXTERN(FILE *) read_stdin(void); |
| 145 | EXTERN(FILE *) write_stdout(void); |
| 146 |
| 147 | /* miscellaneous useful macros */ |
| 148 |
| 149 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ |
| 150 | #define READ_BINARY "r" |
| 151 | #define WRITE_BINARY "w" |
| 152 | #else |
| 153 | #define READ_BINARY "rb" |
| 154 | #define WRITE_BINARY "wb" |
| 155 | #endif |
| 156 |
| 157 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ |
| 158 | #define EXIT_FAILURE 1 |
| 159 | #endif |
| 160 | #ifndef EXIT_SUCCESS |
| 161 | #define EXIT_SUCCESS 0 |
| 162 | #endif |
| 163 | #ifndef EXIT_WARNING |
| 164 | #define EXIT_WARNING 2 |
| 165 | #endif |
| 166 |
| 167 | #define IsExtRGB(cs) \ |
| 168 | (cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB)) |
| 169 |