typo fixes
[mplayer/greg.git] / libmpcodecs / mp_image.h
blobeb019a20ee4c883632771af43b846679c959e0a9
1 #ifndef __MP_IMAGE_H
2 #define __MP_IMAGE_H 1
4 //--------- codec's requirements (filled by the codec/vf) ---------
6 //--- buffer content restrictions:
7 // set if buffer content shouldn't be modified:
8 #define MP_IMGFLAG_PRESERVE 0x01
9 // set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
10 #define MP_IMGFLAG_READABLE 0x02
12 //--- buffer width/stride/plane restrictions: (used for direct rendering)
13 // stride _have_to_ be aligned to MB boundary: [for DR restrictions]
14 #define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE 0x4
15 // stride should be aligned to MB boundary: [for buffer allocation]
16 #define MP_IMGFLAG_PREFER_ALIGNED_STRIDE 0x8
17 // codec accept any stride (>=width):
18 #define MP_IMGFLAG_ACCEPT_STRIDE 0x10
19 // codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width):
20 #define MP_IMGFLAG_ACCEPT_WIDTH 0x20
21 //--- for planar formats only:
22 // uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift
23 #define MP_IMGFLAG_COMMON_STRIDE 0x40
24 // uses only planes[0], and calculates planes[1,2] from width,height,imgfmt
25 #define MP_IMGFLAG_COMMON_PLANE 0x80
27 #define MP_IMGFLAGMASK_RESTRICTIONS 0xFF
29 //--------- color info (filled by mp_image_setfmt() ) -----------
30 // set if number of planes > 1
31 #define MP_IMGFLAG_PLANAR 0x100
32 // set if it's YUV colorspace
33 #define MP_IMGFLAG_YUV 0x200
34 // set if it's swapped (BGR or YVU) plane/byteorder
35 #define MP_IMGFLAG_SWAPPED 0x400
36 // using palette for RGB data
37 #define MP_IMGFLAG_RGB_PALETTE 0x800
39 #define MP_IMGFLAGMASK_COLORS 0xF00
41 // codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2)
42 // [the codec will set this flag if it supports callbacks, and the vo _may_
43 // clear it in get_image() if draw_slice() not implemented]
44 #define MP_IMGFLAG_DRAW_CALLBACK 0x1000
45 // set if it's in video buffer/memory: [set by vo/vf's get_image() !!!]
46 #define MP_IMGFLAG_DIRECT 0x2000
47 // set if buffer is allocated (used in destination images):
48 #define MP_IMGFLAG_ALLOCATED 0x4000
50 // buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
51 #define MP_IMGFLAG_TYPE_DISPLAYED 0x8000
53 // codec doesn't support any form of direct rendering - it has own buffer
54 // allocation. so we just export its buffer pointers:
55 #define MP_IMGTYPE_EXPORT 0
56 // codec requires a static WO buffer, but it does only partial updates later:
57 #define MP_IMGTYPE_STATIC 1
58 // codec just needs some WO memory, where it writes/copies the whole frame to:
59 #define MP_IMGTYPE_TEMP 2
60 // I+P type, requires 2+ independent static R/W buffers
61 #define MP_IMGTYPE_IP 3
62 // I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers
63 #define MP_IMGTYPE_IPB 4
65 #define MP_MAX_PLANES 4
67 #define MP_IMGFIELD_ORDERED 0x01
68 #define MP_IMGFIELD_TOP_FIRST 0x02
69 #define MP_IMGFIELD_REPEAT_FIRST 0x04
70 #define MP_IMGFIELD_TOP 0x08
71 #define MP_IMGFIELD_BOTTOM 0x10
72 #define MP_IMGFIELD_INTERLACED 0x20
74 typedef struct mp_image_s {
75 unsigned short flags;
76 unsigned char type;
77 unsigned char bpp; // bits/pixel. NOT depth! for RGB it will be n*8
78 unsigned int imgfmt;
79 int width,height; // stored dimensions
80 int x,y,w,h; // visible dimensions
81 unsigned char* planes[MP_MAX_PLANES];
82 int stride[MP_MAX_PLANES];
83 char * qscale;
84 int qstride;
85 int pict_type; // 0->unknown, 1->I, 2->P, 3->B
86 int fields;
87 int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2
88 int num_planes;
89 /* these are only used by planar formats Y,U(Cb),V(Cr) */
90 int chroma_width;
91 int chroma_height;
92 int chroma_x_shift; // horizontal
93 int chroma_y_shift; // vertical
94 /* for private use by filter or vo driver (to store buffer id or dmpi) */
95 void* priv;
96 } mp_image_t;
98 #ifdef IMGFMT_YUY2
99 static inline void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){
100 mpi->flags&=~(MP_IMGFLAG_PLANAR|MP_IMGFLAG_YUV|MP_IMGFLAG_SWAPPED);
101 mpi->imgfmt=out_fmt;
102 if(out_fmt == IMGFMT_MPEGPES){
103 mpi->bpp=0;
104 return;
106 if(out_fmt == IMGFMT_ZRMJPEGNI ||
107 out_fmt == IMGFMT_ZRMJPEGIT ||
108 out_fmt == IMGFMT_ZRMJPEGIB){
109 mpi->bpp=0;
110 return;
112 if(IMGFMT_IS_XVMC(out_fmt)){
113 mpi->bpp=0;
114 return;
116 mpi->num_planes=1;
117 if (IMGFMT_IS_RGB(out_fmt)) {
118 if (IMGFMT_RGB_DEPTH(out_fmt) < 8 && !(out_fmt&128))
119 mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt);
120 else
121 mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7);
122 return;
124 if (IMGFMT_IS_BGR(out_fmt)) {
125 if (IMGFMT_BGR_DEPTH(out_fmt) < 8 && !(out_fmt&128))
126 mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt);
127 else
128 mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7);
129 mpi->flags|=MP_IMGFLAG_SWAPPED;
130 return;
132 mpi->flags|=MP_IMGFLAG_YUV;
133 mpi->num_planes=3;
134 switch(out_fmt){
135 case IMGFMT_I420:
136 case IMGFMT_IYUV:
137 mpi->flags|=MP_IMGFLAG_SWAPPED;
138 case IMGFMT_YV12:
139 mpi->flags|=MP_IMGFLAG_PLANAR;
140 mpi->bpp=12;
141 mpi->chroma_width=(mpi->width>>1);
142 mpi->chroma_height=(mpi->height>>1);
143 mpi->chroma_x_shift=1;
144 mpi->chroma_y_shift=1;
145 return;
146 case IMGFMT_IF09:
147 mpi->num_planes=4;
148 case IMGFMT_YVU9:
149 mpi->flags|=MP_IMGFLAG_PLANAR;
150 mpi->bpp=9;
151 mpi->chroma_width=(mpi->width>>2);
152 mpi->chroma_height=(mpi->height>>2);
153 mpi->chroma_x_shift=2;
154 mpi->chroma_y_shift=2;
155 return;
156 case IMGFMT_444P:
157 mpi->flags|=MP_IMGFLAG_PLANAR;
158 mpi->bpp=24;
159 mpi->chroma_width=(mpi->width);
160 mpi->chroma_height=(mpi->height);
161 mpi->chroma_x_shift=0;
162 mpi->chroma_y_shift=0;
163 return;
164 case IMGFMT_422P:
165 mpi->flags|=MP_IMGFLAG_PLANAR;
166 mpi->bpp=16;
167 mpi->chroma_width=(mpi->width>>1);
168 mpi->chroma_height=(mpi->height);
169 mpi->chroma_x_shift=1;
170 mpi->chroma_y_shift=0;
171 return;
172 case IMGFMT_411P:
173 mpi->flags|=MP_IMGFLAG_PLANAR;
174 mpi->bpp=12;
175 mpi->chroma_width=(mpi->width>>2);
176 mpi->chroma_height=(mpi->height);
177 mpi->chroma_x_shift=2;
178 mpi->chroma_y_shift=0;
179 return;
180 case IMGFMT_Y800:
181 case IMGFMT_Y8:
182 /* they're planar ones, but for easier handling use them as packed */
183 // mpi->flags|=MP_IMGFLAG_PLANAR;
184 mpi->bpp=8;
185 mpi->num_planes=1;
186 return;
187 case IMGFMT_UYVY:
188 mpi->flags|=MP_IMGFLAG_SWAPPED;
189 case IMGFMT_YUY2:
190 mpi->bpp=16;
191 mpi->num_planes=1;
192 return;
193 case IMGFMT_NV12:
194 mpi->flags|=MP_IMGFLAG_SWAPPED;
195 case IMGFMT_NV21:
196 mpi->flags|=MP_IMGFLAG_PLANAR;
197 mpi->bpp=12;
198 mpi->num_planes=2;
199 mpi->chroma_width=(mpi->width>>0);
200 mpi->chroma_height=(mpi->height>>1);
201 mpi->chroma_x_shift=0;
202 mpi->chroma_y_shift=1;
203 return;
205 fprintf(stderr,"mp_image: unknown out_fmt: 0x%X\n",out_fmt);
206 mpi->bpp=0;
208 #endif
210 static inline mp_image_t* new_mp_image(int w,int h){
211 mp_image_t* mpi=(mp_image_t*)malloc(sizeof(mp_image_t));
212 if(!mpi) return NULL; // error!
213 memset(mpi,0,sizeof(mp_image_t));
214 mpi->width=mpi->w=w;
215 mpi->height=mpi->h=h;
216 return mpi;
219 static inline void free_mp_image(mp_image_t* mpi){
220 if(!mpi) return;
221 if(mpi->flags&MP_IMGFLAG_ALLOCATED){
222 /* becouse we allocate the whole image in once */
223 if(mpi->planes[0]) free(mpi->planes[0]);
225 free(mpi);
228 #endif