Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__jpeg_decoder__Proj
comparison VSs_tinyjpeg/tinyjpeg-internal.h @ 4:62350c40504f
running in sequential mode
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Mon, 20 Aug 2012 16:56:27 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:666217a1dc50 |
|---|---|
| 1 /* | |
| 2 * Small jpeg decoder library (Internal header) | |
| 3 * | |
| 4 * Copyright (c) 2006, Luc Saillard <luc@saillard.org> | |
| 5 * All rights reserved. | |
| 6 * Redistribution and use in source and binary forms, with or without | |
| 7 * modification, are permitted provided that the following conditions are met: | |
| 8 * | |
| 9 * - Redistributions of source code must retain the above copyright notice, | |
| 10 * this list of conditions and the following disclaimer. | |
| 11 * | |
| 12 * - Redistributions in binary form must reproduce the above copyright notice, | |
| 13 * this list of conditions and the following disclaimer in the documentation | |
| 14 * and/or other materials provided with the distribution. | |
| 15 * | |
| 16 * - Neither the name of the author nor the names of its contributors may be | |
| 17 * used to endorse or promote products derived from this software without | |
| 18 * specific prior written permission. | |
| 19 * | |
| 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
| 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
| 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
| 30 * POSSIBILITY OF SUCH DAMAGE. | |
| 31 * | |
| 32 */ | |
| 33 | |
| 34 #ifndef __TINYJPEG_INTERNAL_H_ | |
| 35 #define __TINYJPEG_INTERNAL_H_ | |
| 36 | |
| 37 #define SANITY_CHECK 1 | |
| 38 | |
| 39 struct jdec_private; | |
| 40 | |
| 41 #define HUFFMAN_BITS_SIZE 256 | |
| 42 #define HUFFMAN_HASH_NBITS 9 | |
| 43 #define HUFFMAN_HASH_SIZE (1UL<<HUFFMAN_HASH_NBITS) | |
| 44 #define HUFFMAN_HASH_MASK (HUFFMAN_HASH_SIZE-1) | |
| 45 | |
| 46 #define HUFFMAN_TABLES 4 | |
| 47 #define COMPONENTS 3 | |
| 48 | |
| 49 #define cY 0 | |
| 50 #define cCb 1 | |
| 51 #define cCr 2 | |
| 52 | |
| 53 #define BLACK_Y 0 | |
| 54 #define BLACK_U 127 | |
| 55 #define BLACK_V 127 | |
| 56 | |
| 57 #if DEBUG | |
| 58 #define trace(fmt, args...) do { \ | |
| 59 fprintf(stderr, fmt, ## args); \ | |
| 60 fflush(stderr); \ | |
| 61 } while(0) | |
| 62 #else | |
| 63 #define trace(fmt, args...) do { } while (0) | |
| 64 #endif | |
| 65 #define error(fmt, args...) do { \ | |
| 66 snprintf(error_string, sizeof(error_string), fmt, ## args); \ | |
| 67 return -1; \ | |
| 68 } while(0) | |
| 69 | |
| 70 #define be16_to_cpu(x) (((x)[0]<<8)|(x)[1]) | |
| 71 | |
| 72 enum std_markers { | |
| 73 DQT = 0xDB, /* Define Quantization Table */ | |
| 74 SOF = 0xC0, /* Start of Frame (size information) */ | |
| 75 DHT = 0xC4, /* Huffman Table */ | |
| 76 SOI = 0xD8, /* Start of Image */ | |
| 77 SOS = 0xDA, /* Start of Scan */ | |
| 78 RST = 0xD0, /* Reset Marker d0 -> .. */ | |
| 79 RST7 = 0xD7, /* Reset Marker .. -> d7 */ | |
| 80 EOI = 0xD9, /* End of Image */ | |
| 81 DRI = 0xDD, /* Define Restart Interval */ | |
| 82 APP0 = 0xE0, | |
| 83 }; | |
| 84 | |
| 85 struct huffman_table | |
| 86 { | |
| 87 /* Fast look up table, using HUFFMAN_HASH_NBITS bits we can have directly the symbol, | |
| 88 * if the symbol is <0, then we need to look into the tree table */ | |
| 89 short int lookup[HUFFMAN_HASH_SIZE]; | |
| 90 /* code size: give the number of bits of a symbol is encoded */ | |
| 91 unsigned char code_size[HUFFMAN_HASH_SIZE]; | |
| 92 /* some place to store value that is not encoded in the lookup table */ | |
| 93 uint16_t slowtable[16-HUFFMAN_HASH_NBITS][256]; | |
| 94 }; | |
| 95 | |
| 96 struct component | |
| 97 { | |
| 98 unsigned int Hfactor; | |
| 99 unsigned int Vfactor; | |
| 100 float *Q_table; /* Pointer to the quantisation table to use */ | |
| 101 struct huffman_table *AC_table; | |
| 102 struct huffman_table *DC_table; | |
| 103 short int previous_DC; /* Previous DC coefficient */ | |
| 104 short int DCT[64]; /* DCT coef */ | |
| 105 #if SANITY_CHECK | |
| 106 unsigned int cid; | |
| 107 #endif | |
| 108 }; | |
| 109 | |
| 110 typedef int (*decode_MCU_fct) (struct jdec_private *priv); | |
| 111 typedef void (*convert_colorspace_fct) (struct jdec_private *priv); | |
| 112 | |
| 113 struct jdec_private | |
| 114 { | |
| 115 /* Public variables */ | |
| 116 uint8_t *components[COMPONENTS]; | |
| 117 unsigned int width, height; /* Size of the image */ | |
| 118 unsigned int mcus_in_width, mcus_in_height; | |
| 119 unsigned int mcus_posx, mcus_posy; | |
| 120 unsigned int flags; | |
| 121 | |
| 122 /* Private variables */ | |
| 123 const unsigned char *stream_begin, *stream_end; | |
| 124 unsigned int stream_length; | |
| 125 | |
| 126 const unsigned char *stream; /* Pointer to the current stream */ | |
| 127 unsigned int reservoir, nbits_in_reservoir; | |
| 128 | |
| 129 struct component component_infos[COMPONENTS]; | |
| 130 float Q_tables[COMPONENTS][64]; /* quantization tables */ | |
| 131 struct huffman_table HTDC[HUFFMAN_TABLES]; /* DC huffman tables */ | |
| 132 struct huffman_table HTAC[HUFFMAN_TABLES]; /* AC huffman tables */ | |
| 133 int default_huffman_table_initialized; | |
| 134 unsigned int restart_interval; | |
| 135 // int restarts_to_go; /* MCUs left in this restart interval */ | |
| 136 int last_rst_marker_seen; /* Rst marker is incremented each time */ | |
| 137 | |
| 138 /* Temp space used after the IDCT to store each components */ | |
| 139 uint8_t Y[64*4], Cr[64], Cb[64]; | |
| 140 | |
| 141 /* Internal Pointer use for colorspace conversion, do not modify it !!! */ | |
| 142 uint8_t *plane; | |
| 143 | |
| 144 }; | |
| 145 | |
| 146 #if defined(__GNUC__) && (__GNUC__ > 3) && defined(__OPTIMIZE__) | |
| 147 #define __likely(x) __builtin_expect(!!(x), 1) | |
| 148 #define __unlikely(x) __builtin_expect(!!(x), 0) | |
| 149 #else | |
| 150 #define __likely(x) (x) | |
| 151 #define __unlikely(x) (x) | |
| 152 #endif | |
| 153 | |
| 154 #define IDCT tinyjpeg_idct_float | |
| 155 void tinyjpeg_idct_float (struct component *compptr, uint8_t *output_buf, int stride); | |
| 156 int parse_JFIF(struct jdec_private *priv, const unsigned char *stream); | |
| 157 | |
| 158 #endif | |
| 159 |
