Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * cdjpeg.h |
| 3 | * |
DRC | 5033f3e | 2014-05-18 18:33:44 +0000 | [diff] [blame] | 4 | * This file was part of the Independent JPEG Group's software: |
Thomas G. Lane | 5ead57a | 1998-03-27 00:00:00 +0000 | [diff] [blame] | 5 | * Copyright (C) 1994-1997, Thomas G. Lane. |
DRC | 5033f3e | 2014-05-18 18:33:44 +0000 | [diff] [blame] | 6 | * It was modified by The libjpeg-turbo Project to include only code relevant |
| 7 | * to libjpeg-turbo. |
DRC | 7e3acc0 | 2015-10-10 10:25:46 -0500 | [diff] [blame] | 8 | * For conditions of distribution and use, see the accompanying README.ijg |
| 9 | * file. |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 10 | * |
| 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 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 15 | #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. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 17 | #include "jinclude.h" |
| 18 | #include "jpeglib.h" |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 19 | #include "jerror.h" /* get library error codes too */ |
| 20 | #include "cderror.h" /* get application-specific error codes */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | /* |
| 24 | * Object interface for cjpeg's source file decoding modules |
| 25 | */ |
| 26 | |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 27 | typedef struct cjpeg_source_struct *cjpeg_source_ptr; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 28 | |
| 29 | struct cjpeg_source_struct { |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 30 | 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. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 33 | |
| 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 | |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 45 | typedef struct djpeg_dest_struct *djpeg_dest_ptr; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 46 | |
| 47 | struct 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 | */ |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 51 | void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 52 | /* Emit the specified number of pixel rows from the buffer. */ |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 53 | void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, |
| 54 | JDIMENSION rows_supplied); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 55 | /* Finish up at the end of the image. */ |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 56 | void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 57 | |
| 58 | /* Target file spec; filled in by djpeg.c after object is created. */ |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 59 | FILE *output_file; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 60 | |
| 61 | /* Output pixel-row buffer. Created by module init or start_output. |
| 62 | * Width is cinfo->output_width * cinfo->output_components; |
| 63 | * height is buffer_height. |
| 64 | */ |
| 65 | JSAMPARRAY buffer; |
| 66 | JDIMENSION buffer_height; |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * cjpeg/djpeg may need to perform extra passes to convert to or from |
| 72 | * the source/destination file format. The JPEG library does not know |
| 73 | * about these passes, but we'd like them to be counted by the progress |
| 74 | * monitor. We use an expanded progress monitor object to hold the |
| 75 | * additional pass count. |
| 76 | */ |
| 77 | |
| 78 | struct cdjpeg_progress_mgr { |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 79 | struct jpeg_progress_mgr pub; /* fields known to JPEG library */ |
| 80 | int completed_extra_passes; /* extra passes completed */ |
| 81 | int total_extra_passes; /* total extra */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 82 | /* last printed percentage stored here to avoid multiple printouts */ |
| 83 | int percent_done; |
| 84 | }; |
| 85 | |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 86 | typedef struct cdjpeg_progress_mgr *cd_progress_ptr; |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 87 | |
| 88 | |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 89 | /* Module selection routines for I/O modules. */ |
| 90 | |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 91 | EXTERN(cjpeg_source_ptr) jinit_read_bmp (j_compress_ptr cinfo); |
| 92 | EXTERN(djpeg_dest_ptr) jinit_write_bmp (j_decompress_ptr cinfo, |
| 93 | boolean is_os2); |
| 94 | EXTERN(cjpeg_source_ptr) jinit_read_gif (j_compress_ptr cinfo); |
| 95 | EXTERN(djpeg_dest_ptr) jinit_write_gif (j_decompress_ptr cinfo); |
| 96 | EXTERN(cjpeg_source_ptr) jinit_read_ppm (j_compress_ptr cinfo); |
| 97 | EXTERN(djpeg_dest_ptr) jinit_write_ppm (j_decompress_ptr cinfo); |
| 98 | EXTERN(cjpeg_source_ptr) jinit_read_rle (j_compress_ptr cinfo); |
| 99 | EXTERN(djpeg_dest_ptr) jinit_write_rle (j_decompress_ptr cinfo); |
| 100 | EXTERN(cjpeg_source_ptr) jinit_read_targa (j_compress_ptr cinfo); |
| 101 | EXTERN(djpeg_dest_ptr) jinit_write_targa (j_decompress_ptr cinfo); |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 102 | |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 103 | /* cjpeg support routines (in rdswitch.c) */ |
| 104 | |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 105 | EXTERN(boolean) read_quant_tables (j_compress_ptr cinfo, char *filename, |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 106 | boolean force_baseline); |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 107 | EXTERN(boolean) read_scan_script (j_compress_ptr cinfo, char *filename); |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 108 | EXTERN(boolean) set_quality_ratings (j_compress_ptr cinfo, char *arg, |
| 109 | boolean force_baseline); |
| 110 | EXTERN(boolean) set_quant_slots (j_compress_ptr cinfo, char *arg); |
| 111 | EXTERN(boolean) set_sample_factors (j_compress_ptr cinfo, char *arg); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 112 | |
| 113 | /* djpeg support routines (in rdcolmap.c) */ |
Thomas G. Lane | 36a4ccc | 1994-09-24 00:00:00 +0000 | [diff] [blame] | 114 | |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 115 | EXTERN(void) read_color_map (j_decompress_ptr cinfo, FILE *infile); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 116 | |
| 117 | /* common support routines (in cdjpeg.c) */ |
| 118 | |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 119 | EXTERN(void) enable_signal_catcher (j_common_ptr cinfo); |
| 120 | EXTERN(void) start_progress_monitor (j_common_ptr cinfo, |
| 121 | cd_progress_ptr progress); |
| 122 | EXTERN(void) end_progress_monitor (j_common_ptr cinfo); |
DRC | bd49803 | 2016-02-19 08:53:33 -0600 | [diff] [blame] | 123 | EXTERN(boolean) keymatch (char *arg, const char *keyword, int minchars); |
DRC | bc56b75 | 2014-05-16 10:43:44 +0000 | [diff] [blame] | 124 | EXTERN(FILE *) read_stdin (void); |
| 125 | EXTERN(FILE *) write_stdout (void); |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 126 | |
| 127 | /* miscellaneous useful macros */ |
| 128 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 129 | #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */ |
| 130 | #define READ_BINARY "r" |
| 131 | #define WRITE_BINARY "w" |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 132 | #else |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 133 | #define READ_BINARY "rb" |
| 134 | #define WRITE_BINARY "wb" |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 135 | #endif |
| 136 | |
DRC | e5eaf37 | 2014-05-09 18:00:32 +0000 | [diff] [blame] | 137 | #ifndef EXIT_FAILURE /* define exit() codes if not provided */ |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 138 | #define EXIT_FAILURE 1 |
| 139 | #endif |
| 140 | #ifndef EXIT_SUCCESS |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 141 | #define EXIT_SUCCESS 0 |
| 142 | #endif |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 143 | #ifndef EXIT_WARNING |
Thomas G. Lane | bc79e06 | 1995-08-02 00:00:00 +0000 | [diff] [blame] | 144 | #define EXIT_WARNING 2 |
| 145 | #endif |