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 /*bits and values*/ 69 unsigned char bits[16]; 70 unsigned char values[256]; 71 }; 72 73 struct component { 74 unsigned int Hfactor; 75 unsigned int Vfactor; 76 unsigned char quant_table_index; 77 unsigned int cid; 78 }; 79 80 81 typedef void (*decode_MCU_fct)(struct jdec_private *priv); 82 typedef void (*convert_colorspace_fct)(struct jdec_private *priv); 83 84 struct jpeg_sos { 85 unsigned int nr_components; 86 struct { 87 unsigned int component_id; 88 unsigned int dc_selector; 89 unsigned int ac_selector; 90 } components[COMPONENTS]; 91 }; 92 93 struct jdec_private { 94 /* Public variables */ 95 unsigned int width[JPEG_SCAN_MAX], height[JPEG_SCAN_MAX]; /* Size of the image */ 96 97 /* Private variables */ 98 const unsigned char *stream_begin, *stream_end, *stream_scan; 99 unsigned int stream_length; 100 101 const unsigned char *stream; /* Pointer to the current stream */ 102 103 struct component component_infos[COMPONENTS]; 104 unsigned int nf_components; 105 unsigned char Q_tables[COMPONENTS][64]; /* quantization tables, zigzag*/ 106 unsigned char Q_tables_valid[COMPONENTS]; 107 struct huffman_table HTDC[HUFFMAN_TABLES]; /* DC huffman tables */ 108 unsigned char HTDC_valid[HUFFMAN_TABLES]; 109 struct huffman_table HTAC[HUFFMAN_TABLES]; /* AC huffman tables */ 110 unsigned char HTAC_valid[HUFFMAN_TABLES]; 111 struct jpeg_sos cur_sos; /* current sos values*/ 112 int default_huffman_table_initialized; 113 int restart_interval; 114 }; 115 116 #endif 117 118