Mercurial > cgi-bin > hgwebdir.cgi > PR > Applications > VSs > VSs__jpeg_decoder__Proj
view VSs_tinyjpeg/tinyjpeg-internal.h @ 0:a8af8b3fc99d
initial commit
| author | Nina Engelhardt <nengel@mailbox.tu-berlin.de> |
|---|---|
| date | Thu, 05 Jul 2012 11:35:03 +0200 |
| parents | |
| children |
line source
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 */
34 #ifndef __TINYJPEG_INTERNAL_H_
35 #define __TINYJPEG_INTERNAL_H_
37 #define SANITY_CHECK 1
39 struct jdec_private;
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)
46 #define HUFFMAN_TABLES 4
47 #define COMPONENTS 3
49 #define cY 0
50 #define cCb 1
51 #define cCr 2
53 #define BLACK_Y 0
54 #define BLACK_U 127
55 #define BLACK_V 127
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)
70 #define be16_to_cpu(x) (((x)[0]<<8)|(x)[1])
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 };
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 };
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 };
110 typedef int (*decode_MCU_fct) (struct jdec_private *priv);
111 typedef void (*convert_colorspace_fct) (struct jdec_private *priv);
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;
122 /* Private variables */
123 const unsigned char *stream_begin, *stream_end;
124 unsigned int stream_length;
126 const unsigned char *stream; /* Pointer to the current stream */
127 unsigned int reservoir, nbits_in_reservoir;
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 */
138 /* Temp space used after the IDCT to store each components */
139 uint8_t Y[64*4], Cr[64], Cb[64];
141 /* Internal Pointer use for colorspace conversion, do not modify it !!! */
142 uint8_t *plane;
144 };
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
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);
158 #endif
