annotate libmpcodecs/native/cyuv.c @ 8507:3f9940a98d7f

updated
author alex
date Sat, 21 Dec 2002 18:11:10 +0000
parents efa56e59a01c
children
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
7468
9360e5203200 use img_format.h instead of wine/mmioFOURCC hack
arpi
parents: 5602
diff changeset
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
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 * This function decodes a buffer containing a CYUV encoded frame.
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
28 *
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
29 * buf - the input buffer to be decoded
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
30 * size - the size of the input buffer
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
31 * frame - the output frame buffer (UYVY format)
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
32 * width - the width of the output frame
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
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
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
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
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
37 {
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
38 unsigned int i, xpos, ypos;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
39 unsigned char *delta_y_tbl, *delta_c_tbl, *ptr;
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
40
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
41 delta_y_tbl = buf + 16;
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
42 delta_c_tbl = buf + 32;
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
43 ptr = buf + (16 * 3);
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
44
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
45 for(ypos = 0; ypos < height; ypos++)
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
46 for(xpos = 0; xpos < width; xpos += 2){
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
47 unsigned char cur_Y1,cur_Y2,cur_U,cur_V;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
48 if(xpos&2){
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
49 i = *(ptr++);
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
50 cur_Y1 = (cur_Y2 + delta_y_tbl[i & 0x0f])/* & 0xff*/;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
51 cur_Y2 = (cur_Y1 + delta_y_tbl[i >> 4])/* & 0xff*/;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
52 } else {
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
53 if(xpos == 0) { /* first pixels in scanline */
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
54 cur_U = *(ptr++);
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
55 cur_Y1= (cur_U & 0x0f) << 4;
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
56 cur_U = cur_U & 0xf0;
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
57 cur_V = *(ptr++);
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
58 cur_Y2= (cur_Y1 + delta_y_tbl[cur_V & 0x0f])/* & 0xff*/;
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
59 cur_V = cur_V & 0xf0;
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
60 } else { /* subsequent pixels in scanline */
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
61 i = *(ptr++);
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
62 cur_U = (cur_U + delta_c_tbl[i >> 4])/* & 0xff*/;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
63 cur_Y1= (cur_Y2 + delta_y_tbl[i & 0x0f])/* & 0xff*/;
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
64 i = *(ptr++);
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
65 cur_V = (cur_V + delta_c_tbl[i >> 4])/* & 0xff*/;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
66 cur_Y2= (cur_Y1 + delta_y_tbl[i & 0x0f])/* & 0xff*/;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
67 }
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
68 }
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
69
7518
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
70 if (format == IMGFMT_YUY2) {
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
71 *frame++ = cur_Y1;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
72 *frame++ = cur_U;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
73 *frame++ = cur_Y2;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
74 *frame++ = cur_V;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
75 } else {
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
76 *frame++ = cur_U;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
77 *frame++ = cur_Y1;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
78 *frame++ = cur_V;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
79 *frame++ = cur_Y2;
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
80 }
efa56e59a01c some cleanup
arpi
parents: 7468
diff changeset
81 }
3969
c4c3f32dae47 integrated Tim Ferguson's native CYUV decoder
melanson
parents:
diff changeset
82
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