annotate cyuv.c @ 5260:7a37ce6f3464

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