1 #ifndef MPLAYER_MP_IMAGE_H
2 #define MPLAYER_MP_IMAGE_H
9 //--------- codec's requirements (filled by the codec/vf) ---------
11 //--- buffer content restrictions:
12 // set if buffer content shouldn't be modified:
13 #define MP_IMGFLAG_PRESERVE 0x01
14 // set if buffer content will be READ for next frame's MC: (I/P mpeg frames)
15 #define MP_IMGFLAG_READABLE 0x02
17 //--- buffer width/stride/plane restrictions: (used for direct rendering)
18 // stride _have_to_ be aligned to MB boundary: [for DR restrictions]
19 #define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE 0x4
20 // stride should be aligned to MB boundary: [for buffer allocation]
21 #define MP_IMGFLAG_PREFER_ALIGNED_STRIDE 0x8
22 // codec accept any stride (>=width):
23 #define MP_IMGFLAG_ACCEPT_STRIDE 0x10
24 // codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width):
25 #define MP_IMGFLAG_ACCEPT_WIDTH 0x20
26 //--- for planar formats only:
27 // uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift
28 #define MP_IMGFLAG_COMMON_STRIDE 0x40
29 // uses only planes[0], and calculates planes[1,2] from width,height,imgfmt
30 #define MP_IMGFLAG_COMMON_PLANE 0x80
32 #define MP_IMGFLAGMASK_RESTRICTIONS 0xFF
34 //--------- color info (filled by mp_image_setfmt() ) -----------
35 // set if number of planes > 1
36 #define MP_IMGFLAG_PLANAR 0x100
37 // set if it's YUV colorspace
38 #define MP_IMGFLAG_YUV 0x200
39 // set if it's swapped (BGR or YVU) plane/byteorder
40 #define MP_IMGFLAG_SWAPPED 0x400
41 // using palette for RGB data
42 #define MP_IMGFLAG_RGB_PALETTE 0x800
44 #define MP_IMGFLAGMASK_COLORS 0xF00
46 // codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2)
47 // [the codec will set this flag if it supports callbacks, and the vo _may_
48 // clear it in get_image() if draw_slice() not implemented]
49 #define MP_IMGFLAG_DRAW_CALLBACK 0x1000
50 // set if it's in video buffer/memory: [set by vo/vf's get_image() !!!]
51 #define MP_IMGFLAG_DIRECT 0x2000
52 // set if buffer is allocated (used in destination images):
53 #define MP_IMGFLAG_ALLOCATED 0x4000
55 // buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!)
56 #define MP_IMGFLAG_TYPE_DISPLAYED 0x8000
57 // set if it can not be reused yet (for MP_IMGTYPE_NUMBERED)
58 #define MP_IMGFLAG_IN_USE 0x10000
60 // codec doesn't support any form of direct rendering - it has own buffer
61 // allocation. so we just export its buffer pointers:
62 #define MP_IMGTYPE_EXPORT 0
63 // codec requires a static WO buffer, but it does only partial updates later:
64 #define MP_IMGTYPE_STATIC 1
65 // codec just needs some WO memory, where it writes/copies the whole frame to:
66 #define MP_IMGTYPE_TEMP 2
67 // I+P type, requires 2+ independent static R/W buffers
68 #define MP_IMGTYPE_IP 3
69 // I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers
70 #define MP_IMGTYPE_IPB 4
71 // Upper 16 bits give desired buffer number, -1 means get next available
72 #define MP_IMGTYPE_NUMBERED 5
74 #define MP_MAX_PLANES 4
76 #define MP_IMGFIELD_ORDERED 0x01
77 #define MP_IMGFIELD_TOP_FIRST 0x02
78 #define MP_IMGFIELD_REPEAT_FIRST 0x04
79 #define MP_IMGFIELD_TOP 0x08
80 #define MP_IMGFIELD_BOTTOM 0x10
81 #define MP_IMGFIELD_INTERLACED 0x20
83 typedef struct mp_image_s
{
87 unsigned char bpp
; // bits/pixel. NOT depth! for RGB it will be n*8
89 int width
,height
; // stored dimensions
90 int x
,y
,w
,h
; // visible dimensions
91 unsigned char* planes
[MP_MAX_PLANES
];
92 int stride
[MP_MAX_PLANES
];
95 int pict_type
; // 0->unknown, 1->I, 2->P, 3->B
97 int qscale_type
; // 0->mpeg1/4/h263, 1->mpeg2
99 /* these are only used by planar formats Y,U(Cb),V(Cr) */
102 int chroma_x_shift
; // horizontal
103 int chroma_y_shift
; // vertical
104 /* for private use by filter or vo driver (to store buffer id or dmpi) */
109 static inline void mp_image_setfmt(mp_image_t
* mpi
,unsigned int out_fmt
){
110 mpi
->flags
&=~(MP_IMGFLAG_PLANAR
|MP_IMGFLAG_YUV
|MP_IMGFLAG_SWAPPED
);
112 // compressed formats
113 if(out_fmt
== IMGFMT_MPEGPES
||
114 out_fmt
== IMGFMT_ZRMJPEGNI
|| out_fmt
== IMGFMT_ZRMJPEGIT
|| out_fmt
== IMGFMT_ZRMJPEGIB
||
115 IMGFMT_IS_VDPAU(out_fmt
) || IMGFMT_IS_XVMC(out_fmt
)){
120 if (IMGFMT_IS_RGB(out_fmt
)) {
121 if (IMGFMT_RGB_DEPTH(out_fmt
) < 8 && !(out_fmt
&128))
122 mpi
->bpp
= IMGFMT_RGB_DEPTH(out_fmt
);
124 mpi
->bpp
=(IMGFMT_RGB_DEPTH(out_fmt
)+7)&(~7);
127 if (IMGFMT_IS_BGR(out_fmt
)) {
128 if (IMGFMT_BGR_DEPTH(out_fmt
) < 8 && !(out_fmt
&128))
129 mpi
->bpp
= IMGFMT_BGR_DEPTH(out_fmt
);
131 mpi
->bpp
=(IMGFMT_BGR_DEPTH(out_fmt
)+7)&(~7);
132 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
135 mpi
->flags
|=MP_IMGFLAG_YUV
;
140 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
142 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
144 mpi
->chroma_width
=(mpi
->width
>>1);
145 mpi
->chroma_height
=(mpi
->height
>>1);
146 mpi
->chroma_x_shift
=1;
147 mpi
->chroma_y_shift
=1;
152 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
154 mpi
->chroma_width
=(mpi
->width
>>2);
155 mpi
->chroma_height
=(mpi
->height
>>2);
156 mpi
->chroma_x_shift
=2;
157 mpi
->chroma_y_shift
=2;
160 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
162 mpi
->chroma_width
=(mpi
->width
);
163 mpi
->chroma_height
=(mpi
->height
);
164 mpi
->chroma_x_shift
=0;
165 mpi
->chroma_y_shift
=0;
168 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
170 mpi
->chroma_width
=(mpi
->width
>>1);
171 mpi
->chroma_height
=(mpi
->height
);
172 mpi
->chroma_x_shift
=1;
173 mpi
->chroma_y_shift
=0;
176 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
178 mpi
->chroma_width
=(mpi
->width
>>2);
179 mpi
->chroma_height
=(mpi
->height
);
180 mpi
->chroma_x_shift
=2;
181 mpi
->chroma_y_shift
=0;
185 /* they're planar ones, but for easier handling use them as packed */
186 // mpi->flags|=MP_IMGFLAG_PLANAR;
191 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
197 mpi
->flags
|=MP_IMGFLAG_SWAPPED
;
199 mpi
->flags
|=MP_IMGFLAG_PLANAR
;
202 mpi
->chroma_width
=(mpi
->width
>>0);
203 mpi
->chroma_height
=(mpi
->height
>>1);
204 mpi
->chroma_x_shift
=0;
205 mpi
->chroma_y_shift
=1;
208 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,"mp_image: unknown out_fmt: 0x%X\n",out_fmt
);
213 static inline mp_image_t
* new_mp_image(int w
,int h
){
214 mp_image_t
* mpi
=(mp_image_t
*)malloc(sizeof(mp_image_t
));
215 if(!mpi
) return NULL
; // error!
216 memset(mpi
,0,sizeof(mp_image_t
));
218 mpi
->height
=mpi
->h
=h
;
222 static inline void free_mp_image(mp_image_t
* mpi
){
224 if(mpi
->flags
&MP_IMGFLAG_ALLOCATED
){
225 /* becouse we allocate the whole image in once */
226 if(mpi
->planes
[0]) free(mpi
->planes
[0]);
231 mp_image_t
* alloc_mpi(int w
, int h
, unsigned long int fmt
);
232 void copy_mpi(mp_image_t
*dmpi
, mp_image_t
*mpi
);
234 #endif /* MPLAYER_MP_IMAGE_H */