8768aa4b6a389cdb90c6753e537e169a1a1b9a73
[oweals/cde.git] / cde / lib / DtHelp / jpeg / cdjpeg.h
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: cdjpeg.h /main/2 1996/05/09 03:45:31 drk $ */
24 /*
25  * cdjpeg.h
26  *
27  * Copyright (C) 1994-1996, Thomas G. Lane.
28  * This file is part of the Independent JPEG Group's software.
29  * For conditions of distribution and use, see the accompanying README file.
30  *
31  * This file contains common declarations for the sample applications
32  * cjpeg and djpeg.  It is NOT used by the core JPEG library.
33  */
34
35 #define JPEG_CJPEG_DJPEG        /* define proper options in jconfig.h */
36 #define JPEG_INTERNAL_OPTIONS   /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
37 #include "jinclude.h"
38 #include "jpeglib.h"
39 #include "jerror.h"             /* get library error codes too */
40 #include "cderror.h"            /* get application-specific error codes */
41
42
43 /*
44  * Object interface for cjpeg's source file decoding modules
45  */
46
47 typedef struct cjpeg_source_struct * cjpeg_source_ptr;
48
49 struct cjpeg_source_struct {
50   JMETHOD(void, start_input, (j_compress_ptr cinfo,
51                               cjpeg_source_ptr sinfo));
52   JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
53                                        cjpeg_source_ptr sinfo));
54   JMETHOD(void, finish_input, (j_compress_ptr cinfo,
55                                cjpeg_source_ptr sinfo));
56
57   FILE *input_file;
58
59   JSAMPARRAY buffer;
60   JDIMENSION buffer_height;
61 };
62
63
64 /*
65  * Object interface for djpeg's output file encoding modules
66  */
67
68 typedef struct djpeg_dest_struct * djpeg_dest_ptr;
69
70 struct djpeg_dest_struct {
71   /* start_output is called after jpeg_start_decompress finishes.
72    * The color map will be ready at this time, if one is needed.
73    */
74   JMETHOD(void, start_output, (j_decompress_ptr cinfo,
75                                djpeg_dest_ptr dinfo));
76   /* Emit the specified number of pixel rows from the buffer. */
77   JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
78                                  djpeg_dest_ptr dinfo,
79                                  JDIMENSION rows_supplied));
80   /* Finish up at the end of the image. */
81   JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
82                                 djpeg_dest_ptr dinfo));
83
84   /* Target file spec; filled in by djpeg.c after object is created. */
85   FILE * output_file;
86
87   /* Output pixel-row buffer.  Created by module init or start_output.
88    * Width is cinfo->output_width * cinfo->output_components;
89    * height is buffer_height.
90    */
91   JSAMPARRAY buffer;
92   JDIMENSION buffer_height;
93 };
94
95
96 /*
97  * cjpeg/djpeg may need to perform extra passes to convert to or from
98  * the source/destination file format.  The JPEG library does not know
99  * about these passes, but we'd like them to be counted by the progress
100  * monitor.  We use an expanded progress monitor object to hold the
101  * additional pass count.
102  */
103
104 struct cdjpeg_progress_mgr {
105   struct jpeg_progress_mgr pub; /* fields known to JPEG library */
106   int completed_extra_passes;   /* extra passes completed */
107   int total_extra_passes;       /* total extra */
108   /* last printed percentage stored here to avoid multiple printouts */
109   int percent_done;
110 };
111
112 typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
113
114
115 /* Short forms of external names for systems with brain-damaged linkers. */
116
117 #ifdef NEED_SHORT_EXTERNAL_NAMES
118 #define jinit_read_bmp          jIRdBMP
119 #define jinit_write_bmp         jIWrBMP
120 #define jinit_read_gif          jIRdGIF
121 #define jinit_write_gif         jIWrGIF
122 #define jinit_read_ppm          jIRdPPM
123 #define jinit_write_ppm         jIWrPPM
124 #define jinit_read_rle          jIRdRLE
125 #define jinit_write_rle         jIWrRLE
126 #define jinit_read_targa        jIRdTarga
127 #define jinit_write_targa       jIWrTarga
128 #define read_quant_tables       RdQTables
129 #define read_scan_script        RdScnScript
130 #define set_quant_slots         SetQSlots
131 #define set_sample_factors      SetSFacts
132 #define read_color_map          RdCMap
133 #define enable_signal_catcher   EnSigCatcher
134 #define start_progress_monitor  StProgMon
135 #define end_progress_monitor    EnProgMon
136 #define read_stdin              RdStdin
137 #define write_stdout            WrStdout
138 #endif /* NEED_SHORT_EXTERNAL_NAMES */
139
140 /* Module selection routines for I/O modules. */
141
142 EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
143 EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
144                                             boolean is_os2));
145 EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
146 EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));
147 EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
148 EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
149 EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
150 EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
151 EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
152 EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
153
154 /* cjpeg support routines (in rdswitch.c) */
155
156 EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
157                                     int scale_factor, boolean force_baseline));
158 EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
159 EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
160 EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
161
162 /* djpeg support routines (in rdcolmap.c) */
163
164 EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
165
166 /* common support routines (in cdjpeg.c) */
167
168 EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
169 EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
170                                          cd_progress_ptr progress));
171 EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
172 EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
173 EXTERN(FILE *) read_stdin JPP((void));
174 EXTERN(FILE *) write_stdout JPP((void));
175
176 /* miscellaneous useful macros */
177
178 #ifdef DONT_USE_B_MODE          /* define mode parameters for fopen() */
179 #define READ_BINARY     "r"
180 #define WRITE_BINARY    "w"
181 #else
182 #define READ_BINARY     "rb"
183 #define WRITE_BINARY    "wb"
184 #endif
185
186 #ifndef EXIT_FAILURE            /* define exit() codes if not provided */
187 #define EXIT_FAILURE  1
188 #endif
189 #ifndef EXIT_SUCCESS
190 #ifdef VMS
191 #define EXIT_SUCCESS  1         /* VMS is very nonstandard */
192 #else
193 #define EXIT_SUCCESS  0
194 #endif
195 #endif
196 #ifndef EXIT_WARNING
197 #ifdef VMS
198 #define EXIT_WARNING  1         /* VMS is very nonstandard */
199 #else
200 #define EXIT_WARNING  2
201 #endif
202 #endif