annotate libmpcodecs/vd_cyuv.c @ 9920:cf5ae3f6175c

ffindeo3 (diff from mplayerxp-cvslog) untested
author michael
date Tue, 15 Apr 2003 20:40:11 +0000
parents 84f406c22df1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7519
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
1 /* ------------------------------------------------------------------------
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
2 * Creative YUV Video Decoder
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
3 *
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
4 * Dr. Tim Ferguson, 2001.
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
5 * For more details on the algorithm:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
6 * http://www.csse.monash.edu.au/~timf/videocodec.html
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
7 *
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
8 * Code restructured, and adopted to MPlayer's mpi by A'rpi, 2002.
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
9 *
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
10 * This is a very simple predictive coder. A video frame is coded in YUV411
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
11 * format. The first pixel of each scanline is coded using the upper four
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
12 * bits of its absolute value. Subsequent pixels for the scanline are coded
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
13 * using the difference between the last pixel and the current pixel (DPCM).
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
14 * The DPCM values are coded using a 16 entry table found at the start of the
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
15 * frame. Thus four bits per component are used and are as follows:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
16 * UY VY YY UY VY YY UY VY...
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
17 * ------------------------------------------------------------------------ */
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
18
4989
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
19 #include <stdio.h>
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
20 #include <stdlib.h>
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
21
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
22 #include "config.h"
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
23 #include "mp_msg.h"
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
24
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
25 #include "vd_internal.h"
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
26
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
27 static vd_info_t info = {
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
28 "Creative YUV decoder",
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
29 "cyuv",
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
30 "A'rpi",
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
31 "Dr. Tim Ferguson",
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
32 "native codec"
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
33 };
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
34
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
35 LIBVD_EXTERN(cyuv)
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
36
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
37 // to set/get/query special features/parameters
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
38 static int control(sh_video_t *sh,int cmd,void* arg,...){
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
39 return CONTROL_UNKNOWN;
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
40 }
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
41
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
42 // init driver
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
43 static int init(sh_video_t *sh){
7519
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
44 return mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_411P);
4989
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
45 }
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
46
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
47 // uninit driver
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
48 static void uninit(sh_video_t *sh){
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
49 }
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
50
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
51 // decode a frame
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
52 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
53 mp_image_t* mpi;
7519
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
54 unsigned int xpos, ypos;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
55 unsigned char *delta_y_tbl = ((unsigned char*)data)+16;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
56 unsigned char *delta_c_tbl = ((unsigned char*)data)+32;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
57 unsigned char *ptr = ((unsigned char*)data)+48;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
58
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
59 if(len<=48) return NULL; // skipped/broken frame
4989
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
60
7519
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
61 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
4989
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
62 sh->disp_w, sh->disp_h);
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
63 if(!mpi) return NULL;
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
64
7519
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
65 for(ypos = 0; ypos < mpi->h; ypos++){
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
66 unsigned int i;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
67 unsigned char cur_Y1,cur_Y2,cur_U,cur_V;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
68 unsigned char *frame=mpi->planes[0]+mpi->stride[0]*ypos;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
69 unsigned char *uframe=mpi->planes[1]+mpi->stride[1]*ypos;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
70 unsigned char *vframe=mpi->planes[2]+mpi->stride[2]*ypos;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
71
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
72 for(xpos = 0; xpos < mpi->w; xpos += 2){
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
73
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
74 if(xpos&2){
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
75 i = *(ptr++);
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
76 cur_Y1 = (cur_Y2 + delta_y_tbl[i & 0x0f])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
77 cur_Y2 = (cur_Y1 + delta_y_tbl[i >> 4])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
78 } else {
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
79 if(xpos == 0) { /* first pixels in scanline */
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
80 cur_U = *(ptr++);
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
81 cur_Y1= (cur_U & 0x0f) << 4;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
82 cur_U = cur_U & 0xf0;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
83 cur_V = *(ptr++);
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
84 cur_Y2= (cur_Y1 + delta_y_tbl[cur_V & 0x0f])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
85 cur_V = cur_V & 0xf0;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
86 } else { /* subsequent pixels in scanline */
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
87 i = *(ptr++);
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
88 cur_U = (cur_U + delta_c_tbl[i >> 4])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
89 cur_Y1= (cur_Y2 + delta_y_tbl[i & 0x0f])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
90 i = *(ptr++);
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
91 cur_V = (cur_V + delta_c_tbl[i >> 4])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
92 cur_Y2= (cur_Y1 + delta_y_tbl[i & 0x0f])/* & 0xff*/;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
93 }
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
94 }
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
95
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
96 // ok, store the pixels:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
97 switch(mpi->imgfmt){
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
98 case IMGFMT_YUY2:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
99 *frame++ = cur_Y1;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
100 *frame++ = cur_U;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
101 *frame++ = cur_Y2;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
102 *frame++ = cur_V;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
103 break;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
104 case IMGFMT_UYVY:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
105 *frame++ = cur_U;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
106 *frame++ = cur_Y1;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
107 *frame++ = cur_V;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
108 *frame++ = cur_Y2;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
109 break;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
110 case IMGFMT_422P:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
111 *uframe++ = cur_U;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
112 *vframe++ = cur_V;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
113 *frame++ = cur_Y1;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
114 *frame++ = cur_Y2;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
115 break;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
116 case IMGFMT_411P:
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
117 if(!(xpos&2)){
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
118 *uframe++ = cur_U;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
119 *vframe++ = cur_V;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
120 }
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
121 *frame++ = cur_Y1;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
122 *frame++ = cur_Y2;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
123 break;
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
124 }
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
125 } // xpos
84f406c22df1 decoder merged, using mpi now. support for stride, and outfmt 411p,422p
arpi
parents: 7180
diff changeset
126 } // ypos
4989
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
127
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
128 return mpi;
11d8bf468334 cyuv, nuv, qtrle, qtsmc, roq added
arpi
parents:
diff changeset
129 }