home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / jlib / jdct.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-16  |  5.9 KB  |  143 lines

  1. //-------------------------------------------------------------------------//
  2. //          Windows Graphics Programming: Win32 GDI and DirectDraw         //
  3. //                        ISBN  0-13-086985-6                              //
  4. //                                                                         //
  5. //  Modified by: Yuan, Feng                             www.fengyuan.com   //
  6. //  Changes    : C++, exception, in-memory source, BGR byte order          //
  7. //  Version    : 1.00.000, May 31, 2000                                    //
  8. //-------------------------------------------------------------------------//
  9.  
  10. /*
  11.  * jdct.h
  12.  *
  13.  * Copyright (C) 1994-1996, Thomas G. Lane.
  14.  * This file is part of the Independent JPEG Group's software.
  15.  * For conditions of distribution and use, see the accompanying README file.
  16.  *
  17.  * This include file contains common declarations for the forward and
  18.  * inverse DCT modules.  These declarations are private to the DCT managers
  19.  * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
  20.  * The individual DCT algorithms are kept in separate files to ease 
  21.  * machine-dependent tuning (e.g., assembly coding).
  22.  */
  23.  
  24.  
  25. /*
  26.  * A forward DCT routine is given a pointer to a work area of type DCTELEM[];
  27.  * the DCT is to be performed in-place in that buffer.  Type DCTELEM is int
  28.  * for 8-bit samples, INT32 for 12-bit samples.  (NOTE: Floating-point DCT
  29.  * implementations use an array of type FAST_FLOAT, instead.)
  30.  * The DCT inputs are expected to be signed (range +-CENTERJSAMPLE).
  31.  * The DCT outputs are returned scaled up by a factor of 8; they therefore
  32.  * have a range of +-8K for 8-bit data, +-128K for 12-bit data.  This
  33.  * convention improves accuracy in integer implementations and saves some
  34.  * work in floating-point ones.
  35.  * Quantization of the output coefficients is done by jcdctmgr.c.
  36.  */
  37.  
  38. #if BITS_IN_JSAMPLE == 8
  39. typedef int DCTELEM;        /* 16 or 32 bits is fine */
  40. #else
  41. typedef long DCTELEM;        /* must have 32 bits */
  42. #endif
  43.  
  44. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  45. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  46.  
  47.  
  48. /*
  49.  * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
  50.  * to an output sample array.  The routine must dequantize the input data as
  51.  * well as perform the IDCT; for dequantization, it uses the multiplier table
  52.  * pointed to by compptr->dct_table.  The output data is to be placed into the
  53.  * sample array starting at a specified column.  (Any row offset needed will
  54.  * be applied to the array pointer before it is passed to the IDCT code.)
  55.  * Note that the number of samples emitted by the IDCT routine is
  56.  * DCT_scaled_size * DCT_scaled_size.
  57.  */
  58.  
  59. /* typedef inverse_DCT_method_ptr is declared in jpegint.h */
  60.  
  61. /*
  62.  * Each IDCT routine has its own ideas about the best dct_table element type.
  63.  */
  64.  
  65. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  66. #if BITS_IN_JSAMPLE == 8
  67. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  68. #define IFAST_SCALE_BITS  2    /* fractional bits in scale factors */
  69. #else
  70. typedef long IFAST_MULT_TYPE;    /* need 32 bits for scaled quantizers */
  71. #define IFAST_SCALE_BITS  13    /* fractional bits in scale factors */
  72. #endif
  73. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  74.  
  75.  
  76. /*
  77.  * Each IDCT routine is responsible for range-limiting its results and
  78.  * converting them to unsigned form (0..MAXJSAMPLE).  The raw outputs could
  79.  * be quite far out of range if the input data is corrupt, so a bulletproof
  80.  * range-limiting step is required.  We use a mask-and-table-lookup method
  81.  * to do the combined operations quickly.  See the comments with
  82.  * prepare_range_limit_table (in jdmaster.c) for more info.
  83.  */
  84.  
  85. #define IDCT_range_limit(cinfo)  ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  86.  
  87. #define RANGE_MASK  (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  88.  
  89.  
  90. /* Extern declarations for the forward and inverse DCT routines. */
  91.  
  92. void jpeg_fdct_islow (DCTELEM * data);
  93. void jpeg_fdct_ifast (DCTELEM * data);
  94. void jpeg_fdct_float (FAST_FLOAT * data);
  95.  
  96. void jpeg_idct_islow
  97.     (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  98.      JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
  99. void jpeg_idct_ifast
  100.     (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  101.      JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
  102. void jpeg_idct_float
  103.     (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  104.      JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
  105. void jpeg_idct_4x4
  106.     (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  107.      JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
  108. void jpeg_idct_2x2
  109.     (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  110.      JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
  111. void jpeg_idct_1x1
  112.     (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  113.      JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col);
  114.  
  115.  
  116. /*
  117.  * Macros for handling fixed-point arithmetic; these are used by many
  118.  * but not all of the DCT/IDCT modules.
  119.  *
  120.  * All values are expected to be of type INT32.
  121.  * Fractional constants are scaled left by CONST_BITS bits.
  122.  * CONST_BITS is defined within each module using these macros,
  123.  * and may differ from one module to the next.
  124.  */
  125.  
  126. #define ONE    ((long) 1)
  127. #define CONST_SCALE (ONE << CONST_BITS)
  128.  
  129. /* Convert a positive real constant to an integer scaled by CONST_SCALE.
  130.  * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
  131.  * thus causing a lot of useless floating-point operations at run time.
  132.  */
  133.  
  134. #define FIX(x)    ((long) ((x) * CONST_SCALE + 0.5))
  135.  
  136. /* Descale and correctly round an INT32 value that's scaled by N bits.
  137.  * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
  138.  * the fudge factor is correct for either sign of X.
  139.  */
  140.  
  141. #define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  142.  
  143.