blob: f878ed7cba87e2723bbab8c5fe5a3e8cbf1c65e1 [file] [log] [blame]
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -08001/*
2 * jmorecfg.h
3 *
4 * Copyright (C) 1991-1997, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file.
7 *
8 * This file contains additional configuration options that customize the
9 * JPEG software for special applications or support machine-dependent
10 * optimizations. Most users will not need to touch this file.
11 */
12
Hal Canary021b9902014-08-01 09:29:17 -040013#ifndef JMORECFG_H
14#define JMORECFG_H
15
16#include <stdint.h>
17
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -080018/*
19 * Define ANDROID_RGB to enable specific optimizations for Android
20 * JCS_RGBA_8888 support
21 * JCS_RGB_565 support
22 *
23 */
24
25#define ANDROID_RGB
26
27#ifdef ANDROID_RGB
Mathias Agopian4e7198a2009-09-04 19:18:45 -070028#define PACK_SHORT_565(r,g,b) ((((r)<<8)&0xf800)|(((g)<<3)&0x7E0)|((b)>>3))
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -080029#define PACK_TWO_PIXELS(l,r) ((r<<16) | l)
Colin Cross0da7ab62014-02-05 18:09:45 -080030#define PACK_NEED_ALIGNMENT(ptr) (((uintptr_t)(ptr))&3)
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -080031#define WRITE_TWO_PIXELS(addr, pixels) do { \
32 ((INT16*)(addr))[0] = (pixels); \
33 ((INT16*)(addr))[1] = (pixels)>>16; \
34 } while(0)
35#define WRITE_TWO_ALIGNED_PIXELS(addr, pixels) ((*(INT32*)(addr)) = pixels)
36#define DITHER_565_R(r, dither) ((r) + ((dither)&0xFF))
37#define DITHER_565_G(g, dither) ((g) + (((dither)&0xFF)>>1))
38#define DITHER_565_B(b, dither) ((b) + ((dither)&0xFF))
39#endif
40
41/*
42 * Define BITS_IN_JSAMPLE as either
43 * 8 for 8-bit sample values (the usual setting)
44 * 12 for 12-bit sample values
45 * Only 8 and 12 are legal data precisions for lossy JPEG according to the
46 * JPEG standard, and the IJG code does not support anything else!
47 * We do not support run-time selection of data precision, sorry.
48 */
49
50#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
51
52
53/*
54 * Maximum number of components (color channels) allowed in JPEG image.
55 * To meet the letter of the JPEG spec, set this to 255. However, darn
56 * few applications need more than 4 channels (maybe 5 for CMYK + alpha
57 * mask). We recommend 10 as a reasonable compromise; use 4 if you are
58 * really short on memory. (Each allowed component costs a hundred or so
59 * bytes of storage, whether actually used in an image or not.)
60 */
61
62#define MAX_COMPONENTS 10 /* maximum number of image components */
63
64
65/*
66 * Basic data types.
67 * You may need to change these if you have a machine with unusual data
68 * type sizes; for example, "char" not 8 bits, "short" not 16 bits,
69 * or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,
70 * but it had better be at least 16.
71 */
72
73/* Representation of a single sample (pixel element value).
74 * We frequently allocate large arrays of these, so it's important to keep
75 * them small. But if you have memory to burn and access to char or short
76 * arrays is very slow on your hardware, you might want to change these.
77 */
78
79#if BITS_IN_JSAMPLE == 8
80/* JSAMPLE should be the smallest type that will hold the values 0..255.
81 * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
82 */
83
84#ifdef HAVE_UNSIGNED_CHAR
85
Hal Canary021b9902014-08-01 09:29:17 -040086typedef uint8_t JSAMPLE;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -080087#define GETJSAMPLE(value) ((int) (value))
88
89#else /* not HAVE_UNSIGNED_CHAR */
90
91typedef char JSAMPLE;
92#ifdef CHAR_IS_UNSIGNED
93#define GETJSAMPLE(value) ((int) (value))
94#else
95#define GETJSAMPLE(value) ((int) (value) & 0xFF)
96#endif /* CHAR_IS_UNSIGNED */
97
98#endif /* HAVE_UNSIGNED_CHAR */
99
100#define MAXJSAMPLE 255
101#define CENTERJSAMPLE 128
102
103#endif /* BITS_IN_JSAMPLE == 8 */
104
105
106#if BITS_IN_JSAMPLE == 12
107/* JSAMPLE should be the smallest type that will hold the values 0..4095.
108 * On nearly all machines "short" will do nicely.
109 */
110
Hal Canary021b9902014-08-01 09:29:17 -0400111typedef int16_t JSAMPLE;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800112#define GETJSAMPLE(value) ((int) (value))
113
114#define MAXJSAMPLE 4095
115#define CENTERJSAMPLE 2048
116
117#endif /* BITS_IN_JSAMPLE == 12 */
118
119
120/* Representation of a DCT frequency coefficient.
121 * This should be a signed value of at least 16 bits; "short" is usually OK.
122 * Again, we allocate large arrays of these, but you can change to int
123 * if you have memory to burn and "short" is really slow.
124 */
125
Hal Canary021b9902014-08-01 09:29:17 -0400126typedef int16_t JCOEF;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800127
128
129/* Compressed datastreams are represented as arrays of JOCTET.
130 * These must be EXACTLY 8 bits wide, at least once they are written to
131 * external storage. Note that when using the stdio data source/destination
132 * managers, this is also the data type passed to fread/fwrite.
133 */
134
135#ifdef HAVE_UNSIGNED_CHAR
136
Hal Canary021b9902014-08-01 09:29:17 -0400137typedef uint8_t JOCTET;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800138#define GETJOCTET(value) (value)
139
140#else /* not HAVE_UNSIGNED_CHAR */
141
142typedef char JOCTET;
143#ifdef CHAR_IS_UNSIGNED
144#define GETJOCTET(value) (value)
145#else
146#define GETJOCTET(value) ((value) & 0xFF)
147#endif /* CHAR_IS_UNSIGNED */
148
149#endif /* HAVE_UNSIGNED_CHAR */
150
151
152/* These typedefs are used for various table entries and so forth.
153 * They must be at least as wide as specified; but making them too big
154 * won't cost a huge amount of memory, so we don't provide special
155 * extraction code like we did for JSAMPLE. (In other words, these
156 * typedefs live at a different point on the speed/space tradeoff curve.)
157 */
158
159/* UINT8 must hold at least the values 0..255. */
160
161#ifdef HAVE_UNSIGNED_CHAR
Hal Canary021b9902014-08-01 09:29:17 -0400162typedef uint8_t UINT8;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800163#else /* not HAVE_UNSIGNED_CHAR */
164#ifdef CHAR_IS_UNSIGNED
165typedef char UINT8;
166#else /* not CHAR_IS_UNSIGNED */
167typedef short UINT8;
168#endif /* CHAR_IS_UNSIGNED */
169#endif /* HAVE_UNSIGNED_CHAR */
170
171/* UINT16 must hold at least the values 0..65535. */
172
173#ifdef HAVE_UNSIGNED_SHORT
Hal Canary021b9902014-08-01 09:29:17 -0400174typedef uint16_t UINT16;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800175#else /* not HAVE_UNSIGNED_SHORT */
176typedef unsigned int UINT16;
177#endif /* HAVE_UNSIGNED_SHORT */
178
179/* INT16 must hold at least the values -32768..32767. */
180
181#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
Hal Canary021b9902014-08-01 09:29:17 -0400182typedef int16_t INT16;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800183#endif
184
185/* INT32 must hold at least signed 32-bit values. */
186
187#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
Hal Canary021b9902014-08-01 09:29:17 -0400188typedef int32_t INT32;
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800189#endif
190
191/* Datatype used for image dimensions. The JPEG standard only supports
192 * images up to 64K*64K due to 16-bit fields in SOF markers. Therefore
193 * "unsigned int" is sufficient on all machines. However, if you need to
194 * handle larger images and you don't mind deviating from the spec, you
195 * can change this datatype.
196 */
197
198typedef unsigned int JDIMENSION;
199
200#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
201
202
203/* These macros are used in all function definitions and extern declarations.
204 * You could modify them if you need to change function linkage conventions;
205 * in particular, you'll need to do that to make the library a Windows DLL.
206 * Another application is to make all functions global for use with debuggers
207 * or code profilers that require it.
208 */
209
210/* a function called through method pointers: */
211#define METHODDEF(type) static type
212/* a function used only in its module: */
213#define LOCAL(type) static type
214/* a function referenced thru EXTERNs: */
215#define GLOBAL(type) type
216/* a reference to a GLOBAL function: */
217#define EXTERN(type) extern type
218
219
220/* This macro is used to declare a "method", that is, a function pointer.
221 * We want to supply prototype parameters if the compiler can cope.
222 * Note that the arglist parameter must be parenthesized!
223 * Again, you can customize this if you need special linkage keywords.
224 */
225
226#ifdef HAVE_PROTOTYPES
227#define JMETHOD(type,methodname,arglist) type (*methodname) arglist
228#else
229#define JMETHOD(type,methodname,arglist) type (*methodname) ()
230#endif
231
232
233/* Here is the pseudo-keyword for declaring pointers that must be "far"
234 * on 80x86 machines. Most of the specialized coding for 80x86 is handled
235 * by just saying "FAR *" where such a pointer is needed. In a few places
236 * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
237 */
238
239#ifdef NEED_FAR_POINTERS
240#define FAR far
241#else
242#define FAR
243#endif
244
245
246/*
247 * On a few systems, type boolean and/or its values FALSE, TRUE may appear
248 * in standard header files. Or you may have conflicts with application-
249 * specific header files that you want to include together with these files.
250 * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
251 */
252
253#ifndef HAVE_BOOLEAN
254typedef int boolean;
255#endif
256#ifndef FALSE /* in case these macros already exist */
257#define FALSE 0 /* values of boolean */
258#endif
259#ifndef TRUE
260#define TRUE 1
261#endif
262
263
264/*
265 * The remaining options affect code selection within the JPEG library,
266 * but they don't need to be visible to most applications using the library.
267 * To minimize application namespace pollution, the symbols won't be
268 * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.
269 */
270
271#ifdef JPEG_INTERNALS
272#define JPEG_INTERNAL_OPTIONS
273#endif
274
275#ifdef JPEG_INTERNAL_OPTIONS
276
277
278/*
279 * These defines indicate whether to include various optional functions.
280 * Undefining some of these symbols will produce a smaller but less capable
281 * library. Note that you can leave certain source files out of the
282 * compilation/linking process if you've #undef'd the corresponding symbols.
283 * (You may HAVE to do that if your compiler doesn't like null source files.)
284 */
285
286/* Arithmetic coding is unsupported for legal reasons. Complaints to IBM. */
287
288/* Capability options common to encoder and decoder: */
289
290#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
291#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
292#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
293
294/* Encoder capability options: */
295
296#undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
297#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
298#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
299#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
300/* Note: if you selected 12-bit data precision, it is dangerous to turn off
301 * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
302 * precision, so jchuff.c normally uses entropy optimization to compute
303 * usable tables for higher precision. If you don't want to do optimization,
304 * you'll have to supply different default Huffman tables.
305 * The exact same statements apply for progressive JPEG: the default tables
306 * don't work for progressive mode. (This may get fixed, however.)
307 */
308#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
309
310/* Decoder capability options: */
311
312#undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
313#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
314#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
315#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
316#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
317#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
318#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
319#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
320#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
321#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
322
323/* more capability options later, no doubt */
324
325
326/*
327 * Ordering of RGB data in scanlines passed to or from the application.
328 * If your application wants to deal with data in the order B,G,R, just
329 * change these macros. You can also deal with formats such as R,G,B,X
330 * (one extra byte per pixel) by changing RGB_PIXELSIZE. Note that changing
331 * the offsets will also change the order in which colormap data is organized.
332 * RESTRICTIONS:
333 * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
334 * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
335 * useful if you are using JPEG color spaces other than YCbCr or grayscale.
336 * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
337 * is not 3 (they don't understand about dummy color components!). So you
338 * can't use color quantization if you change that value.
339 */
340
341#define RGB_RED 0 /* Offset of Red in an RGB scanline element */
342#define RGB_GREEN 1 /* Offset of Green */
343#define RGB_BLUE 2 /* Offset of Blue */
344#ifdef ANDROID_RGB
345#define RGB_ALPHA 3 /* Offset of Alpha */
346#endif
347#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
348
349/* Definitions for speed-related optimizations. */
350
351
352/* If your compiler supports inline functions, define INLINE
353 * as the inline keyword; otherwise define it as empty.
354 */
355
356#ifndef INLINE
357#ifdef __GNUC__ /* for instance, GNU C knows about inline */
358#define INLINE __inline__
359#endif
360#ifndef INLINE
361#define INLINE /* default is to define it as empty */
362#endif
363#endif
364
365
366/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
367 * two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER
368 * as short on such a machine. MULTIPLIER must be at least 16 bits wide.
369 */
370
371#ifndef MULTIPLIER
tengfei.zhao6553d242012-07-04 15:50:59 +0800372#ifdef ANDROID_INTELSSE2_IDCT
373 #define MULTIPLIER short
Prajakta Gudadhe6a3be8d2012-06-11 14:08:27 -0700374#elif ANDROID_MIPS_IDCT
375 #define MULTIPLIER short
376#elif NV_ARM_NEON
377 #define MULTIPLIER short
tengfei.zhao6553d242012-07-04 15:50:59 +0800378#else
Prajakta Gudadhe6a3be8d2012-06-11 14:08:27 -0700379 #define MULTIPLIER int /* type for fastest integer multiply */
tengfei.zhao6553d242012-07-04 15:50:59 +0800380#endif
The Android Open Source Project9f5d49a2009-03-03 19:30:03 -0800381#endif
382
383
384/* FAST_FLOAT should be either float or double, whichever is done faster
385 * by your compiler. (Note that this type is only used in the floating point
386 * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
387 * Typically, float is faster in ANSI C compilers, while double is faster in
388 * pre-ANSI compilers (because they insist on converting to double anyway).
389 * The code below therefore chooses float if we have ANSI-style prototypes.
390 */
391
392#ifndef FAST_FLOAT
393#ifdef HAVE_PROTOTYPES
394#define FAST_FLOAT float
395#else
396#define FAST_FLOAT double
397#endif
398#endif
399
400#endif /* JPEG_INTERNAL_OPTIONS */
Hal Canary021b9902014-08-01 09:29:17 -0400401
402#endif /* JMORECFG_H */