nengel@0: /* nengel@0: * Small jpeg decoder library (Internal header) nengel@0: * nengel@0: * Copyright (c) 2006, Luc Saillard nengel@0: * All rights reserved. nengel@0: * Redistribution and use in source and binary forms, with or without nengel@0: * modification, are permitted provided that the following conditions are met: nengel@0: * nengel@0: * - Redistributions of source code must retain the above copyright notice, nengel@0: * this list of conditions and the following disclaimer. nengel@0: * nengel@0: * - Redistributions in binary form must reproduce the above copyright notice, nengel@0: * this list of conditions and the following disclaimer in the documentation nengel@0: * and/or other materials provided with the distribution. nengel@0: * nengel@0: * - Neither the name of the author nor the names of its contributors may be nengel@0: * used to endorse or promote products derived from this software without nengel@0: * specific prior written permission. nengel@0: * nengel@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" nengel@0: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE nengel@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE nengel@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE nengel@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR nengel@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF nengel@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS nengel@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN nengel@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) nengel@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE nengel@0: * POSSIBILITY OF SUCH DAMAGE. nengel@0: * nengel@0: */ nengel@0: nengel@0: #ifndef __TINYJPEG_INTERNAL_H_ nengel@0: #define __TINYJPEG_INTERNAL_H_ nengel@0: nengel@0: #define SANITY_CHECK 1 nengel@0: nengel@0: struct jdec_private; nengel@0: nengel@0: #define HUFFMAN_BITS_SIZE 256 nengel@0: #define HUFFMAN_HASH_NBITS 9 nengel@0: #define HUFFMAN_HASH_SIZE (1UL< .. */ nengel@0: RST7 = 0xD7, /* Reset Marker .. -> d7 */ nengel@0: EOI = 0xD9, /* End of Image */ nengel@0: DRI = 0xDD, /* Define Restart Interval */ nengel@0: APP0 = 0xE0, nengel@0: }; nengel@0: nengel@0: struct huffman_table nengel@0: { nengel@0: /* Fast look up table, using HUFFMAN_HASH_NBITS bits we can have directly the symbol, nengel@0: * if the symbol is <0, then we need to look into the tree table */ nengel@0: short int lookup[HUFFMAN_HASH_SIZE]; nengel@0: /* code size: give the number of bits of a symbol is encoded */ nengel@0: unsigned char code_size[HUFFMAN_HASH_SIZE]; nengel@0: /* some place to store value that is not encoded in the lookup table */ nengel@0: uint16_t slowtable[16-HUFFMAN_HASH_NBITS][256]; nengel@0: }; nengel@0: nengel@0: struct component nengel@0: { nengel@0: unsigned int Hfactor; nengel@0: unsigned int Vfactor; nengel@0: float *Q_table; /* Pointer to the quantisation table to use */ nengel@0: struct huffman_table *AC_table; nengel@0: struct huffman_table *DC_table; nengel@0: short int previous_DC; /* Previous DC coefficient */ nengel@0: short int DCT[64]; /* DCT coef */ nengel@0: #if SANITY_CHECK nengel@0: unsigned int cid; nengel@0: #endif nengel@0: }; nengel@0: nengel@0: typedef int (*decode_MCU_fct) (struct jdec_private *priv); nengel@0: typedef void (*convert_colorspace_fct) (struct jdec_private *priv); nengel@0: nengel@0: struct jdec_private nengel@0: { nengel@0: /* Public variables */ nengel@0: uint8_t *components[COMPONENTS]; nengel@0: unsigned int width, height; /* Size of the image */ nengel@0: unsigned int mcus_in_width, mcus_in_height; nengel@0: unsigned int mcus_posx, mcus_posy; nengel@0: unsigned int flags; nengel@0: nengel@0: /* Private variables */ nengel@0: const unsigned char *stream_begin, *stream_end; nengel@0: unsigned int stream_length; nengel@0: nengel@0: const unsigned char *stream; /* Pointer to the current stream */ nengel@0: unsigned int reservoir, nbits_in_reservoir; nengel@0: nengel@0: struct component component_infos[COMPONENTS]; nengel@0: float Q_tables[COMPONENTS][64]; /* quantization tables */ nengel@0: struct huffman_table HTDC[HUFFMAN_TABLES]; /* DC huffman tables */ nengel@0: struct huffman_table HTAC[HUFFMAN_TABLES]; /* AC huffman tables */ nengel@0: int default_huffman_table_initialized; nengel@0: unsigned int restart_interval; nengel@0: // int restarts_to_go; /* MCUs left in this restart interval */ nengel@0: int last_rst_marker_seen; /* Rst marker is incremented each time */ nengel@0: nengel@0: /* Temp space used after the IDCT to store each components */ nengel@0: uint8_t Y[64*4], Cr[64], Cb[64]; nengel@0: nengel@0: /* Internal Pointer use for colorspace conversion, do not modify it !!! */ nengel@0: uint8_t *plane; nengel@0: nengel@0: }; nengel@0: nengel@0: #if defined(__GNUC__) && (__GNUC__ > 3) && defined(__OPTIMIZE__) nengel@0: #define __likely(x) __builtin_expect(!!(x), 1) nengel@0: #define __unlikely(x) __builtin_expect(!!(x), 0) nengel@0: #else nengel@0: #define __likely(x) (x) nengel@0: #define __unlikely(x) (x) nengel@0: #endif nengel@0: nengel@0: #define IDCT tinyjpeg_idct_float nengel@0: void tinyjpeg_idct_float (struct component *compptr, uint8_t *output_buf, int stride); nengel@0: int parse_JFIF(struct jdec_private *priv, const unsigned char *stream); nengel@0: nengel@0: #endif nengel@0: