Mercurial > mplayer.hg
annotate libmpcodecs/native/cyuv.c @ 8507:3f9940a98d7f
updated
author | alex |
---|---|
date | Sat, 21 Dec 2002 18:11:10 +0000 |
parents | efa56e59a01c |
children |
rev | line source |
---|---|
3969 | 1 /* ------------------------------------------------------------------------ |
2 * Creative YUV Video Decoder | |
3 * | |
4 * Dr. Tim Ferguson, 2001. | |
5 * For more details on the algorithm: | |
6 * http://www.csse.monash.edu.au/~timf/videocodec.html | |
7 * | |
8 * This is a very simple predictive coder. A video frame is coded in YUV411 | |
9 * format. The first pixel of each scanline is coded using the upper four | |
10 * bits of its absolute value. Subsequent pixels for the scanline are coded | |
11 * using the difference between the last pixel and the current pixel (DPCM). | |
12 * The DPCM values are coded using a 16 entry table found at the start of the | |
13 * frame. Thus four bits per component are used and are as follows: | |
14 * UY VY YY UY VY YY UY VY... | |
15 * This code assumes the frame width will be a multiple of four pixels. This | |
16 * should probably be fixed. | |
17 * ------------------------------------------------------------------------ */ | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 #include <sys/types.h> | |
22 #include <unistd.h> | |
23 | |
7468 | 24 #include "img_format.h" |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
25 |
3969 | 26 /* ------------------------------------------------------------------------ |
27 * This function decodes a buffer containing a CYUV encoded frame. | |
28 * | |
29 * buf - the input buffer to be decoded | |
30 * size - the size of the input buffer | |
31 * frame - the output frame buffer (UYVY format) | |
32 * width - the width of the output frame | |
33 * height - the height of the output frame | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
34 * format - the requested output format |
3969 | 35 */ |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
36 void decode_cyuv(unsigned char *buf, int size, unsigned char *frame, int width, int height, int format) |
3969 | 37 { |
7518 | 38 unsigned int i, xpos, ypos; |
39 unsigned char *delta_y_tbl, *delta_c_tbl, *ptr; | |
3969 | 40 |
41 delta_y_tbl = buf + 16; | |
42 delta_c_tbl = buf + 32; | |
43 ptr = buf + (16 * 3); | |
44 | |
45 for(ypos = 0; ypos < height; ypos++) | |
7518 | 46 for(xpos = 0; xpos < width; xpos += 2){ |
47 unsigned char cur_Y1,cur_Y2,cur_U,cur_V; | |
48 if(xpos&2){ | |
49 i = *(ptr++); | |
50 cur_Y1 = (cur_Y2 + delta_y_tbl[i & 0x0f])/* & 0xff*/; | |
51 cur_Y2 = (cur_Y1 + delta_y_tbl[i >> 4])/* & 0xff*/; | |
52 } else { | |
53 if(xpos == 0) { /* first pixels in scanline */ | |
3969 | 54 cur_U = *(ptr++); |
7518 | 55 cur_Y1= (cur_U & 0x0f) << 4; |
3969 | 56 cur_U = cur_U & 0xf0; |
57 cur_V = *(ptr++); | |
7518 | 58 cur_Y2= (cur_Y1 + delta_y_tbl[cur_V & 0x0f])/* & 0xff*/; |
3969 | 59 cur_V = cur_V & 0xf0; |
7518 | 60 } else { /* subsequent pixels in scanline */ |
61 i = *(ptr++); | |
62 cur_U = (cur_U + delta_c_tbl[i >> 4])/* & 0xff*/; | |
63 cur_Y1= (cur_Y2 + delta_y_tbl[i & 0x0f])/* & 0xff*/; | |
3969 | 64 i = *(ptr++); |
7518 | 65 cur_V = (cur_V + delta_c_tbl[i >> 4])/* & 0xff*/; |
66 cur_Y2= (cur_Y1 + delta_y_tbl[i & 0x0f])/* & 0xff*/; | |
67 } | |
68 } | |
3969 | 69 |
7518 | 70 if (format == IMGFMT_YUY2) { |
71 *frame++ = cur_Y1; | |
72 *frame++ = cur_U; | |
73 *frame++ = cur_Y2; | |
74 *frame++ = cur_V; | |
75 } else { | |
76 *frame++ = cur_U; | |
77 *frame++ = cur_Y1; | |
78 *frame++ = cur_V; | |
79 *frame++ = cur_Y2; | |
80 } | |
81 } | |
3969 | 82 |
83 } | |
84 |