blob: 108e7de98e75b08bfa5c45aca394c4971e6c47f1 [file] [log] [blame]
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00001/*
2 * jmorecfg.h
3 *
DRCa73e8702012-12-31 02:52:30 +00004 * This file was part of the Independent JPEG Group's software:
Thomas G. Lane5ead57a1998-03-27 00:00:00 +00005 * Copyright (C) 1991-1997, Thomas G. Lane.
DRCda13af62014-05-18 17:52:06 +00006 * libjpeg-turbo Modifications:
DRC78df2e62014-05-12 09:23:57 +00007 * Copyright (C) 2009, 2011, 2014, D. R. Commander.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +00008 * For conditions of distribution and use, see the accompanying README file.
9 *
10 * This file contains additional configuration options that customize the
11 * JPEG software for special applications or support machine-dependent
12 * optimizations. Most users will not need to touch this file.
13 */
14
15
16/*
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000017 * Maximum number of components (color channels) allowed in JPEG image.
18 * To meet the letter of the JPEG spec, set this to 255. However, darn
19 * few applications need more than 4 channels (maybe 5 for CMYK + alpha
20 * mask). We recommend 10 as a reasonable compromise; use 4 if you are
21 * really short on memory. (Each allowed component costs a hundred or so
22 * bytes of storage, whether actually used in an image or not.)
23 */
24
DRCe5eaf372014-05-09 18:00:32 +000025#define MAX_COMPONENTS 10 /* maximum number of image components */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000026
27
28/*
29 * Basic data types.
30 * You may need to change these if you have a machine with unusual data
31 * type sizes; for example, "char" not 8 bits, "short" not 16 bits,
32 * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,
33 * but it had better be at least 16.
34 */
35
36/* Representation of a single sample (pixel element value).
37 * We frequently allocate large arrays of these, so it's important to keep
38 * them small. But if you have memory to burn and access to char or short
39 * arrays is very slow on your hardware, you might want to change these.
40 */
41
42#if BITS_IN_JSAMPLE == 8
43/* JSAMPLE should be the smallest type that will hold the values 0..255.
44 * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
45 */
46
47#ifdef HAVE_UNSIGNED_CHAR
48
49typedef unsigned char JSAMPLE;
50#define GETJSAMPLE(value) ((int) (value))
51
52#else /* not HAVE_UNSIGNED_CHAR */
53
54typedef char JSAMPLE;
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +000055#ifdef __CHAR_UNSIGNED__
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000056#define GETJSAMPLE(value) ((int) (value))
57#else
58#define GETJSAMPLE(value) ((int) (value) & 0xFF)
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +000059#endif /* __CHAR_UNSIGNED__ */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000060
61#endif /* HAVE_UNSIGNED_CHAR */
62
DRCe5eaf372014-05-09 18:00:32 +000063#define MAXJSAMPLE 255
64#define CENTERJSAMPLE 128
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000065
66#endif /* BITS_IN_JSAMPLE == 8 */
67
68
69#if BITS_IN_JSAMPLE == 12
70/* JSAMPLE should be the smallest type that will hold the values 0..4095.
71 * On nearly all machines "short" will do nicely.
72 */
73
74typedef short JSAMPLE;
75#define GETJSAMPLE(value) ((int) (value))
76
DRCe5eaf372014-05-09 18:00:32 +000077#define MAXJSAMPLE 4095
78#define CENTERJSAMPLE 2048
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +000079
80#endif /* BITS_IN_JSAMPLE == 12 */
81
82
83/* Representation of a DCT frequency coefficient.
84 * This should be a signed value of at least 16 bits; "short" is usually OK.
85 * Again, we allocate large arrays of these, but you can change to int
86 * if you have memory to burn and "short" is really slow.
87 */
88
89typedef short JCOEF;
90
91
92/* Compressed datastreams are represented as arrays of JOCTET.
93 * These must be EXACTLY 8 bits wide, at least once they are written to
94 * external storage. Note that when using the stdio data source/destination
95 * managers, this is also the data type passed to fread/fwrite.
96 */
97
98#ifdef HAVE_UNSIGNED_CHAR
99
100typedef unsigned char JOCTET;
101#define GETJOCTET(value) (value)
102
103#else /* not HAVE_UNSIGNED_CHAR */
104
105typedef char JOCTET;
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +0000106#ifdef __CHAR_UNSIGNED__
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000107#define GETJOCTET(value) (value)
108#else
109#define GETJOCTET(value) ((value) & 0xFF)
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +0000110#endif /* __CHAR_UNSIGNED__ */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000111
112#endif /* HAVE_UNSIGNED_CHAR */
113
114
115/* These typedefs are used for various table entries and so forth.
116 * They must be at least as wide as specified; but making them too big
117 * won't cost a huge amount of memory, so we don't provide special
118 * extraction code like we did for JSAMPLE. (In other words, these
119 * typedefs live at a different point on the speed/space tradeoff curve.)
120 */
121
122/* UINT8 must hold at least the values 0..255. */
123
124#ifdef HAVE_UNSIGNED_CHAR
125typedef unsigned char UINT8;
126#else /* not HAVE_UNSIGNED_CHAR */
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +0000127#ifdef __CHAR_UNSIGNED__
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000128typedef char UINT8;
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +0000129#else /* not __CHAR_UNSIGNED__ */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000130typedef short UINT8;
Constantin Kaplinsky0ca44252008-09-28 05:08:48 +0000131#endif /* __CHAR_UNSIGNED__ */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000132#endif /* HAVE_UNSIGNED_CHAR */
133
134/* UINT16 must hold at least the values 0..65535. */
135
136#ifdef HAVE_UNSIGNED_SHORT
137typedef unsigned short UINT16;
138#else /* not HAVE_UNSIGNED_SHORT */
139typedef unsigned int UINT16;
140#endif /* HAVE_UNSIGNED_SHORT */
141
142/* INT16 must hold at least the values -32768..32767. */
143
DRCe5eaf372014-05-09 18:00:32 +0000144#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000145typedef short INT16;
146#endif
147
148/* INT32 must hold at least signed 32-bit values. */
149
DRCe5eaf372014-05-09 18:00:32 +0000150#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000151typedef long INT32;
152#endif
153
154/* Datatype used for image dimensions. The JPEG standard only supports
155 * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
156 * "unsigned int" is sufficient on all machines. However, if you need to
157 * handle larger images and you don't mind deviating from the spec, you
158 * can change this datatype.
159 */
160
161typedef unsigned int JDIMENSION;
162
163#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
164
165
Thomas G. Lane489583f1996-02-07 00:00:00 +0000166/* These macros are used in all function definitions and extern declarations.
167 * You could modify them if you need to change function linkage conventions;
168 * in particular, you'll need to do that to make the library a Windows DLL.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000169 * Another application is to make all functions global for use with debuggers
170 * or code profilers that require it.
171 */
172
Thomas G. Lane489583f1996-02-07 00:00:00 +0000173/* a function called through method pointers: */
DRCe5eaf372014-05-09 18:00:32 +0000174#define METHODDEF(type) static type
Thomas G. Lane489583f1996-02-07 00:00:00 +0000175/* a function used only in its module: */
DRCe5eaf372014-05-09 18:00:32 +0000176#define LOCAL(type) static type
Thomas G. Lane489583f1996-02-07 00:00:00 +0000177/* a function referenced thru EXTERNs: */
DRCe5eaf372014-05-09 18:00:32 +0000178#define GLOBAL(type) type
Thomas G. Lane489583f1996-02-07 00:00:00 +0000179/* a reference to a GLOBAL function: */
DRCe5eaf372014-05-09 18:00:32 +0000180#define EXTERN(type) extern type
Thomas G. Lane489583f1996-02-07 00:00:00 +0000181
182
DRCe2dd3e32014-11-25 09:48:15 +0000183/* Originally, this macro was used as a way of defining function prototypes
184 * for both modern compilers as well as older compilers that did not support
DRC2a6b8312014-11-25 10:07:43 +0000185 * prototype parameters. libjpeg-turbo has never supported these older,
186 * non-ANSI compilers, but the macro is still included because there is some
187 * software out there that uses it.
DRCe2dd3e32014-11-25 09:48:15 +0000188 */
189
190#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
191
192
DRC2a6b8312014-11-25 10:07:43 +0000193/* libjpeg-turbo no longer supports platforms that have far symbols (MS-DOS),
194 * but again, some software relies on this macro.
195 */
196
197#undef FAR
198#define FAR
199
200
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000201/*
202 * On a few systems, type boolean and/or its values FALSE, TRUE may appear
203 * in standard header files. Or you may have conflicts with application-
204 * specific header files that you want to include together with these files.
205 * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
206 */
207
208#ifndef HAVE_BOOLEAN
209typedef int boolean;
210#endif
DRCe5eaf372014-05-09 18:00:32 +0000211#ifndef FALSE /* in case these macros already exist */
212#define FALSE 0 /* values of boolean */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000213#endif
214#ifndef TRUE
DRCe5eaf372014-05-09 18:00:32 +0000215#define TRUE 1
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000216#endif
217
218
219/*
220 * The remaining options affect code selection within the JPEG library,
221 * but they don't need to be visible to most applications using the library.
222 * To minimize application namespace pollution, the symbols won't be
223 * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.
224 */
225
226#ifdef JPEG_INTERNALS
227#define JPEG_INTERNAL_OPTIONS
228#endif
229
230#ifdef JPEG_INTERNAL_OPTIONS
231
232
233/*
234 * These defines indicate whether to include various optional functions.
235 * Undefining some of these symbols will produce a smaller but less capable
236 * library. Note that you can leave certain source files out of the
237 * compilation/linking process if you've #undef'd the corresponding symbols.
238 * (You may HAVE to do that if your compiler doesn't like null source files.)
239 */
240
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000241/* Capability options common to encoder and decoder: */
242
DRCe5eaf372014-05-09 18:00:32 +0000243#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
244#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
245#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000246
247/* Encoder capability options: */
248
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000249#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
DRCe5eaf372014-05-09 18:00:32 +0000250#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
251#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000252/* Note: if you selected 12-bit data precision, it is dangerous to turn off
253 * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
254 * precision, so jchuff.c normally uses entropy optimization to compute
255 * usable tables for higher precision. If you don't want to do optimization,
256 * you'll have to supply different default Huffman tables.
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000257 * The exact same statements apply for progressive JPEG: the default tables
258 * don't work for progressive mode. (This may get fixed, however.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000259 */
260#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
261
262/* Decoder capability options: */
263
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000264#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
DRCe5eaf372014-05-09 18:00:32 +0000265#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
266#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
Thomas G. Lanebc79e061995-08-02 00:00:00 +0000267#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
DRCe5eaf372014-05-09 18:00:32 +0000268#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000269#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
270#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
DRCe5eaf372014-05-09 18:00:32 +0000271#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
272#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000273
274/* more capability options later, no doubt */
275
276
277/*
DRC976fd962014-05-13 18:41:33 +0000278 * The RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE macros are a vestigial
279 * feature of libjpeg. The idea was that, if an application developer needed
280 * to compress from/decompress to a BGR/BGRX/RGBX/XBGR/XRGB buffer, they could
281 * change these macros, rebuild libjpeg, and link their application statically
282 * with it. In reality, few people ever did this, because there were some
283 * severe restrictions involved (cjpeg and djpeg no longer worked properly,
284 * compressing/decompressing RGB JPEGs no longer worked properly, and the color
285 * quantizer wouldn't work with pixel sizes other than 3.) Further, since all
286 * of the O/S-supplied versions of libjpeg were built with the default values
287 * of RGB_RED, RGB_GREEN, RGB_BLUE, and RGB_PIXELSIZE, many applications have
288 * come to regard these values as immutable.
289 *
290 * The libjpeg-turbo colorspace extensions provide a much cleaner way of
291 * compressing from/decompressing to buffers with arbitrary component orders
292 * and pixel sizes. Thus, we do not support changing the values of RGB_RED,
293 * RGB_GREEN, RGB_BLUE, or RGB_PIXELSIZE. In addition to the restrictions
294 * listed above, changing these values will also break the SIMD extensions and
295 * the regression tests.
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000296 */
297
DRCe5eaf372014-05-09 18:00:32 +0000298#define RGB_RED 0 /* Offset of Red in an RGB scanline element */
299#define RGB_GREEN 1 /* Offset of Green */
300#define RGB_BLUE 2 /* Offset of Blue */
301#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000302
DRC78df2e62014-05-12 09:23:57 +0000303#define JPEG_NUMCS 17
DRCf25c0712009-04-03 12:00:51 +0000304
DRCb4570bb2011-09-07 06:31:00 +0000305#define EXT_RGB_RED 0
306#define EXT_RGB_GREEN 1
307#define EXT_RGB_BLUE 2
308#define EXT_RGB_PIXELSIZE 3
309
310#define EXT_RGBX_RED 0
311#define EXT_RGBX_GREEN 1
312#define EXT_RGBX_BLUE 2
313#define EXT_RGBX_PIXELSIZE 4
314
315#define EXT_BGR_RED 2
316#define EXT_BGR_GREEN 1
317#define EXT_BGR_BLUE 0
318#define EXT_BGR_PIXELSIZE 3
319
320#define EXT_BGRX_RED 2
321#define EXT_BGRX_GREEN 1
322#define EXT_BGRX_BLUE 0
323#define EXT_BGRX_PIXELSIZE 4
324
325#define EXT_XBGR_RED 3
326#define EXT_XBGR_GREEN 2
327#define EXT_XBGR_BLUE 1
328#define EXT_XBGR_PIXELSIZE 4
329
330#define EXT_XRGB_RED 1
331#define EXT_XRGB_GREEN 2
332#define EXT_XRGB_BLUE 3
333#define EXT_XRGB_PIXELSIZE 4
334
DRCf25c0712009-04-03 12:00:51 +0000335static const int rgb_red[JPEG_NUMCS] = {
DRCb4570bb2011-09-07 06:31:00 +0000336 -1, -1, RGB_RED, -1, -1, -1, EXT_RGB_RED, EXT_RGBX_RED,
DRC67ce3b22011-12-19 02:21:03 +0000337 EXT_BGR_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED,
DRC78df2e62014-05-12 09:23:57 +0000338 EXT_RGBX_RED, EXT_BGRX_RED, EXT_XBGR_RED, EXT_XRGB_RED,
339 -1
DRCf25c0712009-04-03 12:00:51 +0000340};
341
342static const int rgb_green[JPEG_NUMCS] = {
DRCb4570bb2011-09-07 06:31:00 +0000343 -1, -1, RGB_GREEN, -1, -1, -1, EXT_RGB_GREEN, EXT_RGBX_GREEN,
DRC67ce3b22011-12-19 02:21:03 +0000344 EXT_BGR_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN,
DRC78df2e62014-05-12 09:23:57 +0000345 EXT_RGBX_GREEN, EXT_BGRX_GREEN, EXT_XBGR_GREEN, EXT_XRGB_GREEN,
346 -1
DRCf25c0712009-04-03 12:00:51 +0000347};
348
349static const int rgb_blue[JPEG_NUMCS] = {
DRCb4570bb2011-09-07 06:31:00 +0000350 -1, -1, RGB_BLUE, -1, -1, -1, EXT_RGB_BLUE, EXT_RGBX_BLUE,
DRC67ce3b22011-12-19 02:21:03 +0000351 EXT_BGR_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE,
DRC78df2e62014-05-12 09:23:57 +0000352 EXT_RGBX_BLUE, EXT_BGRX_BLUE, EXT_XBGR_BLUE, EXT_XRGB_BLUE,
353 -1
DRCf25c0712009-04-03 12:00:51 +0000354};
355
356static const int rgb_pixelsize[JPEG_NUMCS] = {
DRCb4570bb2011-09-07 06:31:00 +0000357 -1, -1, RGB_PIXELSIZE, -1, -1, -1, EXT_RGB_PIXELSIZE, EXT_RGBX_PIXELSIZE,
DRC67ce3b22011-12-19 02:21:03 +0000358 EXT_BGR_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE,
DRC78df2e62014-05-12 09:23:57 +0000359 EXT_RGBX_PIXELSIZE, EXT_BGRX_PIXELSIZE, EXT_XBGR_PIXELSIZE, EXT_XRGB_PIXELSIZE,
360 -1
DRCf25c0712009-04-03 12:00:51 +0000361};
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000362
363/* Definitions for speed-related optimizations. */
364
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000365/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
366 * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
367 * as short on such a machine. MULTIPLIER must be at least 16 bits wide.
368 */
369
370#ifndef MULTIPLIER
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000371#ifndef WITH_SIMD
DRCe5eaf372014-05-09 18:00:32 +0000372#define MULTIPLIER int /* type for fastest integer multiply */
Pierre Ossman5eb84ff2009-03-09 13:25:30 +0000373#else
374#define MULTIPLIER short /* prefer 16-bit with SIMD for parellelism */
375#endif
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000376#endif
377
378
379/* FAST_FLOAT should be either float or double, whichever is done faster
380 * by your compiler. (Note that this type is only used in the floating point
381 * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000382 */
383
384#ifndef FAST_FLOAT
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000385#define FAST_FLOAT float
Thomas G. Lane36a4ccc1994-09-24 00:00:00 +0000386#endif
387
388#endif /* JPEG_INTERNAL_OPTIONS */