blob: f00bc1038bcad73ec72a17fa6a1721b57a5ff0c8
1 | /*******************************************************************************# |
2 | # guvcview http://guvcview.sourceforge.net # |
3 | # # |
4 | # Paulo Assis <pj.assis@gmail.com> # |
5 | # # |
6 | # This program is free software; you can redistribute it and/or modify # |
7 | # it under the terms of the GNU General Public License as published by # |
8 | # the Free Software Foundation; either version 2 of the License, or # |
9 | # (at your option) any later version. # |
10 | # # |
11 | # This program is distributed in the hope that it will be useful, # |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
14 | # GNU General Public License for more details. # |
15 | # # |
16 | # You should have received a copy of the GNU General Public License # |
17 | # along with this program; if not, write to the Free Software # |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # |
19 | # # |
20 | ********************************************************************************/ |
21 | |
22 | /*******************************************************************************# |
23 | # # |
24 | # MJpeg decoding and frame capture taken from luvcview # |
25 | # # |
26 | # # |
27 | ********************************************************************************/ |
28 | |
29 | #ifndef UTILS_H |
30 | #define UTILS_H |
31 | |
32 | #include "defs.h" |
33 | |
34 | /*video defs*/ |
35 | //#define BI_RGB 0; |
36 | //#define BI_RLE4 1; |
37 | //#define BI_RLE8 2; |
38 | //#define BI_BITFIELDS 3; |
39 | |
40 | /* Fixed point arithmetic */ |
41 | //#define FIXED Sint32 |
42 | //#define FIXED_BITS 16 |
43 | //#define TO_FIXED(X) (((Sint32)(X))<<(FIXED_BITS)) |
44 | //#define FROM_FIXED(X) (((Sint32)(X))>>(FIXED_BITS)) |
45 | |
46 | #define ISHIFT 11 |
47 | |
48 | #define IFIX(a) ((int)((a) * (1 << ISHIFT) + .5)) |
49 | |
50 | #ifndef __P |
51 | # define __P(x) x |
52 | #endif |
53 | |
54 | /* special markers */ |
55 | #define M_BADHUFF -1 |
56 | #define M_EOF 0x80 |
57 | |
58 | struct jpeg_decdata |
59 | { |
60 | int dcts[6 * 64 + 16]; |
61 | int out[64 * 6]; |
62 | int dquant[3][64]; |
63 | }; |
64 | |
65 | struct in |
66 | { |
67 | BYTE *p; |
68 | DWORD bits; |
69 | int left; |
70 | int marker; |
71 | int (*func) __P((void *)); |
72 | void *data; |
73 | }; |
74 | |
75 | /*********************************/ |
76 | #define DECBITS 10 /* seems to be the optimum */ |
77 | |
78 | struct dec_hufftbl |
79 | { |
80 | int maxcode[17]; |
81 | int valptr[16]; |
82 | BYTE vals[256]; |
83 | DWORD llvals[1 << DECBITS]; |
84 | }; |
85 | |
86 | //struct enc_hufftbl; |
87 | |
88 | union hufftblp |
89 | { |
90 | struct dec_hufftbl *dhuff; |
91 | //struct enc_hufftbl *ehuff; |
92 | }; |
93 | |
94 | struct scan |
95 | { |
96 | int dc; /* old dc value */ |
97 | |
98 | union hufftblp hudc; |
99 | union hufftblp huac; |
100 | int next; /* when to switch to next scan */ |
101 | |
102 | int cid; /* component id */ |
103 | int hv; /* horiz/vert, copied from comp */ |
104 | int tq; /* quant tbl, copied from comp */ |
105 | }; |
106 | |
107 | /******** Markers *********/ |
108 | #ifndef M_SOI |
109 | #define M_SOI 0xd8 |
110 | #define M_APP0 0xe0 |
111 | #define M_DQT 0xdb |
112 | #define M_SOF0 0xc0 |
113 | #define M_DHT 0xc4 |
114 | #define M_DRI 0xdd |
115 | #define M_SOS 0xda |
116 | #define M_RST0 0xd0 |
117 | #define M_EOI 0xd9 |
118 | #define M_COM 0xfe |
119 | #endif |
120 | |
121 | /*******Error codes *******/ |
122 | #define ERR_NO_SOI 1 |
123 | #define ERR_NOT_8BIT 2 |
124 | #define ERR_HEIGHT_MISMATCH 3 |
125 | #define ERR_WIDTH_MISMATCH 4 |
126 | #define ERR_BAD_WIDTH_OR_HEIGHT 5 |
127 | #define ERR_TOO_MANY_COMPPS 6 |
128 | #define ERR_ILLEGAL_HV 7 |
129 | #define ERR_QUANT_TABLE_SELECTOR 8 |
130 | #define ERR_NOT_YCBCR_221111 9 |
131 | #define ERR_UNKNOWN_CID_IN_SCAN 10 |
132 | #define ERR_NOT_SEQUENTIAL_DCT 11 |
133 | #define ERR_WRONG_MARKER 12 |
134 | #define ERR_NO_EOI 13 |
135 | #define ERR_BAD_TABLES 14 |
136 | #define ERR_DEPTH_MISMATCH 15 |
137 | #define ERR_NOT_SUPPORTED 16 |
138 | |
139 | typedef struct addr_s |
140 | { |
141 | unsigned char *y; |
142 | unsigned char *v; |
143 | unsigned char *u; |
144 | }addr; |
145 | |
146 | int jpeg_decode(unsigned char **pic, unsigned char *buf, int width, int height,unsigned int outformat); |
147 | |
148 | #endif |
149 | |
150 |