Mercurial > mplayer.hg
comparison cyuv.c @ 3969:c4c3f32dae47
integrated Tim Ferguson's native CYUV decoder
author | melanson |
---|---|
date | Fri, 04 Jan 2002 05:57:00 +0000 |
parents | |
children | eea0213d64c8 |
comparison
equal
deleted
inserted
replaced
3968:3bbaeba57939 | 3969:c4c3f32dae47 |
---|---|
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 | |
24 /* ------------------------------------------------------------------------ | |
25 * This function decodes a buffer containing a CYUV encoded frame. | |
26 * | |
27 * buf - the input buffer to be decoded | |
28 * size - the size of the input buffer | |
29 * frame - the output frame buffer (UYVY format) | |
30 * width - the width of the output frame | |
31 * height - the height of the output frame | |
32 * bit_per_pixel - ignored for now: may be used later for conversions. | |
33 */ | |
34 void decode_cyuv(unsigned char *buf, int size, unsigned char *frame, int width, int height, int bit_per_pixel) | |
35 { | |
36 int i, xpos, ypos, cur_Y = 0, cur_U = 0, cur_V = 0; | |
37 char *delta_y_tbl, *delta_c_tbl, *ptr; | |
38 | |
39 delta_y_tbl = buf + 16; | |
40 delta_c_tbl = buf + 32; | |
41 ptr = buf + (16 * 3); | |
42 | |
43 for(ypos = 0; ypos < height; ypos++) | |
44 for(xpos = 0; xpos < width; xpos += 4) | |
45 { | |
46 if(xpos == 0) /* first pixels in scanline */ | |
47 { | |
48 cur_U = *(ptr++); | |
49 cur_Y = (cur_U & 0x0f) << 4; | |
50 cur_U = cur_U & 0xf0; | |
51 *frame++ = cur_U; | |
52 *frame++ = cur_Y; | |
53 | |
54 cur_V = *(ptr++); | |
55 cur_Y = (cur_Y + delta_y_tbl[cur_V & 0x0f]) & 0xff; | |
56 cur_V = cur_V & 0xf0; | |
57 *frame++ = cur_V; | |
58 *frame++ = cur_Y; | |
59 } | |
60 else /* subsequent pixels in scanline */ | |
61 { | |
62 i = *(ptr++); | |
63 cur_U = (cur_U + delta_c_tbl[i >> 4]) & 0xff; | |
64 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; | |
65 *frame++ = cur_U; | |
66 *frame++ = cur_Y; | |
67 | |
68 i = *(ptr++); | |
69 cur_V = (cur_V + delta_c_tbl[i >> 4]) & 0xff; | |
70 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; | |
71 *frame++ = cur_V; | |
72 *frame++ = cur_Y; | |
73 } | |
74 | |
75 i = *(ptr++); | |
76 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; | |
77 *frame++ = cur_U; | |
78 *frame++ = cur_Y; | |
79 | |
80 cur_Y = (cur_Y + delta_y_tbl[i >> 4]) & 0xff; | |
81 *frame++ = cur_V; | |
82 *frame++ = cur_Y; | |
83 } | |
84 } | |
85 |