1 /*
2 * jpeg.h --
3 *
4 * FIXME: This file needs a description here.
5 *
6 * Copyright (c) 1993-2002 The Regents of the University of California.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * A. Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 * B. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * C. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
22 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 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 @(#) $Header: /usr/mash/src/repository/mash/mash-1/codec/jpeg/jpeg.h,v 1.14 2002/05/22 20:57:06 chema Exp $
34 */
35
36 #ifndef lib_jpeg_h
37 #define lib_jpeg_h
38
39 #ifdef WIN32
40 #include <winsock.h>
41 #else
42 #include <sys/param.h>
43 #endif
44 #include <sys/types.h>
45
46 /*FIXME*/
47 #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
48
49 #define JO_PIXEL 1 /* JPEG output -> pixels */
50 #define JO_DCT 2 /* JPEG output -> DCT coefs */
51
52 // from the type specific field of the jpeg header
53 #define JPEG_FULL_FRAME 0
54 #define JPEG_ODD_FIELD 1
55 #define JPEG_EVEN_FIELD 2
56 #define JPEG_SINGLE_FIELD 3
57
58 class JpegDecoder {
59 public:
60 /*
61 * Baseline JPEG decompression parameters
62 * (which is the only mode we can handle).
63 * (describes the JPEG input stream)
64 */
65 struct config {
66 int width;
67 int height;
68 int precision;
69 int ncomp;
70 struct {
71 int id;
72 int hsf; /* horiz sample factor */
73 int vsf; /* vertical sample factor */
74 int qno;
75 /*
76 * FIXME Assume all scans the same.
77 */
78 int ac_tbl_no;
79 int dc_tbl_no;
80 } comp[4];
81 int qtab[4][64];
82 const u_char *ac_huffbits[4];
83 const u_char *ac_huffval[4];
84 const u_char *dc_huffbits[4];
85 const u_char *dc_huffval[4];
86 };
87 struct margin {
88 int top;
89 int right;
90 int left;
91 int ytopskip;
92 int uvtopskip;
93 int marktopskip;
94 int ylskip;
95 int uvlskip;
96 int marklskip;
97 int yrskip;
98 int uvrskip;
99 int markrskip;
100
101 int ftopskip;
102 int flskip;
103 int frskip;
104
105 } margin_;
106 static void defaults(config&);
107 static void quantizer(config&, int q);
108 static int q_to_thresh(int q);
109 protected:
110 JpegDecoder(const config&, int csss, int ow, int oh);
111 public:
112 virtual ~JpegDecoder();
113 virtual int decode(const u_char* in, int len, u_char* marks, int mark) {
114 return decode(in, len, JPEG_SINGLE_FIELD, marks, mark);
115 }
116 virtual int decode(const u_char* in, int len, int type,
117 u_char* marks, int mark) = 0;
118 inline int width() const { return (width_); }
119 inline int height() const { return (height_); }
120 inline void color(int c) { color_ = c; }
121 inline int csss() const { return (csss_); }
122 inline void thresh(int v) { thresh_ = v; }
123 inline void cthresh(int v) { cthresh_ = v; }
124 inline void resetndblk() { ndblk_ = 0; }
125 inline int ndblk() const { return (ndblk_); }
126 void setRestartInterval(int ri) { rlen_ = ri; rcnt_ = ri+1; }
127
128 protected:
129 virtual void setlrskips(void) = 0;
130 struct component {
131 int hsf; /* horizontal sampling factor (1..4) */
132 int vsf; /* vertical sampling factor (1..4) */
133 int qno; /* quantization table selector (0..3) */
134 /* for decompression, they are read from the SOS marker. */
135 int dc_tbl_no; /* DC entropy table selector (0..3) */
136 int ac_tbl_no; /* AC entropy table selector (0..3) */
137 int dc; /* dc predictor */
138 };
139 void init(const config&);
140 #ifdef INT_64
141 void rdct(int nc, register short *bp, INT_64 mask,
142 u_char* pixels, int stride, int qno);
143 #else
144 void rdct(int nc, register short *bp, u_int mask0, u_int mask1,
145 u_char* pixels, int stride, int qno);
146 #endif
147 int compute_margins(int, int);
148 void idlefill(void);
149 const u_char *inb_; /* input buffer FIXME make u_long */
150 const u_char *end_;
151 u_int bb_; /* bit buffer */
152 int nbb_; /* # bits in bit buffer */
153 int ndblk_; /* # blks decoded for this frame */
154 const u_char* parseJFIF(const u_char*);
155
156 int dct_unbias_; /* true to unbias DCT DC coefs */
157 int csss_; /* color subsampling scheme: can be 422, 411, or 420 */
158 int width_;
159 int height_;
160 int size_;
161 int ncomp_;
162 int owidth_;
163 int oheight_;
164 int osize_;
165 component comp_[3];
166
167 int rlen_; /* restart interval length (0 if not using) */
168 int rcnt_; /* restart interval counter */
169
170 /*
171 * Quantization tables. qt_ is always stored in
172 * natural order (i.e., not zigzagged). fqt_ is
173 * transformed by the DCT module to be in whatever
174 * form it finds most convenient.
175 */
176 int qt_[4][64];
177 int fqt_[4][64];
178 int rdqt(const u_char* p);
179
180 /*
181 * Huffman tables.
182 */
183 u_short* dcht_[NUM_HUFF_TBLS];
184 u_short* acht_[NUM_HUFF_TBLS];
185 void freehufftab();
186
187 /*
188 * Note: an MCU is 16x8 in 4:2:2 color, 16x16 in 4:2:0 color, and
189 * 32x8 in 4:1:1 color
190 */
191 int mcu_cols_; /* no. of mcu's across scan */
192 int mcu_rows_; /* no. of mcu's down scan */
193
194 int huffdc(component&);
195 int huffskip(component&);
196 void huffreset();
197 u_short* huffbuild(const u_char* bits, const u_char* vals) const;
198 int huffblock(int ci, int n, u_int *code, short* dctcoef) const;
199 void mix(u_int dc, const u_char* bp, u_char* out, int stride) const;
200
201 void restart();
202
203 int color_;
204
205 /* state for suppressing work when blocks don't change much */
206 int thresh_;
207 int cthresh_;
208
209 int rcrop_;
210 int lcrop_;
211 int topcrop_;
212 int botcrop_;
213 };
214
215 class JpegPixelDecoder : public JpegDecoder {
216 public:
217 JpegPixelDecoder(const config&, int, int, int);
218 ~JpegPixelDecoder();
219 static JpegPixelDecoder* create(const config&, int, int);
220 inline u_char* frame(void) const { return (frm_); }
221 protected:
222 #ifdef INT_64
223 int huffparse(component&, short* out, short* ref, INT_64* mask,
224 int dontskip = 0);
225 #else
226 int huffparse(component&, short* out, short* ref, u_int* mask,
227 int dontskip = 0);
228 #endif
229 void setlrskips(void);
230 u_char* frm_;
231 short* cache_;
232 };
233
234 class JpegDCTDecoder : public JpegDecoder {
235 public:
236 JpegDCTDecoder(const config&, int, int, int);
237 ~JpegDCTDecoder();
238 static JpegDCTDecoder* create(const config&, int, int);
239 static JpegDCTDecoder* true_create(const config&, int, int);
240 inline short* frame(void) const { return (frm_); }
241 protected:
242 #ifdef INT_64
243 int huffparse(component&, short* out, INT_64* mask,
244 const int *, int dontskip = 0);
245 #else
246 int huffparse(component&, short* out, u_int* mask,
247 const int *, int dontskip = 0);
248 #endif
249 void setlrskips(void);
250 short* frm_;
251 };
252
253 #endif
254
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.