Mercurial > mplayer.hg
annotate libmpcodecs/native/cyuv.c @ 6713:cc917a581b6e
add simple playlist support
author | pontscho |
---|---|
date | Fri, 12 Jul 2002 00:53:26 +0000 |
parents | 628c85c15c7b |
children | 9360e5203200 |
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 | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
24 #include "loader/wine/avifmt.h" // for mmioFOURCC macro |
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 { |
38 int i, xpos, ypos, cur_Y = 0, cur_U = 0, cur_V = 0; | |
39 char *delta_y_tbl, *delta_c_tbl, *ptr; | |
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++) | |
46 for(xpos = 0; xpos < width; xpos += 4) | |
47 { | |
48 if(xpos == 0) /* first pixels in scanline */ | |
49 { | |
50 cur_U = *(ptr++); | |
51 cur_Y = (cur_U & 0x0f) << 4; | |
52 cur_U = cur_U & 0xf0; | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
53 if (format == mmioFOURCC('Y','U','Y','2')) |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
54 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
55 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
56 *frame++ = cur_U; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
57 } |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
58 else |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
59 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
60 *frame++ = cur_U; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
61 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
62 } |
3969 | 63 |
64 cur_V = *(ptr++); | |
65 cur_Y = (cur_Y + delta_y_tbl[cur_V & 0x0f]) & 0xff; | |
66 cur_V = cur_V & 0xf0; | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
67 if (format == mmioFOURCC('Y','U','Y','2')) |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
68 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
69 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
70 *frame++ = cur_V; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
71 } |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
72 else |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
73 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
74 *frame++ = cur_V; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
75 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
76 } |
3969 | 77 } |
78 else /* subsequent pixels in scanline */ | |
79 { | |
80 i = *(ptr++); | |
81 cur_U = (cur_U + delta_c_tbl[i >> 4]) & 0xff; | |
82 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
83 if (format == mmioFOURCC('Y','U','Y','2')) |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
84 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
85 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
86 *frame++ = cur_U; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
87 } |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
88 else |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
89 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
90 *frame++ = cur_U; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
91 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
92 } |
3969 | 93 |
94 i = *(ptr++); | |
95 cur_V = (cur_V + delta_c_tbl[i >> 4]) & 0xff; | |
96 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
97 if (format == mmioFOURCC('Y','U','Y','2')) |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
98 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
99 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
100 *frame++ = cur_V; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
101 } |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
102 else |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
103 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
104 *frame++ = cur_V; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
105 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
106 } |
3969 | 107 } |
108 | |
109 i = *(ptr++); | |
110 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff; | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
111 if (format == mmioFOURCC('Y','U','Y','2')) |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
112 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
113 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
114 *frame++ = cur_U; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
115 } |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
116 else |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
117 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
118 *frame++ = cur_U; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
119 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
120 } |
3969 | 121 |
122 cur_Y = (cur_Y + delta_y_tbl[i >> 4]) & 0xff; | |
5351
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
123 if (format == mmioFOURCC('Y','U','Y','2')) |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
124 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
125 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
126 *frame++ = cur_V; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
127 } |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
128 else |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
129 { |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
130 *frame++ = cur_V; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
131 *frame++ = cur_Y; |
eea0213d64c8
added YUY2 output to the widely used (heh) CYUV decoder because it seemed
melanson
parents:
3969
diff
changeset
|
132 } |
3969 | 133 } |
134 } | |
135 |