home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / gfx / edit / tsmorph / jpeg_ls / jpegdata.h < prev    next >
C/C++ Source or Header  |  1993-12-21  |  40KB  |  946 lines

  1. // Source code changed to allow GIF read etc to be used as JPEG read code
  2.  
  3. /*
  4.  * jpegdata.h
  5.  *
  6.  * Copyright (C) 1991, 1992, Thomas G. Lane.
  7.  * This file is part of the Independent JPEG Group's software.
  8.  * For conditions of distribution and use, see the accompanying README file.
  9.  *
  10.  * This file defines shared data structures for the various JPEG modules.
  11.  */
  12.  
  13.  
  14. /*
  15.  * You might need to change some of the following declarations if you are
  16.  * using the JPEG software within a surrounding application program
  17.  * or porting it to an unusual system.
  18.  */
  19.  
  20.  
  21. /* If the source or destination of image data is not to be stdio streams,
  22.  * these types may need work.  You can replace them with some kind of
  23.  * pointer or indicator that is useful to you, or just ignore 'em.
  24.  * Note that the user interface and the various jrdxxx/jwrxxx modules
  25.  * will also need work for non-stdio input/output.
  26.  */
  27.  
  28. #ifdef AMIGA_IO
  29. typedef BPTR JFILEREF;
  30. typedef BPTR IFILEREF;
  31. #else
  32. typedef FILE * JFILEREF;    /* source or dest of JPEG-compressed data */
  33.  
  34. typedef FILE * IFILEREF;    /* source or dest of non-JPEG image data */
  35. #endif
  36.  
  37. /* These defines are used in all function definitions and extern declarations.
  38.  * You could modify them if you need to change function linkage conventions,
  39.  * as is shown below for use with C++.  Another application would be to make
  40.  * all functions global for use with code profilers that require it.
  41.  * NOTE: the C++ test does the right thing if you are reading this include
  42.  * file in a C++ application to link to JPEG code that's been compiled with a
  43.  * regular C compiler.  I'm not sure it works if you try to compile the JPEG
  44.  * code with C++.
  45.  */
  46.  
  47. #define METHODDEF static    /* a function called through method pointers */
  48. #define LOCAL      static    /* a function used only in its module */
  49. #define GLOBAL            /* a function referenced thru EXTERNs */
  50. #ifdef __cplusplus
  51. #define EXTERN      extern "C"    /* a reference to a GLOBAL function */
  52. #else
  53. #define EXTERN      extern    /* a reference to a GLOBAL function */
  54. #endif
  55.  
  56.  
  57. /* Here is the pseudo-keyword for declaring pointers that must be "far"
  58.  * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
  59.  * by just saying "FAR *" where such a pointer is needed.  In a few places
  60.  * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
  61.  */
  62.  
  63. #ifdef NEED_FAR_POINTERS
  64. #define FAR  far
  65. #else
  66. #define FAR
  67. #endif
  68.  
  69.  
  70.  
  71. /* The remaining declarations are not system-dependent, we hope. */
  72.  
  73.  
  74. /*
  75.  * NOTE: if you have an ancient, strict-K&R C compiler, it may choke on the
  76.  * similarly-named fields in Compress_info_struct and Decompress_info_struct.
  77.  * If this happens, you can get around it by rearranging the two structs so
  78.  * that the similarly-named fields appear first and in the same order in
  79.  * each struct.  Since such compilers are now pretty rare, we haven't done
  80.  * this in the portable code, preferring to maintain a logical ordering.
  81.  */
  82.  
  83.  
  84.  
  85. /* This macro is used to declare a "method", that is, a function pointer. */
  86. /* We want to supply prototype parameters if the compiler can cope. */
  87. /* Note that the arglist parameter must be parenthesized! */
  88.  
  89. #ifdef PROTO
  90. #define METHOD(type,methodname,arglist)  type (*methodname) arglist
  91. #else
  92. #define METHOD(type,methodname,arglist)  type (*methodname) ()
  93. #endif
  94.  
  95. /* Forward references to lists of method pointers */
  96. typedef struct External_methods_struct * external_methods_ptr;
  97. typedef struct Compress_methods_struct * compress_methods_ptr;
  98. typedef struct Decompress_methods_struct * decompress_methods_ptr;
  99.  
  100.  
  101. /* Data structures for images containing either samples or coefficients. */
  102. /* Note that the topmost (leftmost) index is always color component. */
  103. /* On 80x86 machines, the image arrays are too big for near pointers, */
  104. /* but the pointer arrays can fit in near memory. */
  105.  
  106. typedef JSAMPLE FAR *JSAMPROW;    /* ptr to one image row of pixel samples. */
  107. typedef JSAMPROW *JSAMPARRAY;    /* ptr to some rows (a 2-D sample array) */
  108. typedef JSAMPARRAY *JSAMPIMAGE;    /* a 3-D sample array: top index is color */
  109.  
  110.  
  111. #define DCTSIZE        8    /* The basic DCT block is 8x8 samples */
  112. #define DCTSIZE2    64    /* DCTSIZE squared; # of elements in a block */
  113.  
  114. typedef JCOEF JBLOCK[DCTSIZE2];    /* one block of coefficients */
  115. typedef JBLOCK FAR *JBLOCKROW;    /* pointer to one row of coefficient blocks */
  116. typedef JBLOCKROW *JBLOCKARRAY;        /* a 2-D array of coefficient blocks */
  117. typedef JBLOCKARRAY *JBLOCKIMAGE;    /* a 3-D array of coefficient blocks */
  118.  
  119. typedef JCOEF FAR *JCOEFPTR;    /* useful in a couple of places */
  120.  
  121.  
  122. /* The input and output data of the DCT transform subroutines are of
  123.  * the following type, which need not be the same as JCOEF.
  124.  * For example, on a machine with fast floating point, it might make sense
  125.  * to recode the DCT routines to use floating point; then DCTELEM would be
  126.  * 'float' or 'double'.
  127.  */
  128.  
  129. typedef JCOEF DCTELEM;
  130. typedef DCTELEM DCTBLOCK[DCTSIZE2];
  131.  
  132.  
  133. /* Types for JPEG compression parameters and working tables. */
  134.  
  135.  
  136. typedef enum {            /* defines known color spaces */
  137.     CS_UNKNOWN,        /* error/unspecified */
  138.     CS_GRAYSCALE,        /* monochrome (only 1 component) */
  139.     CS_RGB,            /* red/green/blue */
  140.     CS_YCbCr,        /* Y/Cb/Cr (also known as YUV) */
  141.     CS_YIQ,            /* Y/I/Q */
  142.     CS_CMYK            /* C/M/Y/K */
  143. } COLOR_SPACE;
  144.  
  145.  
  146. typedef struct {        /* Basic info about one component */
  147.   /* These values are fixed over the whole image */
  148.   /* For compression, they must be supplied by the user interface; */
  149.   /* for decompression, they are read from the SOF marker. */
  150.     short component_id;    /* identifier for this component (0..255) */
  151.     short component_index;    /* its index in SOF or cinfo->comp_info[] */
  152.     short h_samp_factor;    /* horizontal sampling factor (1..4) */
  153.     short v_samp_factor;    /* vertical sampling factor (1..4) */
  154.     short quant_tbl_no;    /* quantization table selector (0..3) */
  155.   /* These values may vary between scans */
  156.   /* For compression, they must be supplied by the user interface; */
  157.   /* for decompression, they are read from the SOS marker. */
  158.     short dc_tbl_no;    /* DC entropy table selector (0..3) */
  159.     short ac_tbl_no;    /* AC entropy table selector (0..3) */
  160.   /* These values are computed during compression or decompression startup */
  161.     long true_comp_width;    /* component's image width in samples */
  162.     long true_comp_height;    /* component's image height in samples */
  163.     /* the above are the logical dimensions of the downsampled image */
  164.   /* These values are computed before starting a scan of the component */
  165.     short MCU_width;    /* number of blocks per MCU, horizontally */
  166.     short MCU_height;    /* number of blocks per MCU, vertically */
  167.     short MCU_blocks;    /* MCU_width * MCU_height */
  168.     long downsampled_width;    /* image width in samples, after expansion */
  169.     long downsampled_height; /* image height in samples, after expansion */
  170.     /* the above are the true_comp_xxx values rounded up to multiples of */
  171.     /* the MCU dimensions; these are the working dimensions of the array */
  172.     /* as it is passed through the DCT or IDCT step.  NOTE: these values */
  173.     /* differ depending on whether the component is interleaved or not!! */
  174. } jpeg_component_info;
  175.  
  176.  
  177. /* DCT coefficient quantization tables.
  178.  * For 8-bit precision, 'INT16' should be good enough for quantization values;
  179.  * for more precision, we go for the full 16 bits.  'INT16' provides a useful
  180.  * speedup on many machines (multiplication & division of JCOEFs by
  181.  * quantization values is a significant chunk of the runtime).
  182.  * Note: the values in a QUANT_TBL are always given in zigzag order.
  183.  */
  184. #ifdef EIGHT_BIT_SAMPLES
  185. typedef INT16 QUANT_VAL;    /* element of a quantization table */
  186. #else
  187. typedef UINT16 QUANT_VAL;    /* element of a quantization table */
  188. #endif
  189. typedef QUANT_VAL QUANT_TBL[DCTSIZE2];    /* A quantization table */
  190. typedef QUANT_VAL * QUANT_TBL_PTR;    /* pointer to same */
  191.  
  192.  
  193. typedef struct {        /* A Huffman coding table */
  194.   /* These two fields directly represent the contents of a JPEG DHT marker */
  195.     UINT8 bits[17];        /* bits[k] = # of symbols with codes of */
  196.                 /* length k bits; bits[0] is unused */
  197.     UINT8 huffval[256];    /* The symbols, in order of incr code length */
  198.   /* This field is used only during compression.  It's initialized FALSE when
  199.    * the table is created, and set TRUE when it's