1 /* 2 * Small jpeg decoder library (Internal header) 3 * 4 * Copyright (c) 2006, Luc Saillard <luc@saillard.org> 5 * Copyright (c) 2012 Intel Corporation. 6 * All rights reserved. 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions are met: 9 * 10 * - Redistributions of source code must retain the above copyright notice, 11 * this list of conditions and the following disclaimer. 12 * 13 * - Redistributions in binary form must reproduce the above copyright notice, 14 * this list of conditions and the following disclaimer in the documentation 15 * and/or other materials provided with the distribution. 16 * 17 * - Neither the name of the author nor the names of its contributors may be 18 * used to endorse or promote products derived from this software without 19 * specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 * 33 */ 34 35 36 #ifndef __TINYJPEG_INTERNAL_H_ 37 #define __TINYJPEG_INTERNAL_H_ 38 39 #include <setjmp.h> 40 41 #define SANITY_CHECK 1 42 43 struct jdec_private; 44 45 #define HUFFMAN_BITS_SIZE 256 46 47 #define HUFFMAN_TABLES 4 48 #define COMPONENTS 4 49 #define JPEG_MAX_WIDTH 2048 50 #define JPEG_MAX_HEIGHT 2048 51 #define JPEG_SCAN_MAX 4 52 53 enum std_markers { 54 DQT = 0xDB, /* Define Quantization Table */ 55 SOF = 0xC0, /* Start of Frame (size information) */ 56 DHT = 0xC4, /* Huffman Table */ 57 SOI = 0xD8, /* Start of Image */ 58 SOS = 0xDA, /* Start of Scan */ 59 RST = 0xD0, /* Reset Marker d0 -> .. */ 60 RST7 = 0xD7, /* Reset Marker .. -> d7 */ 61 EOI = 0xD9, /* End of Image */ 62 DRI = 0xDD, /* Define Restart Interval */ 63 APP0 = 0xE0, 64 }; 65 66 67 struct huffman_table 68 { 69 /*bits and values*/ 70 unsigned char bits[16]; 71 unsigned char values[256]; 72 }; 73 74 struct component 75 { 76 unsigned int Hfactor; 77 unsigned int Vfactor; 78 unsigned char quant_table_index; 79 unsigned int cid; 80 }; 81 82 83 typedef void (*decode_MCU_fct) (struct jdec_private *priv); 84 typedef void (*convert_colorspace_fct) (struct jdec_private *priv); 85 86 struct jpeg_sos 87 { 88 unsigned int nr_components; 89 struct { 90 unsigned int component_id; 91 unsigned int dc_selector; 92 unsigned int ac_selector; 93 }components[4]; 94 }; 95 96 struct jdec_private 97 { 98 /* Public variables */ 99 unsigned int width[JPEG_SCAN_MAX], height[JPEG_SCAN_MAX]; /* Size of the image */ 100 101 /* Private variables */ 102 const unsigned char *stream_begin, *stream_end,*stream_scan; 103 unsigned int stream_length; 104 105 const unsigned char *stream; /* Pointer to the current stream */ 106 107 struct component component_infos[COMPONENTS]; 108 unsigned int nf_components; 109 unsigned char Q_tables[COMPONENTS][64]; /* quantization tables, zigzag*/ 110 unsigned char Q_tables_valid[COMPONENTS]; 111 struct huffman_table HTDC[HUFFMAN_TABLES]; /* DC huffman tables */ 112 unsigned char HTDC_valid[HUFFMAN_TABLES]; 113 struct huffman_table HTAC[HUFFMAN_TABLES]; /* AC huffman tables */ 114 unsigned char HTAC_valid[HUFFMAN_TABLES]; 115 struct jpeg_sos cur_sos; /* current sos values*/ 116 int default_huffman_table_initialized; 117 int restart_interval; 118 }; 119 120 #endif 121 122