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
{
77 unsigned char bpp
; // bits/pixel. NOT depth! for RGB it will be n*8
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
];
85 int pict_type
; // 0->unknown, 1->I, 2->P, 3->B
87 int qscale_type
; // 0->mpeg1/4/h263, 1->mpeg2
89 /* these are only used by planar formats Y,U(Cb),V(Cr) */
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) */
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
);
102 if(out_fmt
== IMGFMT_MPEGPES
){
106 if(out_fmt
== IMGFMT_ZRMJPEGNI
||
107 out_fmt
== IMGFMT_ZRMJPEGIT
||
108 out_fmt
== IMGFMT_ZRMJPEGIB
){
112 if(IMGFMT_IS_XVMC(out_fmt
)){
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
);
121 mpi
->bpp
=(IMGFMT_RGB_DEPTH(out_fmt
)+7)&(~7);
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
);
128 mpi
->bpp
=(IMGFMT_BGR_DEPTH(out_fmt
)+7)&(~7);
129 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
132 mpi
->flags
|=MP_IMGFLAG_YUV
;
137 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
139 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
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;
149 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
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;
157 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
159 mpi
->chroma_width
=(mpi
->width
);
160 mpi
->chroma_height
=(mpi
->height
);
161 mpi
->chroma_x_shift
=0;
162 mpi
->chroma_y_shift
=0;
165 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
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;
173 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
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;
182 /* they're planar ones, but for easier handling use them as packed */
183 // mpi->flags|=MP_IMGFLAG_PLANAR;
188 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
194 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
196 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
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;
205 fprintf(stderr
,"mp_image: unknown out_fmt: 0x%X\n",out_fmt
);
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
));
215 mpi
->height
=mpi
->h
=h
;
219 static inline void free_mp_image(mp_image_t
* mpi
){
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]);
228 mp_image_t
* alloc_mpi(int w
, int h
, unsigned long int fmt
);
229 void copy_mpi(mp_image_t
*dmpi
, mp_image_t
*mpi
);