1 #ifndef MPLAYER_MP_IMAGE_H
2 #define MPLAYER_MP_IMAGE_H
8 //--------- codec's requirements (filled by the codec/vf) ---------
10 //--- buffer content restrictions:
11 // set if buffer content shouldn't be modified:
12 #define MP_IMGFLAG_PRESERVE 0x01
13 // set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
14 #define MP_IMGFLAG_READABLE 0x02
16 //--- buffer width/stride/plane restrictions: (used for direct rendering)
17 // stride _have_to_ be aligned to MB boundary: [for DR restrictions]
18 #define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE 0x4
19 // stride should be aligned to MB boundary: [for buffer allocation]
20 #define MP_IMGFLAG_PREFER_ALIGNED_STRIDE 0x8
21 // codec accept any stride (>=width):
22 #define MP_IMGFLAG_ACCEPT_STRIDE 0x10
23 // codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width):
24 #define MP_IMGFLAG_ACCEPT_WIDTH 0x20
25 //--- for planar formats only:
26 // uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift
27 #define MP_IMGFLAG_COMMON_STRIDE 0x40
28 // uses only planes[0], and calculates planes[1,2] from width,height,imgfmt
29 #define MP_IMGFLAG_COMMON_PLANE 0x80
31 #define MP_IMGFLAGMASK_RESTRICTIONS 0xFF
33 //--------- color info (filled by mp_image_setfmt() ) -----------
34 // set if number of planes > 1
35 #define MP_IMGFLAG_PLANAR 0x100
36 // set if it's YUV colorspace
37 #define MP_IMGFLAG_YUV 0x200
38 // set if it's swapped (BGR or YVU) plane/byteorder
39 #define MP_IMGFLAG_SWAPPED 0x400
40 // using palette for RGB data
41 #define MP_IMGFLAG_RGB_PALETTE 0x800
43 #define MP_IMGFLAGMASK_COLORS 0xF00
45 // codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2)
46 // [the codec will set this flag if it supports callbacks, and the vo _may_
47 // clear it in get_image() if draw_slice() not implemented]
48 #define MP_IMGFLAG_DRAW_CALLBACK 0x1000
49 // set if it's in video buffer/memory: [set by vo/vf's get_image() !!!]
50 #define MP_IMGFLAG_DIRECT 0x2000
51 // set if buffer is allocated (used in destination images):
52 #define MP_IMGFLAG_ALLOCATED 0x4000
54 // buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
55 #define MP_IMGFLAG_TYPE_DISPLAYED 0x8000
57 // codec doesn't support any form of direct rendering - it has own buffer
58 // allocation. so we just export its buffer pointers:
59 #define MP_IMGTYPE_EXPORT 0
60 // codec requires a static WO buffer, but it does only partial updates later:
61 #define MP_IMGTYPE_STATIC 1
62 // codec just needs some WO memory, where it writes/copies the whole frame to:
63 #define MP_IMGTYPE_TEMP 2
64 // I+P type, requires 2+ independent static R/W buffers
65 #define MP_IMGTYPE_IP 3
66 // I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers
67 #define MP_IMGTYPE_IPB 4
69 #define MP_MAX_PLANES 4
71 #define MP_IMGFIELD_ORDERED 0x01
72 #define MP_IMGFIELD_TOP_FIRST 0x02
73 #define MP_IMGFIELD_REPEAT_FIRST 0x04
74 #define MP_IMGFIELD_TOP 0x08
75 #define MP_IMGFIELD_BOTTOM 0x10
76 #define MP_IMGFIELD_INTERLACED 0x20
78 typedef struct mp_image
{
81 unsigned char bpp
; // bits/pixel. NOT depth! for RGB it will be n*8
83 int width
,height
; // stored dimensions
84 int x
,y
,w
,h
; // visible dimensions
85 unsigned char* planes
[MP_MAX_PLANES
];
86 int stride
[MP_MAX_PLANES
];
89 int pict_type
; // 0->unknown, 1->I, 2->P, 3->B
91 int qscale_type
; // 0->mpeg1/4/h263, 1->mpeg2
93 /* these are only used by planar formats Y,U(Cb),V(Cr) */
96 int chroma_x_shift
; // horizontal
97 int chroma_y_shift
; // vertical
98 /* for private use by filter or vo driver (to store buffer id or dmpi) */
103 static inline void mp_image_setfmt(mp_image_t
* mpi
,unsigned int out_fmt
){
104 mpi
->flags
&=~(MP_IMGFLAG_PLANAR
|MP_IMGFLAG_YUV
|MP_IMGFLAG_SWAPPED
);
106 if(out_fmt
== IMGFMT_MPEGPES
){
110 if(out_fmt
== IMGFMT_ZRMJPEGNI
||
111 out_fmt
== IMGFMT_ZRMJPEGIT
||
112 out_fmt
== IMGFMT_ZRMJPEGIB
){
116 if(IMGFMT_IS_XVMC(out_fmt
)){
121 if (IMGFMT_IS_RGB(out_fmt
)) {
122 if (IMGFMT_RGB_DEPTH(out_fmt
) < 8 && !(out_fmt
&128))
123 mpi
->bpp
= IMGFMT_RGB_DEPTH(out_fmt
);
125 mpi
->bpp
=(IMGFMT_RGB_DEPTH(out_fmt
)+7)&(~7);
128 if (IMGFMT_IS_BGR(out_fmt
)) {
129 if (IMGFMT_BGR_DEPTH(out_fmt
) < 8 && !(out_fmt
&128))
130 mpi
->bpp
= IMGFMT_BGR_DEPTH(out_fmt
);
132 mpi
->bpp
=(IMGFMT_BGR_DEPTH(out_fmt
)+7)&(~7);
133 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
136 mpi
->flags
|=MP_IMGFLAG_YUV
;
141 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
143 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
145 mpi
->chroma_width
=(mpi
->width
>>1);
146 mpi
->chroma_height
=(mpi
->height
>>1);
147 mpi
->chroma_x_shift
=1;
148 mpi
->chroma_y_shift
=1;
153 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
155 mpi
->chroma_width
=(mpi
->width
>>2);
156 mpi
->chroma_height
=(mpi
->height
>>2);
157 mpi
->chroma_x_shift
=2;
158 mpi
->chroma_y_shift
=2;
161 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
163 mpi
->chroma_width
=(mpi
->width
);
164 mpi
->chroma_height
=(mpi
->height
);
165 mpi
->chroma_x_shift
=0;
166 mpi
->chroma_y_shift
=0;
169 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
171 mpi
->chroma_width
=(mpi
->width
>>1);
172 mpi
->chroma_height
=(mpi
->height
);
173 mpi
->chroma_x_shift
=1;
174 mpi
->chroma_y_shift
=0;
177 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
179 mpi
->chroma_width
=(mpi
->width
>>2);
180 mpi
->chroma_height
=(mpi
->height
);
181 mpi
->chroma_x_shift
=2;
182 mpi
->chroma_y_shift
=0;
186 /* they're planar ones, but for easier handling use them as packed */
187 // mpi->flags|=MP_IMGFLAG_PLANAR;
192 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
198 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
200 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
203 mpi
->chroma_width
=(mpi
->width
>>0);
204 mpi
->chroma_height
=(mpi
->height
>>1);
205 mpi
->chroma_x_shift
=0;
206 mpi
->chroma_y_shift
=1;
209 fprintf(stderr
,"mp_image: unknown out_fmt: 0x%X\n",out_fmt
);
214 static inline mp_image_t
* new_mp_image(int w
,int h
){
215 mp_image_t
* mpi
=(mp_image_t
*)malloc(sizeof(mp_image_t
));
216 if(!mpi
) return NULL
; // error!
217 memset(mpi
,0,sizeof(mp_image_t
));
219 mpi
->height
=mpi
->h
=h
;
223 static inline void free_mp_image(mp_image_t
* mpi
){
225 if(mpi
->flags
&MP_IMGFLAG_ALLOCATED
){
226 /* becouse we allocate the whole image in once */
227 if(mpi
->planes
[0]) free(mpi
->planes
[0]);
232 mp_image_t
* alloc_mpi(int w
, int h
, unsigned long int fmt
);
233 void copy_mpi(mp_image_t
*dmpi
, mp_image_t
*mpi
);
235 #endif /* MPLAYER_MP_IMAGE_H */