comparison libmpcodecs/native/cyuv.c @ 5602:628c85c15c7b

moved to libmpcodecs/native/
author arpi
date Sat, 13 Apr 2002 18:03:02 +0000
parents cyuv.c@eea0213d64c8
children 9360e5203200
comparison
equal deleted inserted replaced
5601:fd85802f755b 5602:628c85c15c7b
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 #include "loader/wine/avifmt.h" // for mmioFOURCC macro
25
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
34 * format - the requested output format
35 */
36 void decode_cyuv(unsigned char *buf, int size, unsigned char *frame, int width, int height, int format)
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;
53 if (format == mmioFOURCC('Y','U','Y','2'))
54 {
55 *frame++ = cur_Y;
56 *frame++ = cur_U;
57 }
58 else
59 {
60 *frame++ = cur_U;
61 *frame++ = cur_Y;
62 }
63
64 cur_V = *(ptr++);
65 cur_Y = (cur_Y + delta_y_tbl[cur_V & 0x0f]) & 0xff;
66 cur_V = cur_V & 0xf0;
67 if (format == mmioFOURCC('Y','U','Y','2'))
68 {
69 *frame++ = cur_Y;
70 *frame++ = cur_V;
71 }
72 else
73 {
74 *frame++ = cur_V;
75 *frame++ = cur_Y;
76 }
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;
83 if (format == mmioFOURCC('Y','U','Y','2'))
84 {
85 *frame++ = cur_Y;
86 *frame++ = cur_U;
87 }
88 else
89 {
90 *frame++ = cur_U;
91 *frame++ = cur_Y;
92 }
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;
97 if (format == mmioFOURCC('Y','U','Y','2'))
98 {
99 *frame++ = cur_Y;
100 *frame++ = cur_V;
101 }
102 else
103 {
104 *frame++ = cur_V;
105 *frame++ = cur_Y;
106 }
107 }
108
109 i = *(ptr++);
110 cur_Y = (cur_Y + delta_y_tbl[i & 0x0f]) & 0xff;
111 if (format == mmioFOURCC('Y','U','Y','2'))
112 {
113 *frame++ = cur_Y;
114 *frame++ = cur_U;
115 }
116 else
117 {
118 *frame++ = cur_U;
119 *frame++ = cur_Y;
120 }
121
122 cur_Y = (cur_Y + delta_y_tbl[i >> 4]) & 0xff;
123 if (format == mmioFOURCC('Y','U','Y','2'))
124 {
125 *frame++ = cur_Y;
126 *frame++ = cur_V;
127 }
128 else
129 {
130 *frame++ = cur_V;
131 *frame++ = cur_Y;
132 }
133 }
134 }
135