Mercurial > mplayer.hg
annotate libmpcodecs/mp_image.h @ 7130:a27a786e98f9
remove nonsense tabs from makefile so emacs won't complain :)
author | rfelker |
---|---|
date | Thu, 29 Aug 2002 01:49:15 +0000 |
parents | 695bd84c1b24 |
children | 31fd09cc9ba2 |
rev | line source |
---|---|
4933 | 1 #ifndef __MP_IMAGE_H |
2 #define __MP_IMAGE_H 1 | |
4185 | 3 |
6875 | 4 //--------- codec's requirements (filled by the codec/vf) --------- |
5 | |
6 //--- buffer content restrictions: | |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
7 // set if buffer content shouldn't be modified: |
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
8 #define MP_IMGFLAG_PRESERVE 0x01 |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
9 // set if buffer content will be READ for next frame's MC: (I/P mpeg frames) |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
10 #define MP_IMGFLAG_READABLE 0x02 |
6875 | 11 |
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 | |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
17 // codec accept any stride (>=width): |
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
18 #define MP_IMGFLAG_ACCEPT_STRIDE 0x10 |
6875 | 19 // codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width): |
4962 | 20 #define MP_IMGFLAG_ACCEPT_WIDTH 0x20 |
6875 | 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 | |
4185 | 26 |
6875 | 27 #define MP_IMGFLAGMASK_RESTRICTIONS 0xFF |
28 | |
29 //--------- color info (filled by mp_image_setfmt() ) ----------- | |
4185 | 30 // set if number of planes > 1 |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
31 #define MP_IMGFLAG_PLANAR 0x100 |
4185 | 32 // set if it's YUV colorspace |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
33 #define MP_IMGFLAG_YUV 0x200 |
6875 | 34 // set if it's swapped (BGR or YVU) plane/byteorder |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
35 #define MP_IMGFLAG_SWAPPED 0x400 |
6478 | 36 // using palette for RGB data |
6875 | 37 #define MP_IMGFLAG_RGB_PALETTE 0x800 |
38 | |
39 #define MP_IMGFLAGMASK_COLORS 0xF00 | |
40 | |
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 | |
49 | |
50 // buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!) | |
51 #define MP_IMGFLAG_TYPE_DISPLAYED 0x8000 | |
4185 | 52 |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
53 // codec doesn't support any form of direct rendering - it has own buffer |
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
54 // allocation. so we just export its buffer pointers: |
4186 | 55 #define MP_IMGTYPE_EXPORT 0 |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
56 // codec requires a static WO buffer, but it does only partial updates later: |
4186 | 57 #define MP_IMGTYPE_STATIC 1 |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
58 // codec just needs some WO memory, where it writes/copies the whole frame to: |
4186 | 59 #define MP_IMGTYPE_TEMP 2 |
4877
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
60 // I+P type, requires 2+ independent static R/W buffers |
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
61 #define MP_IMGTYPE_IP 3 |
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
62 // I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers |
9d97874d8691
new flags added for direct rendering (libmpcodecs core)
arpi
parents:
4187
diff
changeset
|
63 #define MP_IMGTYPE_IPB 4 |
4186 | 64 |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
65 #define MP_MAX_PLANES 4 |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
66 |
4185 | 67 typedef struct mp_image_s { |
68 unsigned short flags; | |
4186 | 69 unsigned char type; |
70 unsigned char bpp; // bits/pixel. NOT depth! for RGB it will be n*8 | |
4185 | 71 unsigned int imgfmt; |
72 int width,height; // stored dimensions | |
73 int x,y,w,h; // visible dimensions | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
74 unsigned char* planes[MP_MAX_PLANES]; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
75 unsigned int stride[MP_MAX_PLANES]; |
4185 | 76 int* qscale; |
77 int qstride; | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
78 int num_planes; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
79 /* these are only used by planar formats Y,U(Cb),V(Cr) */ |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
80 int chroma_width; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
81 int chroma_height; |
6539
79b536a37e40
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6538
diff
changeset
|
82 int chroma_x_shift; // horizontal |
79b536a37e40
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6538
diff
changeset
|
83 int chroma_y_shift; // vertical |
6759
415be01747ae
added 'priv' field to mpi - requires for tracking frames with different
arpi
parents:
6707
diff
changeset
|
84 /* for private use by filter or vo driver (to store buffer id or dmpi) */ |
415be01747ae
added 'priv' field to mpi - requires for tracking frames with different
arpi
parents:
6707
diff
changeset
|
85 void* priv; |
4185 | 86 } mp_image_t; |
87 | |
88 #ifdef IMGFMT_YUY2 | |
89 static inline void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){ | |
90 mpi->flags&=~(MP_IMGFLAG_PLANAR|MP_IMGFLAG_YUV|MP_IMGFLAG_SWAPPED); | |
4187 | 91 mpi->imgfmt=out_fmt; |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
92 if(out_fmt == IMGFMT_MPEGPES){ |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
93 mpi->bpp=0; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
94 return; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
95 } |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
96 mpi->num_planes=1; |
6707 | 97 if (IMGFMT_IS_RGB(out_fmt)) { |
98 if (IMGFMT_RGB_DEPTH(out_fmt) < 8) | |
99 mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt); | |
100 else | |
101 mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7); | |
4185 | 102 return; |
103 } | |
6707 | 104 if (IMGFMT_IS_BGR(out_fmt)) { |
105 if (IMGFMT_BGR_DEPTH(out_fmt) < 8) | |
106 mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt); | |
107 else | |
108 mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7); | |
4185 | 109 mpi->flags|=MP_IMGFLAG_SWAPPED; |
110 return; | |
111 } | |
112 mpi->flags|=MP_IMGFLAG_YUV; | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
113 mpi->num_planes=3; |
4185 | 114 switch(out_fmt){ |
115 case IMGFMT_I420: | |
116 case IMGFMT_IYUV: | |
117 mpi->flags|=MP_IMGFLAG_SWAPPED; | |
118 case IMGFMT_YV12: | |
119 mpi->flags|=MP_IMGFLAG_PLANAR; | |
120 mpi->bpp=12; | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
121 mpi->chroma_width=(mpi->width>>1); |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
122 mpi->chroma_height=(mpi->height>>1); |
6539
79b536a37e40
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6538
diff
changeset
|
123 mpi->chroma_x_shift=1; |
79b536a37e40
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6538
diff
changeset
|
124 mpi->chroma_y_shift=1; |
4185 | 125 return; |
6525 | 126 case IMGFMT_IF09: |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
127 mpi->num_planes=4; |
6478 | 128 case IMGFMT_YVU9: |
129 mpi->flags|=MP_IMGFLAG_PLANAR; | |
130 mpi->bpp=9; | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
131 mpi->chroma_width=(mpi->width>>2); |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
132 mpi->chroma_height=(mpi->height>>2); |
6539
79b536a37e40
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6538
diff
changeset
|
133 mpi->chroma_x_shift=2; |
79b536a37e40
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6538
diff
changeset
|
134 mpi->chroma_y_shift=2; |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
135 return; |
6863 | 136 case IMGFMT_444P: |
137 mpi->flags|=MP_IMGFLAG_PLANAR; | |
138 mpi->bpp=24; | |
139 mpi->chroma_width=(mpi->width); | |
140 mpi->chroma_height=(mpi->height); | |
141 mpi->chroma_x_shift=0; | |
142 mpi->chroma_y_shift=0; | |
143 return; | |
144 case IMGFMT_422P: | |
145 mpi->flags|=MP_IMGFLAG_PLANAR; | |
146 mpi->bpp=16; | |
147 mpi->chroma_width=(mpi->width>>1); | |
148 mpi->chroma_height=(mpi->height); | |
149 mpi->chroma_x_shift=1; | |
150 mpi->chroma_y_shift=0; | |
151 return; | |
152 case IMGFMT_411P: | |
153 mpi->flags|=MP_IMGFLAG_PLANAR; | |
154 mpi->bpp=12; | |
155 mpi->chroma_width=(mpi->width>>2); | |
156 mpi->chroma_height=(mpi->height); | |
157 mpi->chroma_x_shift=2; | |
158 mpi->chroma_y_shift=0; | |
159 return; | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
160 case IMGFMT_Y800: |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
161 case IMGFMT_Y8: |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
162 /* they're planar ones, but for easier handling use them as packed */ |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
163 // mpi->flags|=MP_IMGFLAG_PLANAR; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
164 mpi->bpp=8; |
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
165 mpi->num_planes=1; |
6478 | 166 return; |
4185 | 167 case IMGFMT_UYVY: |
168 mpi->flags|=MP_IMGFLAG_SWAPPED; | |
169 case IMGFMT_YUY2: | |
170 mpi->bpp=16; | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
171 mpi->num_planes=1; |
5144 | 172 return; |
4185 | 173 } |
174 printf("mp_image: Unknown out_fmt: 0x%X\n",out_fmt); | |
175 mpi->bpp=0; | |
176 } | |
177 #endif | |
178 | |
179 static inline mp_image_t* new_mp_image(int w,int h){ | |
6911 | 180 mp_image_t* mpi=(mp_image_t*)malloc(sizeof(mp_image_t)); |
4185 | 181 if(!mpi) return NULL; // error! |
182 memset(mpi,0,sizeof(mp_image_t)); | |
183 mpi->width=mpi->w=w; | |
184 mpi->height=mpi->h=h; | |
185 return mpi; | |
186 } | |
4933 | 187 |
5737 | 188 static inline void free_mp_image(mp_image_t* mpi){ |
189 if(!mpi) return; | |
190 if(mpi->flags&MP_IMGFLAG_ALLOCATED){ | |
6538
afb4f3c107e7
better planar support, chroma subsampling support and Y8/Y800 support
alex
parents:
6525
diff
changeset
|
191 /* becouse we allocate the whole image in once */ |
5737 | 192 if(mpi->planes[0]) free(mpi->planes[0]); |
193 } | |
194 free(mpi); | |
195 } | |
196 | |
4933 | 197 #endif |