deps/jpeg-6b -> jpeg-9a
[sdk] / deps / jpeg-9a / jpeglib.h
similarity index 90%
rename from deps/jpeg-6b/jpeglib.h
rename to deps/jpeg-9a/jpeglib.h
index d1be8dd..f4fbf23 100644 (file)
@@ -2,6 +2,7 @@
  * jpeglib.h
  *
  * Copyright (C) 1991-1998, Thomas G. Lane.
+ * Modified 2002-2013 by Guido Vollbeding.
  * This file is part of the Independent JPEG Group's software.
  * For conditions of distribution and use, see the accompanying README file.
  *
 #include "jmorecfg.h"          /* seldom changed options */
 
 
-/* Version ID for the JPEG library.
- * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
+#ifdef __cplusplus
+#ifndef DONT_USE_EXTERN_C
+extern "C" {
+#endif
+#endif
+
+/* Version IDs for the JPEG library.
+ * Might be useful for tests like "#if JPEG_LIB_VERSION >= 90".
  */
 
-#define JPEG_LIB_VERSION  62   /* Version 6b */
+#define JPEG_LIB_VERSION        90     /* Compatibility version 9.0 */
+#define JPEG_LIB_VERSION_MAJOR  9
+#define JPEG_LIB_VERSION_MINOR  1
 
 
 /* Various constants determining the sizes of things.
- * All of these are specified by the JPEG standard, so don't change them
- * if you want to be compatible.
+ * All of these are specified by the JPEG standard,
+ * so don't change them if you want to be compatible.
  */
 
-#define DCTSIZE                    8   /* The basic DCT block is 8x8 samples */
+#define DCTSIZE                    8   /* The basic DCT block is 8x8 coefficients */
 #define DCTSIZE2           64  /* DCTSIZE squared; # of elements in a block */
 #define NUM_QUANT_TBLS      4  /* Quantization tables are numbered 0..3 */
 #define NUM_HUFF_TBLS       4  /* Huffman tables are numbered 0..3 */
@@ -138,33 +147,38 @@ typedef struct {
    */
   JDIMENSION width_in_blocks;
   JDIMENSION height_in_blocks;
-  /* Size of a DCT block in samples.  Always DCTSIZE for compression.
-   * For decompression this is the size of the output from one DCT block,
-   * reflecting any scaling we choose to apply during the IDCT step.
-   * Values of 1,2,4,8 are likely to be supported.  Note that different
-   * components may receive different IDCT scalings.
+  /* Size of a DCT block in samples,
+   * reflecting any scaling we choose to apply during the DCT step.
+   * Values from 1 to 16 are supported.
+   * Note that different components may receive different DCT scalings.
    */
-  int DCT_scaled_size;
+  int DCT_h_scaled_size;
+  int DCT_v_scaled_size;
   /* The downsampled dimensions are the component's actual, unpadded number
-   * of samples at the main buffer (preprocessing/compression interface), thus
-   * downsampled_width = ceil(image_width * Hi/Hmax)
-   * and similarly for height.  For decompression, IDCT scaling is included, so
-   * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
+   * of samples at the main buffer (preprocessing/compression interface);
+   * DCT scaling is included, so
+   * downsampled_width =
+   *   ceil(image_width * Hi/Hmax * DCT_h_scaled_size/block_size)
+   * and similarly for height.
    */
   JDIMENSION downsampled_width;         /* actual width in samples */
   JDIMENSION downsampled_height; /* actual height in samples */
-  /* This flag is used only for decompression.  In cases where some of the
-   * components will be ignored (eg grayscale output from YCbCr image),
-   * we can skip most computations for the unused components.
+  /* For decompression, in cases where some of the components will be
+   * ignored (eg grayscale output from YCbCr image), we can skip most
+   * computations for the unused components.
+   * For compression, some of the components will need further quantization
+   * scale by factor of 2 after DCT (eg BG_YCC output from normal RGB input).
+   * The field is first set TRUE for decompression, FALSE for compression
+   * in initial_setup, and then adapted in color conversion setup.
    */
-  boolean component_needed;    /* do we need the value of this component? */
+  boolean component_needed;
 
   /* These values are computed before starting a scan of the component. */
   /* The decompressor output side may not use these variables. */
   int MCU_width;               /* number of blocks per MCU, horizontally */
   int MCU_height;              /* number of blocks per MCU, vertically */
   int MCU_blocks;              /* MCU_width * MCU_height */
-  int MCU_sample_width;                /* MCU width in samples, MCU_width*DCT_scaled_size */
+  int MCU_sample_width;        /* MCU width in samples: MCU_width * DCT_h_scaled_size */
   int last_col_width;          /* # of non-dummy blocks across in last MCU */
   int last_row_height;         /* # of non-dummy blocks down in last MCU */
 
@@ -206,12 +220,21 @@ struct jpeg_marker_struct {
 typedef enum {
        JCS_UNKNOWN,            /* error/unspecified */
        JCS_GRAYSCALE,          /* monochrome */
-       JCS_RGB,                /* red/green/blue */
-       JCS_YCbCr,              /* Y/Cb/Cr (also known as YUV) */
+       JCS_RGB,                /* red/green/blue, standard RGB (sRGB) */
+       JCS_YCbCr,              /* Y/Cb/Cr (also known as YUV), standard YCC */
        JCS_CMYK,               /* C/M/Y/K */
-       JCS_YCCK                /* Y/Cb/Cr/K */
+       JCS_YCCK,               /* Y/Cb/Cr/K */
+       JCS_BG_RGB,             /* big gamut red/green/blue, bg-sRGB */
+       JCS_BG_YCC              /* big gamut Y/Cb/Cr, bg-sYCC */
 } J_COLOR_SPACE;
 
+/* Supported color transforms. */
+
+typedef enum {
+       JCT_NONE           = 0,
+       JCT_SUBTRACT_GREEN = 1
+} J_COLOR_TRANSFORM;
+
 /* DCT/IDCT algorithm options. */
 
 typedef enum {
@@ -291,6 +314,17 @@ struct jpeg_compress_struct {
    * helper routines to simplify changing parameters.
    */
 
+  unsigned int scale_num, scale_denom; /* fraction by which to scale image */
+
+  JDIMENSION jpeg_width;       /* scaled JPEG image width */
+  JDIMENSION jpeg_height;      /* scaled JPEG image height */
+  /* Dimensions of actual JPEG image that will be written to file,
+   * derived from input dimensions by scaling factors above.
+   * These fields are computed by jpeg_start_compress().
+   * You can also use jpeg_calc_jpeg_dimensions() to determine these values
+   * in advance of calling jpeg_start_compress().
+   */
+
   int data_precision;          /* bits of precision in image data */
 
   int num_components;          /* # of color components in JPEG image */
@@ -298,14 +332,17 @@ struct jpeg_compress_struct {
 
   jpeg_component_info * comp_info;
   /* comp_info[i] describes component that appears i'th in SOF */
-  
+
   JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
-  /* ptrs to coefficient quantization tables, or NULL if not defined */
-  
+  int q_scale_factor[NUM_QUANT_TBLS];
+  /* ptrs to coefficient quantization tables, or NULL if not defined,
+   * and corresponding scale factors (percentage, initialized 100).
+   */
+
   JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
   JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
   /* ptrs to Huffman coding tables, or NULL if not defined */
-  
+
   UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
   UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
   UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
@@ -321,6 +358,7 @@ struct jpeg_compress_struct {
   boolean arith_code;          /* TRUE=arithmetic coding, FALSE=Huffman */
   boolean optimize_coding;     /* TRUE=optimize entropy encoding parms */
   boolean CCIR601_sampling;    /* TRUE=first samples are cosited */
+  boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */
   int smoothing_factor;                /* 1..100, or 0 for no input smoothing */
   J_DCT_METHOD dct_method;     /* DCT algorithm selector */
 
@@ -345,7 +383,10 @@ struct jpeg_compress_struct {
   UINT16 X_density;            /* Horizontal pixel density */
   UINT16 Y_density;            /* Vertical pixel density */
   boolean write_Adobe_marker;  /* should an Adobe marker be written? */
-  
+
+  J_COLOR_TRANSFORM color_transform;
+  /* Color transform identifier, writes LSE marker if nonzero */
+
   /* State variable: index of next scanline to be written to
    * jpeg_write_scanlines().  Application may use this to control its
    * processing loop, e.g., "while (next_scanline < image_height)".
@@ -364,6 +405,9 @@ struct jpeg_compress_struct {
   int max_h_samp_factor;       /* largest h_samp_factor */
   int max_v_samp_factor;       /* largest v_samp_factor */
 
+  int min_DCT_h_scaled_size;   /* smallest DCT_h_scaled_size of any component */
+  int min_DCT_v_scaled_size;   /* smallest DCT_v_scaled_size of any component */
+
   JDIMENSION total_iMCU_rows;  /* # of iMCU rows to be input to coef ctlr */
   /* The coefficient controller receives data in units of MCU rows as defined
    * for fully interleaved scans (whether the JPEG file is interleaved or not).
@@ -389,6 +433,10 @@ struct jpeg_compress_struct {
 
   int Ss, Se, Ah, Al;          /* progressive JPEG parameters for scan */
 
+  int block_size;              /* the basic DCT block size: 1..16 */
+  const int * natural_order;   /* natural-order position array */
+  int lim_Se;                  /* min( Se, DCTSIZE2-1 ) */
+
   /*
    * Links to compression subobjects (methods and private variables of modules)
    */
@@ -535,6 +583,7 @@ struct jpeg_decompress_struct {
   jpeg_component_info * comp_info;
   /* comp_info[i] describes component that appears i'th in SOF */
 
+  boolean is_baseline;         /* TRUE if Baseline SOF0 encountered */
   boolean progressive_mode;    /* TRUE if SOFn specifies progressive mode */
   boolean arith_code;          /* TRUE=arithmetic coding, FALSE=Huffman */
 
@@ -557,6 +606,9 @@ struct jpeg_decompress_struct {
   boolean saw_Adobe_marker;    /* TRUE iff an Adobe APP14 marker was found */
   UINT8 Adobe_transform;       /* Color transform code from Adobe marker */
 
+  J_COLOR_TRANSFORM color_transform;
+  /* Color transform identifier derived from LSE marker, otherwise zero */
+
   boolean CCIR601_sampling;    /* TRUE=first samples are cosited */
 
   /* Aside from the specific data retained from APPn markers known to the
@@ -575,7 +627,8 @@ struct jpeg_decompress_struct {
   int max_h_samp_factor;       /* largest h_samp_factor */
   int max_v_samp_factor;       /* largest v_samp_factor */
 
-  int min_DCT_scaled_size;     /* smallest DCT_scaled_size of any component */
+  int min_DCT_h_scaled_size;   /* smallest DCT_h_scaled_size of any component */
+  int min_DCT_v_scaled_size;   /* smallest DCT_v_scaled_size of any component */
 
   JDIMENSION total_iMCU_rows;  /* # of iMCU rows in image */
   /* The coefficient controller's input and output progress is measured in
@@ -583,7 +636,7 @@ struct jpeg_decompress_struct {
    * in fully interleaved JPEG scans, but are used whether the scan is
    * interleaved or not.  We define an iMCU row as v_samp_factor DCT block
    * rows of each component.  Therefore, the IDCT output contains
-   * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.
+   * v_samp_factor*DCT_v_scaled_size sample rows of a component per iMCU row.
    */
 
   JSAMPLE * sample_range_limit; /* table for fast range-limiting */
@@ -607,6 +660,12 @@ struct jpeg_decompress_struct {
 
   int Ss, Se, Ah, Al;          /* progressive JPEG parameters for scan */
 
+  /* These fields are derived from Se of first SOS marker.
+   */
+  int block_size;              /* the basic DCT block size: 1..16 */
+  const int * natural_order; /* natural-order position array for entropy decode */
+  int lim_Se;                  /* min( Se, DCTSIZE2-1 ) for entropy decode */
+
   /* This field is shared between entropy decoder and marker parser.
    * It is either zero or the code of a JPEG marker that has been
    * read from the data source, but has not yet been processed.
@@ -642,7 +701,7 @@ struct jpeg_decompress_struct {
 
 struct jpeg_error_mgr {
   /* Error exit handler: does not return to caller */
-  JMETHOD(void, error_exit, (j_common_ptr cinfo));
+  JMETHOD(noreturn_t, error_exit, (j_common_ptr cinfo));
   /* Conditionally emit a trace or warning message */
   JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
   /* Routine that actually outputs a trace or error message */
@@ -836,11 +895,14 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
 #define jpeg_destroy_decompress        jDestDecompress
 #define jpeg_stdio_dest                jStdDest
 #define jpeg_stdio_src         jStdSrc
+#define jpeg_mem_dest          jMemDest
+#define jpeg_mem_src           jMemSrc
 #define jpeg_set_defaults      jSetDefaults
 #define jpeg_set_colorspace    jSetColorspace
 #define jpeg_default_colorspace        jDefColorspace
 #define jpeg_set_quality       jSetQuality
 #define jpeg_set_linear_quality        jSetLQuality
+#define jpeg_default_qtables   jDefQTables
 #define jpeg_add_quant_table   jAddQuantTable
 #define jpeg_quality_scaling   jQualityScaling
 #define jpeg_simple_progression        jSimProgress
@@ -850,6 +912,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
 #define jpeg_start_compress    jStrtCompress
 #define jpeg_write_scanlines   jWrtScanlines
 #define jpeg_finish_compress   jFinCompress
+#define jpeg_calc_jpeg_dimensions      jCjpegDimensions
 #define jpeg_write_raw_data    jWrtRawData
 #define jpeg_write_marker      jWrtMarker
 #define jpeg_write_m_header    jWrtMHeader
@@ -866,6 +929,7 @@ typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
 #define jpeg_input_complete    jInComplete
 #define jpeg_new_colormap      jNewCMap
 #define jpeg_consume_input     jConsumeInput
+#define jpeg_core_output_dimensions    jCoreDimensions
 #define jpeg_calc_output_dimensions    jCalcDimensions
 #define jpeg_save_markers      jSaveMarkers
 #define jpeg_set_marker_processor      jSetMarker
@@ -910,6 +974,14 @@ EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
 EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
 EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
 
+/* Data source and destination managers: memory buffers. */
+EXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,
+                              unsigned char ** outbuffer,
+                              unsigned long * outsize));
+EXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,
+                             unsigned char * inbuffer,
+                             unsigned long insize));
+
 /* Default parameter setup for compression */
 EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
 /* Compression parameter setup aids */
@@ -921,6 +993,8 @@ EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
 EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
                                          int scale_factor,
                                          boolean force_baseline));
+EXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo,
+                                      boolean force_baseline));
 EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
                                       const unsigned int *basic_table,
                                       int scale_factor,
@@ -940,12 +1014,15 @@ EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
                                             JDIMENSION num_lines));
 EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
 
+/* Precalculate JPEG dimensions for current compression parameters. */
+EXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo));
+
 /* Replaces jpeg_write_scanlines when writing raw downsampled data. */
 EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
                                            JSAMPIMAGE data,
                                            JDIMENSION num_lines));
 
-/* Write a special marker.  See libjpeg.doc concerning safe usage. */
+/* Write a special marker.  See libjpeg.txt concerning safe usage. */
 EXTERN(void) jpeg_write_marker
        JPP((j_compress_ptr cinfo, int marker,
             const JOCTET * dataptr, unsigned int datalen));
@@ -999,6 +1076,7 @@ EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
 #define JPEG_SCAN_COMPLETED    4 /* Completed last iMCU row of a scan */
 
 /* Precalculate output dimensions for current decompression parameters. */
+EXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo));
 EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
 
 /* Control saving of COM and APPn markers into marker_list. */
@@ -1093,4 +1171,10 @@ struct jpeg_color_quantizer { long dummy; };
 #include "jerror.h"            /* fetch error codes too */
 #endif
 
+#ifdef __cplusplus
+#ifndef DONT_USE_EXTERN_C
+}
+#endif
+#endif
+
 #endif /* JPEGLIB_H */