utils.c
Go to the documentation of this file.
1 /*******************************************************************************
2 # luvcview: Sdl video Usb Video Class grabber . #
3 #This package work with the Logitech UVC based webcams with the mjpeg feature. #
4 #All the decoding is in user space with the embedded jpeg decoder #
5 #. #
6 # Copyright (C) 2005 2006 Laurent Pinchart && Michel Xhaard #
7 # #
8 # This program is free software; you can redistribute it and/or modify #
9 # it under the terms of the GNU General Public License as published by #
10 # the Free Software Foundation; either version 2 of the License, or #
11 # (at your option) any later version. #
12 # #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
17 # #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program; if not, write to the Free Software #
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21 # #
22 *******************************************************************************/
23 
24 #include "luvcview/utils.h"
25 #include "luvcview/color.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <linux/types.h>
30 #include <string.h>
31 #include <fcntl.h>
32 #include <wait.h>
33 #include <time.h>
34 #include <limits.h>
35 #include "luvcview/huffman.h"
36 
37 #define ISHIFT 11
38 
39 #define IFIX(a) ((int)((a) * (1 << ISHIFT) + .5))
40 
41 #ifndef __P
42 # define __P(x) x
43 #endif
44 
45 /* special markers */
46 #define M_BADHUFF -1
47 #define M_EOF 0x80
48 
49 struct jpeg_decdata {
50  int dcts[6 * 64 + 16];
51  int out[64 * 6];
52  int dquant[3][64];
53 };
54 
55 struct in {
56  unsigned char *p;
57  unsigned int bits;
58  int left;
59  int marker;
60  int (*func) __P((void *));
61  void *data;
62 };
63 
64 /*********************************/
65 struct dec_hufftbl;
66 struct enc_hufftbl;
67 
68 union hufftblp {
69  struct dec_hufftbl *dhuff;
70  struct enc_hufftbl *ehuff;
71 };
72 
73 struct scan {
74  int dc; /* old dc value */
75 
76  union hufftblp hudc;
77  union hufftblp huac;
78  int next; /* when to switch to next scan */
79 
80  int cid; /* component id */
81  int hv; /* horiz/vert, copied from comp */
82  int tq; /* quant tbl, copied from comp */
83 };
84 
85 /*********************************/
86 
87 #define DECBITS 10 /* seems to be the optimum */
88 
89 struct dec_hufftbl {
90  int maxcode[17];
91  int valptr[16];
92  unsigned char vals[256];
93  unsigned int llvals[1 << DECBITS];
94 };
95 static int huffman_init(void);
96 static void decode_mcus
97 __P((struct in *, int *, int, struct scan *, int *));
98 static int dec_readmarker __P((struct in *));
99 static void dec_makehuff
100 __P((struct dec_hufftbl *, int *, unsigned char *));
101 
102 static void setinput __P((struct in *, unsigned char *));
103 /*********************************/
104 
105 #undef PREC
106 #define PREC int
107 
108 static void idctqtab __P((unsigned char *, PREC *));
109 
110 inline static void idct(int *in, int *out, int *quant, long off, int max);
111 
112 int is_huffman(unsigned char *buf);
113 
114 /*********************************/
115 
116 static void yuv420pto422(int * out,unsigned char *pic,int width);
117 static void yuv422pto422(int * out,unsigned char *pic,int width);
118 static void yuv444pto422(int * out,unsigned char *pic,int width);
119 static void yuv400pto422(int * out,unsigned char *pic,int width);
120 typedef void (*ftopict) ( int *out, unsigned char *pic, int width) ;
121 /*********************************/
122 
123 #define M_SOI 0xd8
124 #define M_APP0 0xe0
125 #define M_DQT 0xdb
126 #define M_SOF0 0xc0
127 #define M_DHT 0xc4
128 #define M_DRI 0xdd
129 #define M_SOS 0xda
130 #define M_RST0 0xd0
131 #define M_EOI 0xd9
132 #define M_COM 0xfe
133 
134 static unsigned char *datap;
135 
136 static int getbyte(void)
137 {
138  return *datap++;
139 }
140 
141 static int getword(void)
142 {
143  int c1, c2;
144  c1 = *datap++;
145  c2 = *datap++;
146  return c1 << 8 | c2;
147 }
148 
149 struct comp {
150  int cid;
151  int hv;
152  int tq;
153 };
154 
155 #define MAXCOMP 4
156 struct jpginfo {
157  int nc; /* number of components */
158  int ns; /* number of scans */
159  int dri; /* restart interval */
160  int nm; /* mcus til next marker */
161  int rm; /* next restart marker */
162 };
163 
164 static struct jpginfo info;
165 static struct comp comps[MAXCOMP];
166 
167 static struct scan dscans[MAXCOMP];
168 
169 static unsigned char quant[4][64];
170 
171 static struct dec_hufftbl dhuff[4];
172 
173 #define dec_huffdc (dhuff + 0)
174 #define dec_huffac (dhuff + 2)
175 
176 static struct in in;
177 
178 static int readtables(int till, int *isDHT)
179 {
180  int m, l, i, j, lq, pq, tq;
181  int tc, th, tt;
182 
183  for (;;) {
184  if (getbyte() != 0xff)
185  return -1;
186 nextbyte:
187  if ((m = getbyte()) == till)
188  break;
189 
190  switch (m) {
191  case 0xc2:
192  return 0;
193 
194  case M_DQT:
195  //printf("find DQT \n");
196  lq = getword();
197  while (lq > 2) {
198  pq = getbyte();
199  tq = pq & 15;
200  if (tq > 3)
201  return -1;
202  pq >>= 4;
203  if (pq != 0)
204  return -1;
205  for (i = 0; i < 64; i++)
206  quant[tq][i] = getbyte();
207  lq -= 64 + 1;
208  }
209  break;
210 
211  case M_DHT:
212  //printf("find DHT \n");
213  l = getword();
214  while (l > 2) {
215  int hufflen[16], k;
216  unsigned char huffvals[256];
217 
218  tc = getbyte();
219  th = tc & 15;
220  tc >>= 4;
221  tt = tc * 2 + th;
222  if (tc > 1 || th > 1)
223  return -1;
224  for (i = 0; i < 16; i++)
225  hufflen[i] = getbyte();
226  l -= 1 + 16;
227  k = 0;
228  for (i = 0; i < 16; i++) {
229  for (j = 0; j < hufflen[i]; j++)
230  huffvals[k++] = getbyte();
231  l -= hufflen[i];
232  }
233  dec_makehuff(dhuff + tt, hufflen, huffvals);
234  }
235  *isDHT= 1;
236  break;
237 
238  case M_DRI:
239  printf("find DRI \n");
240  l = getword();
241  info.dri = getword();
242  break;
243  case 0xff:
244  goto nextbyte;
245  break;
246 
247  default:
248  l = getword();
249  while (l-- > 2)
250  getbyte();
251  break;
252  }
253  }
254 
255  return 0;
256 }
257 
258 static void dec_initscans(void)
259 {
260  int i;
261 
262  info.nm = info.dri + 1;
263  info.rm = M_RST0;
264  for (i = 0; i < info.ns; i++)
265  dscans[i].dc = 0;
266 }
267 
268 static int dec_checkmarker(void)
269 {
270  int i;
271 
272  if (dec_readmarker(&in) != info.rm)
273  return -1;
274  info.nm = info.dri;
275  info.rm = (info.rm + 1) & ~0x08;
276  for (i = 0; i < info.ns; i++)
277  dscans[i].dc = 0;
278  return 0;
279 }
280 
281 
282 int jpeg_decode(unsigned char **pic, unsigned char *buf, int *width,
283  int *height)
284 {
285  struct jpeg_decdata *decdata;
286  int i, j, m, tac, tdc;
287  int intwidth, intheight;
288  int mcusx, mcusy, mx, my;
289  int ypitch ,xpitch,bpp,pitch,x,y;
290  int mb;
291  int max[6];
292  ftopict convert;
293  int err = 0;
294  int isInitHuffman = 0;
295  decdata = (struct jpeg_decdata *) malloc(sizeof(struct jpeg_decdata));
296 
297  if (!decdata) {
298  err = -1;
299  goto error;
300  }
301  if (buf == NULL) {
302  err = -1;
303  goto error;
304  }
305  datap = buf;
306  if (getbyte() != 0xff) {
307  err = ERR_NO_SOI;
308  goto error;
309  }
310  if (getbyte() != M_SOI) {
311  err = ERR_NO_SOI;
312  goto error;
313  }
314  if (readtables(M_SOF0, &isInitHuffman)) {
315  err = ERR_BAD_TABLES;
316  goto error;
317  }
318  getword();
319  i = getbyte();
320  if (i != 8) {
321  err = ERR_NOT_8BIT;
322  goto error;
323  }
324  intheight = getword();
325  intwidth = getword();
326 
327  if ((intheight & 7) || (intwidth & 7)) {
329  goto error;
330  }
331  info.nc = getbyte();
332  if (info.nc > MAXCOMP) {
333  err = ERR_TOO_MANY_COMPPS;
334  goto error;
335  }
336  for (i = 0; i < info.nc; i++) {
337  int h, v;
338  comps[i].cid = getbyte();
339  comps[i].hv = getbyte();
340  v = comps[i].hv & 15;
341  h = comps[i].hv >> 4;
342  comps[i].tq = getbyte();
343  if (h > 3 || v > 3) {
344  err = ERR_ILLEGAL_HV;
345  goto error;
346  }
347  if (comps[i].tq > 3) {
349  goto error;
350  }
351  }
352  if (readtables(M_SOS,&isInitHuffman)) {
353  err = ERR_BAD_TABLES;
354  goto error;
355  }
356  getword();
357  info.ns = getbyte();
358  if (!info.ns){
359  printf("info ns %d/n",info.ns);
360  err = ERR_NOT_YCBCR_221111;
361  goto error;
362  }
363  for (i = 0; i < info.ns; i++) {
364  dscans[i].cid = getbyte();
365  tdc = getbyte();
366  tac = tdc & 15;
367  tdc >>= 4;
368  if (tdc > 1 || tac > 1) {
370  goto error;
371  }
372  for (j = 0; j < info.nc; j++)
373  if (comps[j].cid == dscans[i].cid)
374  break;
375  if (j == info.nc) {
377  goto error;
378  }
379  dscans[i].hv = comps[j].hv;
380  dscans[i].tq = comps[j].tq;
381  dscans[i].hudc.dhuff = dec_huffdc + tdc;
382  dscans[i].huac.dhuff = dec_huffac + tac;
383  }
384 
385  i = getbyte();
386  j = getbyte();
387  m = getbyte();
388 
389  if (i != 0 || j != 63 || m != 0) {
390  printf("hmm FW error,not seq DCT ??\n");
391  }
392  // printf("ext huffman table %d \n",isInitHuffman);
393  if(!isInitHuffman) {
394  if(huffman_init() < 0)
395  return -ERR_BAD_TABLES;
396  }
397 /*
398  if (dscans[0].cid != 1 || dscans[1].cid != 2 || dscans[2].cid != 3) {
399  err = ERR_NOT_YCBCR_221111;
400  goto error;
401  }
402 
403  if (dscans[1].hv != 0x11 || dscans[2].hv != 0x11) {
404  err = ERR_NOT_YCBCR_221111;
405  goto error;
406  }
407 */
408  /* if internal width and external are not the same or heigth too
409  and pic not allocated realloc the good size and mark the change
410  need 1 macroblock line more ?? */
411  if (intwidth != *width || intheight != *height || *pic == NULL) {
412  *width = intwidth;
413  *height = intheight;
414  // BytesperPixel 2 yuyv , 3 rgb24
415  *pic =
416  (unsigned char *) realloc((unsigned char *) *pic,
417  (size_t) intwidth * (intheight +
418  8) * 2);
419  }
420 
421 
422  switch (dscans[0].hv) {
423  case 0x22: // 411
424  mb=6;
425  mcusx = *width >> 4;
426  mcusy = *height >> 4;
427  bpp=2;
428  xpitch = 16 * bpp;
429  pitch = *width * bpp; // YUYV out
430  ypitch = 16 * pitch;
431  convert = yuv420pto422;
432  break;
433  case 0x21: //422
434  // printf("find 422 %dx%d\n",*width,*height);
435  mb=4;
436  mcusx = *width >> 4;
437  mcusy = *height >> 3;
438  bpp=2;
439  xpitch = 16 * bpp;
440  pitch = *width * bpp; // YUYV out
441  ypitch = 8 * pitch;
442  convert = yuv422pto422;
443  break;
444  case 0x11: //444
445  mcusx = *width >> 3;
446  mcusy = *height >> 3;
447  bpp=2;
448  xpitch = 8 * bpp;
449  pitch = *width * bpp; // YUYV out
450  ypitch = 8 * pitch;
451  if (info.ns==1) {
452  mb = 1;
453  convert = yuv400pto422;
454  } else {
455  mb=3;
456  convert = yuv444pto422;
457  }
458  break;
459  default:
460  err = ERR_NOT_YCBCR_221111;
461  goto error;
462  break;
463  }
464 
465  idctqtab(quant[dscans[0].tq], decdata->dquant[0]);
466  idctqtab(quant[dscans[1].tq], decdata->dquant[1]);
467  idctqtab(quant[dscans[2].tq], decdata->dquant[2]);
468  setinput(&in, datap);
469  dec_initscans();
470 
471  dscans[0].next = 2;
472  dscans[1].next = 1;
473  dscans[2].next = 0; /* 4xx encoding */
474  for (my = 0,y=0; my < mcusy; my++,y+=ypitch) {
475  for (mx = 0,x=0; mx < mcusx; mx++,x+=xpitch) {
476  if (info.dri && !--info.nm)
477  if (dec_checkmarker()) {
478  err = ERR_WRONG_MARKER;
479  goto error;
480  }
481  switch (mb){
482  case 6: {
483  decode_mcus(&in, decdata->dcts, mb, dscans, max);
484  idct(decdata->dcts, decdata->out, decdata->dquant[0],
485  IFIX(128.5), max[0]);
486  idct(decdata->dcts + 64, decdata->out + 64,
487  decdata->dquant[0], IFIX(128.5), max[1]);
488  idct(decdata->dcts + 128, decdata->out + 128,
489  decdata->dquant[0], IFIX(128.5), max[2]);
490  idct(decdata->dcts + 192, decdata->out + 192,
491  decdata->dquant[0], IFIX(128.5), max[3]);
492  idct(decdata->dcts + 256, decdata->out + 256,
493  decdata->dquant[1], IFIX(0.5), max[4]);
494  idct(decdata->dcts + 320, decdata->out + 320,
495  decdata->dquant[2], IFIX(0.5), max[5]);
496 
497  } break;
498  case 4:
499  {
500  decode_mcus(&in, decdata->dcts, mb, dscans, max);
501  idct(decdata->dcts, decdata->out, decdata->dquant[0],
502  IFIX(128.5), max[0]);
503  idct(decdata->dcts + 64, decdata->out + 64,
504  decdata->dquant[0], IFIX(128.5), max[1]);
505  idct(decdata->dcts + 128, decdata->out + 256,
506  decdata->dquant[1], IFIX(0.5), max[4]);
507  idct(decdata->dcts + 192, decdata->out + 320,
508  decdata->dquant[2], IFIX(0.5), max[5]);
509 
510  }
511  break;
512  case 3:
513  decode_mcus(&in, decdata->dcts, mb, dscans, max);
514  idct(decdata->dcts, decdata->out, decdata->dquant[0],
515  IFIX(128.5), max[0]);
516  idct(decdata->dcts + 64, decdata->out + 256,
517  decdata->dquant[1], IFIX(0.5), max[4]);
518  idct(decdata->dcts + 128, decdata->out + 320,
519  decdata->dquant[2], IFIX(0.5), max[5]);
520 
521 
522  break;
523  case 1:
524  decode_mcus(&in, decdata->dcts, mb, dscans, max);
525  idct(decdata->dcts, decdata->out, decdata->dquant[0],
526  IFIX(128.5), max[0]);
527 
528  break;
529 
530  } // switch enc411
531  convert(decdata->out,*pic+y+x,pitch);
532  }
533  }
534 
535  m = dec_readmarker(&in);
536  if (m != M_EOI) {
537  err = ERR_NO_EOI;
538  goto error;
539  }
540  if (decdata)
541  free(decdata);
542  return 0;
543  error:
544  if (decdata)
545  free(decdata);
546  return err;
547 }
548 
549 /****************************************************************/
550 /************** huffman decoder ***************/
551 /****************************************************************/
552 static int huffman_init(void)
553 { int tc, th, tt;
554  const unsigned char *ptr= JPEGHuffmanTable ;
555  int i, j, l;
557  while (l > 0) {
558  int hufflen[16], k;
559  unsigned char huffvals[256];
560 
561  tc = *ptr++;
562  th = tc & 15;
563  tc >>= 4;
564  tt = tc * 2 + th;
565  if (tc > 1 || th > 1)
566  return -ERR_BAD_TABLES;
567  for (i = 0; i < 16; i++)
568  hufflen[i] = *ptr++;
569  l -= 1 + 16;
570  k = 0;
571  for (i = 0; i < 16; i++) {
572  for (j = 0; j < hufflen[i]; j++)
573  huffvals[k++] = *ptr++;
574  l -= hufflen[i];
575  }
576  dec_makehuff(dhuff + tt, hufflen, huffvals);
577  }
578  return 0;
579 }
580 
581 static int fillbits __P((struct in *, int, unsigned int));
582 static int dec_rec2
583 __P((struct in *, struct dec_hufftbl *, int *, int, int));
584 
585 static void setinput(in, p)
586 struct in *in;
587 unsigned char *p;
588 {
589  in->p = p;
590  in->left = 0;
591  in->bits = 0;
592  in->marker = 0;
593 }
594 
595 static int fillbits(in, le, bi)
596 struct in *in;
597 int le;
598 unsigned int bi;
599 {
600  int b, m;
601 
602  if (in->marker) {
603  if (le <= 16)
604  in->bits = bi << 16, le += 16;
605  return le;
606  }
607  while (le <= 24) {
608  b = *in->p++;
609  if (b == 0xff && (m = *in->p++) != 0) {
610  if (m == M_EOF) {
611  if (in->func && (m = in->func(in->data)) == 0)
612  continue;
613  }
614  in->marker = m;
615  if (le <= 16)
616  bi = bi << 16, le += 16;
617  break;
618  }
619  bi = bi << 8 | b;
620  le += 8;
621  }
622  in->bits = bi; /* tmp... 2 return values needed */
623  return le;
624 }
625 
626 static int dec_readmarker(in)
627 struct in *in;
628 {
629  int m;
630 
631  in->left = fillbits(in, in->left, in->bits);
632  if ((m = in->marker) == 0)
633  return 0;
634  in->left = 0;
635  in->marker = 0;
636  return m;
637 }
638 
639 #define LEBI_DCL int le, bi
640 #define LEBI_GET(in) (le = in->left, bi = in->bits)
641 #define LEBI_PUT(in) (in->left = le, in->bits = bi)
642 
643 #define GETBITS(in, n) ( \
644  (le < (n) ? le = fillbits(in, le, bi), bi = in->bits : 0), \
645  (le -= (n)), \
646  bi >> le & ((1 << (n)) - 1) \
647 )
648 
649 #define UNGETBITS(in, n) ( \
650  le += (n) \
651 )
652 
653 
654 static int dec_rec2(in, hu, runp, c, i)
655 struct in *in;
656 struct dec_hufftbl *hu;
657 int *runp;
658 int c, i;
659 {
660  LEBI_DCL;
661 
662  LEBI_GET(in);
663  if (i) {
664  UNGETBITS(in, i & 127);
665  *runp = i >> 8 & 15;
666  i >>= 16;
667  } else {
668  for (i = DECBITS;
669  (c = ((c << 1) | GETBITS(in, 1))) >= (hu->maxcode[i]); i++);
670  if (i >= 16) {
671  in->marker = M_BADHUFF;
672  return 0;
673  }
674  i = hu->vals[hu->valptr[i] + c - hu->maxcode[i - 1] * 2];
675  *runp = i >> 4;
676  i &= 15;
677  }
678  if (i == 0) { /* sigh, 0xf0 is 11 bit */
679  LEBI_PUT(in);
680  return 0;
681  }
682  /* receive part */
683  c = GETBITS(in, i);
684  if (c < (1 << (i - 1)))
685  c += (-1 << i) + 1;
686  LEBI_PUT(in);
687  return c;
688 }
689 
690 #define DEC_REC(in, hu, r, i) ( \
691  r = GETBITS(in, DECBITS), \
692  i = hu->llvals[r], \
693  i & 128 ? \
694  ( \
695  UNGETBITS(in, i & 127), \
696  r = i >> 8 & 15, \
697  i >> 16 \
698  ) \
699  : \
700  ( \
701  LEBI_PUT(in), \
702  i = dec_rec2(in, hu, &r, r, i), \
703  LEBI_GET(in), \
704  i \
705  ) \
706 )
707 
708 static void decode_mcus(in, dct, n, sc, maxp)
709 struct in *in;
710 int *dct;
711 int n;
712 struct scan *sc;
713 int *maxp;
714 {
715  struct dec_hufftbl *hu;
716  int i, r, t;
717  LEBI_DCL;
718 
719  memset(dct, 0, n * 64 * sizeof(*dct));
720  LEBI_GET(in);
721  while (n-- > 0) {
722  hu = sc->hudc.dhuff;
723  *dct++ = (sc->dc += DEC_REC(in, hu, r, t));
724 
725  hu = sc->huac.dhuff;
726  i = 63;
727  while (i > 0) {
728  t = DEC_REC(in, hu, r, t);
729  if (t == 0 && r == 0) {
730  dct += i;
731  break;
732  }
733  dct += r;
734  *dct++ = t;
735  i -= r + 1;
736  }
737  *maxp++ = 64 - i;
738  if (n == sc->next)
739  sc++;
740  }
741  LEBI_PUT(in);
742 }
743 
744 static void dec_makehuff(hu, hufflen, huffvals)
745 struct dec_hufftbl *hu;
746 int *hufflen;
747 unsigned char *huffvals;
748 {
749  int code, k, i, j, d, x, c, v;
750  for (i = 0; i < (1 << DECBITS); i++)
751  hu->llvals[i] = 0;
752 
753 /*
754  * llvals layout:
755  *
756  * value v already known, run r, backup u bits:
757  * vvvvvvvvvvvvvvvv 0000 rrrr 1 uuuuuuu
758  * value unknown, size b bits, run r, backup u bits:
759  * 000000000000bbbb 0000 rrrr 0 uuuuuuu
760  * value and size unknown:
761  * 0000000000000000 0000 0000 0 0000000
762  */
763  code = 0;
764  k = 0;
765  for (i = 0; i < 16; i++, code <<= 1) { /* sizes */
766  hu->valptr[i] = k;
767  for (j = 0; j < hufflen[i]; j++) {
768  hu->vals[k] = *huffvals++;
769  if (i < DECBITS) {
770  c = code << (DECBITS - 1 - i);
771  v = hu->vals[k] & 0x0f; /* size */
772  for (d = 1 << (DECBITS - 1 - i); --d >= 0;) {
773  if (v + i < DECBITS) { /* both fit in table */
774  x = d >> (DECBITS - 1 - v - i);
775  if (v && x < (1 << (v - 1)))
776  x += (-1 << v) + 1;
777  x = x << 16 | (hu->vals[k] & 0xf0) << 4 |
778  (DECBITS - (i + 1 + v)) | 128;
779  } else
780  x = v << 16 | (hu->vals[k] & 0xf0) << 4 |
781  (DECBITS - (i + 1));
782  hu->llvals[c | d] = x;
783  }
784  }
785  code++;
786  k++;
787  }
788  hu->maxcode[i] = code;
789  }
790  hu->maxcode[16] = 0x20000; /* always terminate decode */
791 }
792 
793 /****************************************************************/
794 /************** idct ***************/
795 /****************************************************************/
796 
797 
798 #define IMULT(a, b) (((a) * (b)) >> ISHIFT)
799 #define ITOINT(a) ((a) >> ISHIFT)
800 
801 #define S22 ((PREC)IFIX(2 * 0.382683432))
802 #define C22 ((PREC)IFIX(2 * 0.923879532))
803 #define IC4 ((PREC)IFIX(1 / 0.707106781))
804 
805 static unsigned char zig2[64] = {
806  0, 2, 3, 9, 10, 20, 21, 35,
807  14, 16, 25, 31, 39, 46, 50, 57,
808  5, 7, 12, 18, 23, 33, 37, 48,
809  27, 29, 41, 44, 52, 55, 59, 62,
810  15, 26, 30, 40, 45, 51, 56, 58,
811  1, 4, 8, 11, 19, 22, 34, 36,
812  28, 42, 43, 53, 54, 60, 61, 63,
813  6, 13, 17, 24, 32, 38, 47, 49
814 };
815 
816 inline static void idct(int *in, int *out, int *quant, long off, int max)
817 {
818  long t0, t1, t2, t3, t4, t5, t6, t7; // t ;
819  long tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
820  long tmp[64], *tmpp;
821  int i, j, te;
822  unsigned char *zig2p;
823 
824  t0 = off;
825  if (max == 1) {
826  t0 += in[0] * quant[0];
827  for (i = 0; i < 64; i++)
828  out[i] = ITOINT(t0);
829  return;
830  }
831  zig2p = zig2;
832  tmpp = tmp;
833  for (i = 0; i < 8; i++) {
834  j = *zig2p++;
835  t0 += in[j] * (long) quant[j];
836  j = *zig2p++;
837  t5 = in[j] * (long) quant[j];
838  j = *zig2p++;
839  t2 = in[j] * (long) quant[j];
840  j = *zig2p++;
841  t7 = in[j] * (long) quant[j];
842  j = *zig2p++;
843  t1 = in[j] * (long) quant[j];
844  j = *zig2p++;
845  t4 = in[j] * (long) quant[j];
846  j = *zig2p++;
847  t3 = in[j] * (long) quant[j];
848  j = *zig2p++;
849  t6 = in[j] * (long) quant[j];
850 
851 
852  if ((t1 | t2 | t3 | t4 | t5 | t6 | t7) == 0) {
853 
854  tmpp[0 * 8] = t0;
855  tmpp[1 * 8] = t0;
856  tmpp[2 * 8] = t0;
857  tmpp[3 * 8] = t0;
858  tmpp[4 * 8] = t0;
859  tmpp[5 * 8] = t0;
860  tmpp[6 * 8] = t0;
861  tmpp[7 * 8] = t0;
862 
863  tmpp++;
864  t0 = 0;
865  continue;
866  }
867  //IDCT;
868  tmp0 = t0 + t1;
869  t1 = t0 - t1;
870  tmp2 = t2 - t3;
871  t3 = t2 + t3;
872  tmp2 = IMULT(tmp2, IC4) - t3;
873  tmp3 = tmp0 + t3;
874  t3 = tmp0 - t3;
875  tmp1 = t1 + tmp2;
876  tmp2 = t1 - tmp2;
877  tmp4 = t4 - t7;
878  t7 = t4 + t7;
879  tmp5 = t5 + t6;
880  t6 = t5 - t6;
881  tmp6 = tmp5 - t7;
882  t7 = tmp5 + t7;
883  tmp5 = IMULT(tmp6, IC4);
884  tmp6 = IMULT((tmp4 + t6), S22);
885  tmp4 = IMULT(tmp4, (C22 - S22)) + tmp6;
886  t6 = IMULT(t6, (C22 + S22)) - tmp6;
887  t6 = t6 - t7;
888  t5 = tmp5 - t6;
889  t4 = tmp4 - t5;
890 
891  tmpp[0 * 8] = tmp3 + t7; //t0;
892  tmpp[1 * 8] = tmp1 + t6; //t1;
893  tmpp[2 * 8] = tmp2 + t5; //t2;
894  tmpp[3 * 8] = t3 + t4; //t3;
895  tmpp[4 * 8] = t3 - t4; //t4;
896  tmpp[5 * 8] = tmp2 - t5; //t5;
897  tmpp[6 * 8] = tmp1 - t6; //t6;
898  tmpp[7 * 8] = tmp3 - t7; //t7;
899  tmpp++;
900  t0 = 0;
901  }
902  for (i = 0, j = 0; i < 8; i++) {
903  t0 = tmp[j + 0];
904  t1 = tmp[j + 1];
905  t2 = tmp[j + 2];
906  t3 = tmp[j + 3];
907  t4 = tmp[j + 4];
908  t5 = tmp[j + 5];
909  t6 = tmp[j + 6];
910  t7 = tmp[j + 7];
911  if ((t1 | t2 | t3 | t4 | t5 | t6 | t7) == 0) {
912  te = ITOINT(t0);
913  out[j + 0] = te;
914  out[j + 1] = te;
915  out[j + 2] = te;
916  out[j + 3] = te;
917  out[j + 4] = te;
918  out[j + 5] = te;
919  out[j + 6] = te;
920  out[j + 7] = te;
921  j += 8;
922  continue;
923  }
924  //IDCT;
925  tmp0 = t0 + t1;
926  t1 = t0 - t1;
927  tmp2 = t2 - t3;
928  t3 = t2 + t3;
929  tmp2 = IMULT(tmp2, IC4) - t3;
930  tmp3 = tmp0 + t3;
931  t3 = tmp0 - t3;
932  tmp1 = t1 + tmp2;
933  tmp2 = t1 - tmp2;
934  tmp4 = t4 - t7;
935  t7 = t4 + t7;
936  tmp5 = t5 + t6;
937  t6 = t5 - t6;
938  tmp6 = tmp5 - t7;
939  t7 = tmp5 + t7;
940  tmp5 = IMULT(tmp6, IC4);
941  tmp6 = IMULT((tmp4 + t6), S22);
942  tmp4 = IMULT(tmp4, (C22 - S22)) + tmp6;
943  t6 = IMULT(t6, (C22 + S22)) - tmp6;
944  t6 = t6 - t7;
945  t5 = tmp5 - t6;
946  t4 = tmp4 - t5;
947 
948  out[j + 0] = ITOINT(tmp3 + t7);
949  out[j + 1] = ITOINT(tmp1 + t6);
950  out[j + 2] = ITOINT(tmp2 + t5);
951  out[j + 3] = ITOINT(t3 + t4);
952  out[j + 4] = ITOINT(t3 - t4);
953  out[j + 5] = ITOINT(tmp2 - t5);
954  out[j + 6] = ITOINT(tmp1 - t6);
955  out[j + 7] = ITOINT(tmp3 - t7);
956  j += 8;
957  }
958 
959 }
960 
961 
962 #define FOUR_TWO_TWO 2 //Y00 Cb Y01 Cr
963 
964 
965 /* translate YUV422Packed to rgb24 */
966 
967 unsigned int
968 Pyuv422togray8(unsigned char * input_ptr, unsigned char * output_ptr, unsigned int image_width, unsigned int image_height)
969 {
970  unsigned int i, size;
971  unsigned char *buff = input_ptr;
972  unsigned char *output_pt = output_ptr;
973  size = image_width * image_height;
974  for (i = size; i > 0; i--) {
975  buff += 2;
976  *output_pt++ = *buff;
977  }
978 
979  return FOUR_TWO_TWO;
980 }
981 unsigned int
982 Pyuv422torgb24(unsigned char * input_ptr, unsigned char * output_ptr, unsigned int image_width, unsigned int image_height)
983 {
984  unsigned int i, size;
985  unsigned char Y, Y1, U, V;
986  unsigned char *buff = input_ptr;
987  unsigned char *output_pt = output_ptr;
988  size = image_width * image_height /2;
989  for (i = size; i > 0; i--) {
990  /* bgr instead rgb ?? */
991  Y = buff[0] ;
992  U = buff[1] ;
993  Y1 = buff[2];
994  V = buff[3];
995  buff += 4;
996  *output_pt++ = R_FROMYV(Y,V);
997  *output_pt++ = G_FROMYUV(Y,U,V); //b
998  *output_pt++ = B_FROMYU(Y,U); //v
999 
1000  *output_pt++ = R_FROMYV(Y1,V);
1001  *output_pt++ = G_FROMYUV(Y1,U,V); //b
1002  *output_pt++ = B_FROMYU(Y1,U); //v
1003  }
1004 
1005  return FOUR_TWO_TWO;
1006 }
1007 
1008 void Pyuv422tobgr24(unsigned char *input_ptr, unsigned char *output_ptr, unsigned int image_width, unsigned int image_height)
1009 {
1010  unsigned int i, size;
1011  unsigned char Y, Y1, U, V;
1012  unsigned char *buff = input_ptr;
1013  unsigned char *output_pt = output_ptr;
1014  size = image_width * image_height / 2;
1015  for(i = size; i > 0; i--) {
1016  /* bgr instead rgb ?? */
1017  Y = buff[0] ;
1018  U = buff[1] ;
1019  Y1 = buff[2];
1020  V = buff[3];
1021  buff += 4;
1022  *output_pt++ = B_FROMYU(Y, U);
1023  *output_pt++ = G_FROMYUV(Y, U, V);
1024  *output_pt++ = R_FROMYV(Y, V);
1025 
1026  *output_pt++ = B_FROMYU(Y1, U);
1027  *output_pt++ = G_FROMYUV(Y1, U, V);
1028  *output_pt++ = R_FROMYV(Y1, V);
1029  }
1030 }
1031 
1032 static void yuv420pto422(int * out,unsigned char *pic,int width)
1033 {
1034  int j, k;
1035  unsigned char *pic0, *pic1;
1036  int *outy, *outu, *outv;
1037  int outy1 = 0;
1038  int outy2 = 8;
1039 
1040 
1041  pic0 = pic;
1042  pic1 = pic + width;
1043  outy = out;
1044  outu = out + 64 * 4;
1045  outv = out + 64 * 5;
1046  for (j = 0; j < 8; j++) {
1047  for (k = 0; k < 8; k++) {
1048  if( k == 4) {
1049  outy1 += 56;
1050  outy2 += 56;
1051  }
1052  *pic0++ = CLIP(outy[outy1]);
1053  *pic0++ = CLIP(128 + *outu);
1054  *pic0++ = CLIP(outy[outy1+1]);
1055  *pic0++ = CLIP(128 + *outv);
1056  *pic1++ = CLIP(outy[outy2]);
1057  *pic1++ = CLIP(128 + *outu);
1058  *pic1++ = CLIP(outy[outy2+1]);
1059  *pic1++ = CLIP(128 + *outv);
1060  outy1 +=2; outy2 += 2; outu++; outv++;
1061  }
1062  if(j==3) {
1063  outy = out + 128;
1064  } else {
1065  outy += 16;
1066  }
1067  outy1 = 0;
1068  outy2 = 8;
1069  pic0 += 2 * (width -16);
1070  pic1 += 2 * (width -16);
1071 
1072  }
1073 
1074 }
1075 static void yuv422pto422(int * out,unsigned char *pic,int width)
1076 {
1077  int j, k;
1078  unsigned char *pic0, *pic1;
1079  int *outy, *outu, *outv;
1080  int outy1 = 0;
1081  int outy2 = 8;
1082  int outu1 = 0;
1083  int outv1 = 0;
1084 
1085 
1086  pic0 = pic;
1087  pic1 = pic + width;
1088  outy = out;
1089  outu = out + 64 * 4;
1090  outv = out + 64 * 5;
1091  for (j = 0; j < 4; j++) {
1092  for (k = 0; k < 8; k++) {
1093  if( k == 4) {
1094  outy1 += 56;
1095  outy2 += 56;
1096  }
1097  *pic0++ = CLIP(outy[outy1]);
1098  *pic0++ = CLIP(128 + outu[outu1]);
1099  *pic0++ = CLIP(outy[outy1+1]);
1100  *pic0++ = CLIP(128 + outv[outv1]);
1101  *pic1++ = CLIP(outy[outy2]);
1102  *pic1++ = CLIP(128 + outu[outu1+8]);
1103  *pic1++ = CLIP(outy[outy2+1]);
1104  *pic1++ = CLIP(128 + outv[outv1+8]);
1105  outv1 += 1; outu1 += 1;
1106  outy1 +=2; outy2 +=2;
1107 
1108  }
1109 
1110  outy += 16;outu +=8; outv +=8;
1111  outv1 = 0; outu1=0;
1112  outy1 = 0;
1113  outy2 = 8;
1114  pic0 += 2 * (width -16);
1115  pic1 += 2 * (width -16);
1116 
1117  }
1118 
1119 }
1120 static void yuv444pto422(int * out,unsigned char *pic,int width)
1121 {
1122  int j, k;
1123  unsigned char *pic0, *pic1;
1124  int *outy, *outu, *outv;
1125  int outy1 = 0;
1126  int outy2 = 8;
1127  int outu1 = 0;
1128  int outv1 = 0;
1129 
1130  pic0 = pic;
1131  pic1 = pic + width;
1132  outy = out;
1133  outu = out + 64 * 4; // Ooops where did i invert ??
1134  outv = out + 64 * 5;
1135  for (j = 0; j < 4; j++) {
1136  for (k = 0; k < 4; k++) {
1137 
1138  *pic0++ =CLIP( outy[outy1]);
1139  *pic0++ =CLIP( 128 + outu[outu1]);
1140  *pic0++ =CLIP( outy[outy1+1]);
1141  *pic0++ =CLIP( 128 + outv[outv1]);
1142  *pic1++ =CLIP( outy[outy2]);
1143  *pic1++ =CLIP( 128 + outu[outu1+8]);
1144  *pic1++ =CLIP( outy[outy2+1]);
1145  *pic1++ =CLIP( 128 + outv[outv1+8]);
1146  outv1 += 2; outu1 += 2;
1147  outy1 +=2; outy2 +=2;
1148  }
1149  outy += 16;outu +=16; outv +=16;
1150  outv1 = 0; outu1=0;
1151  outy1 = 0;
1152  outy2 = 8;
1153  pic0 += 2 * (width -8);
1154  pic1 += 2 * (width -8);
1155  }
1156 
1157 }
1158 static void yuv400pto422(int * out,unsigned char *pic,int width)
1159 {
1160  int j, k;
1161  unsigned char *pic0, *pic1;
1162  int *outy ;
1163  int outy1 = 0;
1164  int outy2 = 8;
1165  pic0 = pic;
1166  pic1 = pic + width;
1167  outy = out;
1168 
1169  for (j = 0; j < 4; j++) {
1170  for (k = 0; k < 4; k++) {
1171  *pic0++ = CLIP(outy[outy1]);
1172  *pic0++ = 128 ;
1173  *pic0++ = CLIP(outy[outy1+1]);
1174  *pic0++ = 128 ;
1175  *pic1++ = CLIP(outy[outy2]);
1176  *pic1++ = 128 ;
1177  *pic1++ = CLIP(outy[outy2+1]);
1178  *pic1++ = 128 ;
1179  outy1 +=2; outy2 +=2;
1180  }
1181  outy += 16;
1182  outy1 = 0;
1183  outy2 = 8;
1184  pic0 += 2 * (width -8);
1185  pic1 += 2 * (width -8);
1186  }
1187 
1188 }
1189 static unsigned char zig[64] = {
1190  0, 1, 5, 6, 14, 15, 27, 28,
1191  2, 4, 7, 13, 16, 26, 29, 42,
1192  3, 8, 12, 17, 25, 30, 41, 43,
1193  9, 11, 18, 24, 31, 40, 44, 53,
1194  10, 19, 23, 32, 39, 45, 52, 54,
1195  20, 22, 33, 38, 46, 51, 55, 60,
1196  21, 34, 37, 47, 50, 56, 59, 61,
1197  35, 36, 48, 49, 57, 58, 62, 63
1198 };
1199 
1200 static PREC aaidct[8] = {
1201  IFIX(0.3535533906), IFIX(0.4903926402),
1202  IFIX(0.4619397663), IFIX(0.4157348062),
1203  IFIX(0.3535533906), IFIX(0.2777851165),
1204  IFIX(0.1913417162), IFIX(0.0975451610)
1205 };
1206 
1207 
1208 static void idctqtab(qin, qout)
1209 unsigned char *qin;
1210 PREC *qout;
1211 {
1212  int i, j;
1213 
1214  for (i = 0; i < 8; i++)
1215  for (j = 0; j < 8; j++)
1216  qout[zig[i * 8 + j]] = qin[zig[i * 8 + j]] *
1217  IMULT(aaidct[i], aaidct[j]);
1218 }
1219 
1220 
1221 int
1222 is_huffman(unsigned char *buf)
1223 {
1224 unsigned char *ptbuf;
1225 int i = 0;
1226 ptbuf = buf;
1227 while (((ptbuf[0] << 8) | ptbuf[1]) != 0xffda){
1228  if(i++ > 2048)
1229  return 0;
1230  if(((ptbuf[0] << 8) | ptbuf[1]) == 0xffc4)
1231  return 1;
1232  ptbuf++;
1233 }
1234 return 0;
1235 }
1236 static void
1237  getPictureName (char *Picture, int fmt)
1238 {
1239 char temp[80];
1240  char *myext[] = { "pnm", "jpg" };
1241  int i;
1242  time_t curdate;
1243  struct tm *tdate;
1244  memset (temp, '\0', sizeof (temp));
1245  time (&curdate);
1246  tdate = localtime (&curdate);
1247  snprintf (temp, 26, "P-%02d:%02d:%04d-%02d:%02d:%02d.%s%c",
1248  tdate->tm_mon + 1, tdate->tm_mday, tdate->tm_year + 1900,
1249  tdate->tm_hour, tdate->tm_min, tdate->tm_sec, myext[fmt],'\0');
1250 
1251  memcpy (Picture, temp, strlen (temp));
1252 }
1253 int
1254 get_picture(unsigned char *buf,int size)
1255 {
1256 FILE *file;
1257 unsigned char *ptdeb,*ptcur = buf;
1258 int sizein;
1259 char *name = NULL;
1260 name = calloc(80,1);
1261 getPictureName (name, 1);
1262 file = fopen(name, "wb");
1263 if (file != NULL) {
1264  if(!is_huffman(buf)){
1265  ptdeb = ptcur = buf;
1266  while (((ptcur[0] << 8) | ptcur[1]) != 0xffc0)
1267  ptcur++;
1268  sizein = ptcur-ptdeb;
1269  fwrite(buf,
1270  sizein, 1, file);
1271  fwrite(dht_data,
1272  DHT_SIZE, 1, file);
1273  fwrite(ptcur,size-sizein,1,file);
1274  } else {
1275  fwrite(ptcur,size,1,file); /* ptcur was uninit -wsr */
1276  }
1277  fclose(file);
1278  }
1279 if(name)
1280  free(name);
1281 return 0;
1282 }
1283 
1284 int
1285 get_pictureYV2(unsigned char *buf,int width,int height)
1286 {
1287 FILE *foutpict;
1288 unsigned char *picture = NULL;
1289 char *name = NULL;
1290 name = calloc(80,1);
1291 getPictureName (name, 0);
1292 picture = (unsigned char *)malloc(width*height*3*sizeof(char));
1293 if(picture){
1294  Pyuv422torgb24(buf, picture, width, height);
1295 }else{
1296  printf(" no room to take a picture \n");
1297  return 0;
1298 }
1299 if(name){
1300  foutpict = fopen (name, "wb");
1301  fprintf (foutpict, "P6\n%d %d\n255\n", width, height);
1302  fwrite (picture, sizeof (char), width * height * 3, foutpict);
1303  fclose (foutpict);
1304  free(name);
1305 }
1306 free(picture);
1307 picture = NULL;
1308 return 0;
1309 }
Definition: utils.c:73
unsigned char B_FROMYU(unsigned char y, unsigned char u)
Definition: color.c:73
static void idctqtab(unsigned char *qin, PREC *qout)
Definition: utils.c:1208
int get_picture(unsigned char *buf, int size)
Definition: utils.c:1254
static int getbyte(void)
Definition: utils.c:136
int hv
Definition: utils.c:151
#define ERR_ILLEGAL_HV
Definition: utils.h:30
static PREC aaidct[8]
Definition: utils.c:1200
static void idct(int *in, int *out, int *quant, long off, int max)
Definition: utils.c:816
void(* ftopict)(int *out, unsigned char *pic, int width)
Definition: utils.c:120
static struct scan dscans[MAXCOMP]
Definition: utils.c:167
#define dec_huffdc
Definition: utils.c:173
#define M_DHT
Definition: utils.c:127
#define IMULT(a, b)
Definition: utils.c:798
#define ERR_BAD_WIDTH_OR_HEIGHT
Definition: utils.h:28
static int getword(void)
Definition: utils.c:141
#define M_RST0
Definition: utils.c:130
unsigned char G_FROMYUV(unsigned char y, unsigned char u, unsigned char v)
Definition: color.c:68
#define S22
Definition: utils.c:801
int dcts[6 *64+16]
Definition: utils.c:50
static void decode_mcus(struct in *in, int *dct, int n, struct scan *sc, int *maxp)
Definition: utils.c:708
#define ERR_UNKNOWN_CID_IN_SCAN
Definition: utils.h:33
static int dec_readmarker(struct in *in)
Definition: utils.c:626
int get_pictureYV2(unsigned char *buf, int width, int height)
Definition: utils.c:1285
#define LEBI_PUT(in)
Definition: utils.c:641
struct enc_hufftbl * ehuff
Definition: utils.c:70
#define M_SOI
Definition: utils.c:123
int cid
Definition: utils.c:150
#define ERR_NOT_8BIT
Definition: utils.h:25
#define M_BADHUFF
Definition: utils.c:46
static unsigned char zig2[64]
Definition: utils.c:805
#define PREC
Definition: utils.c:106
int tq
Definition: utils.c:152
#define ERR_QUANT_TABLE_SELECTOR
Definition: utils.h:31
Definition: utils.c:149
static struct comp comps[MAXCOMP]
Definition: utils.c:165
#define C22
Definition: utils.c:802
static unsigned char zig[64]
Definition: utils.c:1189
int left
Definition: utils.c:58
int maxcode[17]
Definition: utils.c:90
static struct jpginfo info
Definition: utils.c:164
#define JPG_HUFFMAN_TABLE_LENGTH
Definition: huffman.h:50
static void yuv422pto422(int *out, unsigned char *pic, int width)
Definition: utils.c:1075
#define LEBI_GET(in)
Definition: utils.c:640
void Pyuv422tobgr24(unsigned char *input_ptr, unsigned char *output_ptr, unsigned int image_width, unsigned int image_height)
Definition: utils.c:1008
static void yuv400pto422(int *out, unsigned char *pic, int width)
Definition: utils.c:1158
#define ERR_NO_EOI
Definition: utils.h:36
#define IC4
Definition: utils.c:803
#define M_EOI
Definition: utils.c:131
static void setinput(struct in *in, unsigned char *p)
Definition: utils.c:585
static void dec_makehuff(struct dec_hufftbl *hu, int *hufflen, unsigned char *huffvals)
Definition: utils.c:744
static struct dec_hufftbl dhuff[4]
Definition: utils.c:171
int out[64 *6]
Definition: utils.c:51
#define ERR_BAD_TABLES
Definition: utils.h:37
int jpeg_decode(unsigned char **pic, unsigned char *buf, int *width, int *height)
Definition: utils.c:282
static void getPictureName(char *Picture, int fmt)
Definition: utils.c:1237
union hufftblp hudc
Definition: utils.c:76
unsigned int Pyuv422torgb24(unsigned char *input_ptr, unsigned char *output_ptr, unsigned int image_width, unsigned int image_height)
Definition: utils.c:982
#define M_SOS
Definition: utils.c:129
static int readtables(int till, int *isDHT)
Definition: utils.c:178
#define ERR_TOO_MANY_COMPPS
Definition: utils.h:29
int ns
Definition: utils.c:158
static void yuv420pto422(int *out, unsigned char *pic, int width)
Definition: utils.c:1032
static int huffman_init(void)
Definition: utils.c:552
int next
Definition: utils.c:78
#define ERR_WRONG_MARKER
Definition: utils.h:35
Definition: utils.c:156
#define ERR_NOT_YCBCR_221111
Definition: utils.h:32
#define CLIP(color)
Definition: color.h:50
static unsigned char dht_data[DHT_SIZE]
Definition: huffman.h:4
#define M_EOF
Definition: utils.c:47
#define DHT_SIZE
Definition: huffman.h:2
Definition: utils.c:55
static int dec_rec2(struct in *in, struct dec_hufftbl *hu, int *runp, int c, int i)
Definition: utils.c:654
#define UNGETBITS(in, n)
Definition: utils.c:649
#define M_DRI
Definition: utils.c:128
#define DEC_REC(in, hu, r, i)
Definition: utils.c:690
#define ITOINT(a)
Definition: utils.c:799
#define ERR_NO_SOI
Definition: utils.h:24
#define GETBITS(in, n)
Definition: utils.c:643
static unsigned char quant[4][64]
Definition: utils.c:169
union hufftblp huac
Definition: utils.c:77
int cid
Definition: utils.c:80
unsigned char vals[256]
Definition: utils.c:92
int marker
Definition: utils.c:59
#define dec_huffac
Definition: utils.c:174
unsigned char R_FROMYV(unsigned char y, unsigned char v)
Definition: color.c:63
unsigned int Pyuv422togray8(unsigned char *input_ptr, unsigned char *output_ptr, unsigned int image_width, unsigned int image_height)
Definition: utils.c:968
static unsigned char * datap
Definition: utils.c:134
#define __P(x)
Definition: utils.c:42
#define DECBITS
Definition: utils.c:87
#define IFIX(a)
Definition: utils.c:39
#define MAXCOMP
Definition: utils.c:155
unsigned char * p
Definition: utils.c:56
#define LEBI_DCL
Definition: utils.c:639
unsigned int bits
Definition: utils.c:57
int hv
Definition: utils.c:81
int nc
Definition: utils.c:157
static void yuv444pto422(int *out, unsigned char *pic, int width)
Definition: utils.c:1120
static int dec_checkmarker(void)
Definition: utils.c:268
struct dec_hufftbl * dhuff
Definition: utils.c:69
const unsigned char JPEGHuffmanTable[JPG_HUFFMAN_TABLE_LENGTH]
Definition: huffman.h:53
int valptr[16]
Definition: utils.c:91
int dc
Definition: utils.c:74
int is_huffman(unsigned char *buf)
Definition: utils.c:1222
#define M_SOF0
Definition: utils.c:126
int tq
Definition: utils.c:82
static int fillbits(struct in *in, int le, unsigned int bi)
Definition: utils.c:595
int rm
Definition: utils.c:161
int dri
Definition: utils.c:159
int nm
Definition: utils.c:160
#define FOUR_TWO_TWO
Definition: utils.c:962
#define M_DQT
Definition: utils.c:125
int dquant[3][64]
Definition: utils.c:52
Definition: utils.c:68
static void dec_initscans(void)
Definition: utils.c:258


tuw_uvc
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:39:24