/*1* jmorecfg.h2*3* Copyright (C) 1991-1997, Thomas G. Lane.4* Modified 1997-2025 by Guido Vollbeding.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 the9* JPEG software for special applications or support machine-dependent10* optimizations. Most users will not need to touch this file.11*/121314#define JPEG_DATA_PRECISION 8 /* see table below */15#define BITS_IN_JSAMPLE JPEG_DATA_PRECISION /* see table below */16/*17* Most useful alternative for "HDR" (High Dynamic Range) application18* with backward compatibility for file interchange (see table below;19* move comment marks for selection):20#define BITS_IN_JSAMPLE 1021*/22/* For still higher demands (see table below):23#define BITS_IN_JSAMPLE 1124*/25/* or26#define BITS_IN_JSAMPLE 1227*/2829/* | BITS_IN_JSAMPLE30* JPEG_DATA_PRECISION | read / write with full DCT up to lossless operation31* | exceptions see below32* -------------------------------------------------------------------------------33* {[_8_]} | _8_ <9> <10> <11>* <12>~34* [_9_] | <8> _9_ <10> <11> <12>*35* [_10_] | <8> <9> _10_ <11> <12> 13 *36* _11_ | <8> <9> <10> _11_ <12> 13 14 *37* _12_ | <8> <9> <10> <11> _12_ 13 14 15 *38* 13 | 8 9 10 11 12 13 14 15 16 *39*40* _x_ currently and previously implemented - default configuration41* <x> newly implemented42* {x} current standard for file interchange - backward compatible43* [x] next standard for file interchange - common DCT implementation category44* * does not support GCC lossless (GCbCr lossless - requires 1 extra bit)45* ~ 1 bit precision loss - effective 11 bits precision (lossy)46*47* Since the DCT coefficients are 3 bits larger than sample values with normal DCT48* processing, it is possible to support sample values with up to 3 more bits than49* the nominal JPEG data precision parameter by adapted DCT processing with up to50* lossless operation. The generated JPEG files are fully interchangeable for the51* same JPEG data precision parameter. Another BITS_IN_JSAMPLE setting will just52* reconstruct an image with corresponding precision.53*54* A special case for JPEG data precision 8 with 12-bit sample size (4 more bits)55* is provided so that all previously available sample formats are now supported56* for file interchange with backward compatibility.57* If full-feature DCT up to lossless operation with up to 12-bit sample size is58* required, it is recommended to select JPEG data precision 10, because it falls59* in the same DCT implementation category with 8 and 9 which may be commonly60* supported at run-time as the next standard for file interchange.61*62* Remaining bit depths and variability at run-time may be added later and63* are currently not supported, sorry.64* Exception: The transcoding part (jpegtran) supports all settings in a65* single instance, since it operates on the level of DCT coefficients and66* not sample values. The DCT coefficients are of the same type (16 bits)67* in all cases (see below).68*/697071/*72* Maximum number of components (color channels) allowed in JPEG image.73* To meet the letter of the JPEG spec, set this to 255. However, darn74* few applications need more than 4 channels (maybe 5 for CMYK + alpha75* mask). We recommend 10 as a reasonable compromise; use 4 if you are76* really short on memory. (Each allowed component costs a hundred or so77* bytes of storage, whether actually used in an image or not.)78*/7980#define MAX_COMPONENTS 10 /* maximum number of image components */818283/*84* Basic data types.85* You may need to change these if you have a machine with unusual data86* type sizes; for example, "char" not 8 bits, "short" not 16 bits,87* or "long" not 32 bits. We don't care whether "int" is 16 or 32 bits,88* but it had better be at least 16.89*/9091/* Representation of a single sample (pixel element value).92* We frequently allocate large arrays of these, so it's important to keep93* them small. But if you have memory to burn and access to char or short94* arrays is very slow on your hardware, you might want to change these.95*/9697#if BITS_IN_JSAMPLE == 898/* JSAMPLE should be the smallest type that will hold the values 0..255.99* You can use a signed char by having GETJSAMPLE mask it with 0xFF.100*/101102#ifdef HAVE_UNSIGNED_CHAR103104typedef unsigned char JSAMPLE;105#define GETJSAMPLE(value) ((int) (value))106107#else /* not HAVE_UNSIGNED_CHAR */108109typedef char JSAMPLE;110#ifdef CHAR_IS_UNSIGNED111#define GETJSAMPLE(value) ((int) (value))112#else113#define GETJSAMPLE(value) ((int) (value) & 0xFF)114#endif /* CHAR_IS_UNSIGNED */115116#endif /* HAVE_UNSIGNED_CHAR */117118#define MAXJSAMPLE 255119#define CENTERJSAMPLE 128120121#endif /* BITS_IN_JSAMPLE == 8 */122123124#if BITS_IN_JSAMPLE == 9125/* JSAMPLE should be the smallest type that will hold the values 0..511.126* On nearly all machines "short" will do nicely.127*/128129typedef short JSAMPLE;130#define GETJSAMPLE(value) ((int) (value))131132#define MAXJSAMPLE 511133#define CENTERJSAMPLE 256134135#endif /* BITS_IN_JSAMPLE == 9 */136137138#if BITS_IN_JSAMPLE == 10139/* JSAMPLE should be the smallest type that will hold the values 0..1023.140* On nearly all machines "short" will do nicely.141*/142143typedef short JSAMPLE;144#define GETJSAMPLE(value) ((int) (value))145146#define MAXJSAMPLE 1023147#define CENTERJSAMPLE 512148149#endif /* BITS_IN_JSAMPLE == 10 */150151152#if BITS_IN_JSAMPLE == 11153/* JSAMPLE should be the smallest type that will hold the values 0..2047.154* On nearly all machines "short" will do nicely.155*/156157typedef short JSAMPLE;158#define GETJSAMPLE(value) ((int) (value))159160#define MAXJSAMPLE 2047161#define CENTERJSAMPLE 1024162163#endif /* BITS_IN_JSAMPLE == 11 */164165166#if BITS_IN_JSAMPLE == 12167/* JSAMPLE should be the smallest type that will hold the values 0..4095.168* On nearly all machines "short" will do nicely.169*/170171typedef short JSAMPLE;172#define GETJSAMPLE(value) ((int) (value))173174#define MAXJSAMPLE 4095175#define CENTERJSAMPLE 2048176177#endif /* BITS_IN_JSAMPLE == 12 */178179180/* Representation of a DCT frequency coefficient.181* This should be a signed value of at least 16 bits; "short" is usually OK.182* Again, we allocate large arrays of these, but you can change to int183* if you have memory to burn and "short" is really slow.184*/185186typedef short JCOEF;187188189/* Compressed datastreams are represented as arrays of JOCTET.190* These must be EXACTLY 8 bits wide, at least once they are written to191* external storage. Note that when using the stdio data source/destination192* managers, this is also the data type passed to fread/fwrite.193*/194195#ifdef HAVE_UNSIGNED_CHAR196197typedef unsigned char JOCTET;198#define GETJOCTET(value) (value)199200#else /* not HAVE_UNSIGNED_CHAR */201202typedef char JOCTET;203#ifdef CHAR_IS_UNSIGNED204#define GETJOCTET(value) (value)205#else206#define GETJOCTET(value) ((value) & 0xFF)207#endif /* CHAR_IS_UNSIGNED */208209#endif /* HAVE_UNSIGNED_CHAR */210211212/* These typedefs are used for various table entries and so forth.213* They must be at least as wide as specified; but making them too big214* won't cost a huge amount of memory, so we don't provide special215* extraction code like we did for JSAMPLE. (In other words, these216* typedefs live at a different point on the speed/space tradeoff curve.)217*/218219/* UINT8 must hold at least the values 0..255. */220221#ifdef HAVE_UNSIGNED_CHAR222typedef unsigned char UINT8;223#else /* not HAVE_UNSIGNED_CHAR */224#ifdef CHAR_IS_UNSIGNED225typedef char UINT8;226#else /* not CHAR_IS_UNSIGNED */227typedef short UINT8;228#endif /* CHAR_IS_UNSIGNED */229#endif /* HAVE_UNSIGNED_CHAR */230231/* UINT16 must hold at least the values 0..65535. */232233#ifdef HAVE_UNSIGNED_SHORT234typedef unsigned short UINT16;235#else /* not HAVE_UNSIGNED_SHORT */236typedef unsigned int UINT16;237#endif /* HAVE_UNSIGNED_SHORT */238239/* INT16 must hold at least the values -32768..32767. */240241#ifndef XMD_H /* X11/xmd.h correctly defines INT16 */242typedef short INT16;243#endif244245/* INT32 must hold at least signed 32-bit values. */246247#ifndef XMD_H /* X11/xmd.h correctly defines INT32 */248#ifndef _BASETSD_H_ /* Microsoft defines it in basetsd.h */249#ifndef _BASETSD_H /* MinGW is slightly different */250#ifndef QGLOBAL_H /* Qt defines it in qglobal.h */251typedef long INT32;252#endif253#endif254#endif255#endif256257/* Datatype used for image dimensions. The JPEG standard only supports258* images up to 64K*64K due to 16-bit fields in SOF markers. Therefore259* "unsigned int" is sufficient on all machines. However, if you need to260* handle larger images and you don't mind deviating from the spec, you261* can change this datatype.262*/263264typedef unsigned int JDIMENSION;265266#define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */267268269/* These macros are used in all function definitions and extern declarations.270* You could modify them if you need to change function linkage conventions;271* in particular, you'll need to do that to make the library a Windows DLL.272* Another application is to make all functions global for use with debuggers273* or code profilers that require it.274*/275276/* a function called through method pointers: */277#define METHODDEF(type) static type278/* a function used only in its module: */279#define LOCAL(type) static type280/* a function referenced thru EXTERNs: */281#define GLOBAL(type) type282/* a reference to a GLOBAL function: */283#define EXTERN(type) extern type284285286/* This macro is used to declare a "method", that is, a function pointer.287* We want to supply prototype parameters if the compiler can cope.288* Note that the arglist parameter must be parenthesized!289* Again, you can customize this if you need special linkage keywords.290*/291292#ifdef HAVE_PROTOTYPES293#define JMETHOD(type,methodname,arglist) type (*methodname) arglist294#else295#define JMETHOD(type,methodname,arglist) type (*methodname) ()296#endif297298299/* The noreturn type identifier is used to declare functions300* which cannot return.301* Compilers can thus create more optimized code and perform302* better checks for warnings and errors.303* Static analyzer tools can make improved inferences about304* execution paths and are prevented from giving false alerts.305*306* Unfortunately, the proposed specifications of corresponding307* extensions in the Dec 2011 ISO C standard revision (C11),308* GCC, MSVC, etc. are not viable.309* Thus we introduce a user defined type to declare noreturn310* functions at least for clarity. A proper compiler would311* have a suitable noreturn type to match in place of void.312*/313314#ifndef HAVE_NORETURN_T315typedef void noreturn_t;316#endif317318319/* Here is the pseudo-keyword for declaring pointers that must be "far"320* on 80x86 machines. Most of the specialized coding for 80x86 is handled321* by just saying "FAR *" where such a pointer is needed. In a few places322* explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.323*/324325#ifndef FAR326#ifdef NEED_FAR_POINTERS327#define FAR far328#else329#define FAR330#endif331#endif332333334/*335* On a few systems, type boolean and/or its values FALSE, TRUE may appear336* in standard header files. Or you may have conflicts with application-337* specific header files that you want to include together with these files.338* Defining HAVE_BOOLEAN before including jpeglib.h should make it work.339*/340341#ifndef HAVE_BOOLEAN342#if defined FALSE || defined TRUE || defined QGLOBAL_H343/* Qt3 defines FALSE and TRUE as "const" variables in qglobal.h */344typedef int boolean;345#ifndef FALSE /* in case these macros already exist */346#define FALSE 0 /* values of boolean */347#endif348#ifndef TRUE349#define TRUE 1350#endif351#else352typedef enum { FALSE = 0, TRUE = 1 } boolean;353#endif354#endif355356357/*358* The remaining options affect code selection within the JPEG library,359* but they don't need to be visible to most applications using the library.360* To minimize application namespace pollution, the symbols won't be361* defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.362*/363364#ifdef JPEG_INTERNALS365#define JPEG_INTERNAL_OPTIONS366#endif367368#ifdef JPEG_INTERNAL_OPTIONS369370371/*372* These defines indicate whether to include various optional functions.373* Undefining some of these symbols will produce a smaller but less capable374* library. Note that you can leave certain source files out of the375* compilation/linking process if you've #undef'd the corresponding symbols.376* (You may HAVE to do that if your compiler doesn't like null source files.)377*/378379/* Capability options common to encoder and decoder: */380381#define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */382#define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */383#define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */384385/* Encoder capability options: */386387#define C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */388#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */389#define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN) */390#define DCT_SCALING_SUPPORTED /* Input rescaling via DCT? (Requires DCT_ISLOW) */391#define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */392/* Note: if you selected more than 8-bit data precision, it is dangerous to393* turn off ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only394* good for 8-bit precision, so arithmetic coding is recommended for higher395* precision. The Huffman encoder normally uses entropy optimization to396* compute usable tables for higher precision. Otherwise, you'll have to397* supply different default Huffman tables.398* The exact same statements apply for progressive JPEG: the default tables399* don't work for progressive mode. (This may get fixed, however.)400*/401#define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */402403/* Decoder capability options: */404405#define D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */406#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */407#define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN) */408#define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? (Requires DCT_ISLOW) */409#define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */410#define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */411#undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */412#define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */413#define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */414#define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */415416/* more capability options later, no doubt */417418419/*420* Ordering of RGB data in scanlines passed to or from the application.421* If your application wants to deal with data in the order B,G,R, just422* #define JPEG_USE_RGB_CUSTOM in jconfig.h, or define your own custom423* order in jconfig.h and #define JPEG_HAVE_RGB_CUSTOM.424* You can also deal with formats such as R,G,B,X (one extra byte per pixel)425* by changing RGB_PIXELSIZE.426* Note that changing the offsets will also change427* the order in which colormap data is organized.428* RESTRICTIONS:429* 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.430* 2. The color quantizer modules will not behave desirably if RGB_PIXELSIZE431* is not 3 (they don't understand about dummy color components!).432* So you can't use color quantization if you change that value.433*/434435#ifndef JPEG_HAVE_RGB_CUSTOM436#ifdef JPEG_USE_RGB_CUSTOM437#define RGB_RED 2 /* Offset of Red in an RGB scanline element */438#define RGB_GREEN 1 /* Offset of Green */439#define RGB_BLUE 0 /* Offset of Blue */440#else441#define RGB_RED 0 /* Offset of Red in an RGB scanline element */442#define RGB_GREEN 1 /* Offset of Green */443#define RGB_BLUE 2 /* Offset of Blue */444#endif445#define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */446#endif447448449/* Definitions for speed-related optimizations. */450451452/* If your compiler supports inline functions, define INLINE453* as the inline keyword; otherwise define it as empty.454*/455456#ifndef INLINE457#ifdef __GNUC__ /* for instance, GNU C knows about inline */458#define INLINE __inline__459#endif460#ifndef INLINE461#define INLINE /* default is to define it as empty */462#endif463#endif464465466/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying467* two 16-bit shorts is faster than multiplying two ints. Define MULTIPLIER468* as short on such a machine. MULTIPLIER must be at least 16 bits wide.469*/470471#ifndef MULTIPLIER472#define MULTIPLIER int /* type for fastest integer multiply */473#endif474475476/* FAST_FLOAT should be either float or double, whichever is done faster477* by your compiler. (Note that this type is only used in the floating point478* DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)479* Typically, float is faster in ANSI C compilers, while double is faster in480* pre-ANSI compilers (because they insist on converting to double anyway).481* The code below therefore chooses float if we have ANSI-style prototypes.482*/483484#ifndef FAST_FLOAT485#ifdef HAVE_PROTOTYPES486#define FAST_FLOAT float487#else488#define FAST_FLOAT double489#endif490#endif491492#endif /* JPEG_INTERNAL_OPTIONS */493494495