Merge svn changes up to r30463
[mplayer/kovensky.git] / libmpcodecs / mp_image.c
blobebc9e6a7497f4bf3a3bba5ccd3da4eeb8cb450d3
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "config.h"
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #if HAVE_MALLOC_H
26 #include <malloc.h>
27 #endif
29 #include "libmpcodecs/img_format.h"
30 #include "libmpcodecs/mp_image.h"
32 #include "libvo/fastmemcpy.h"
34 void mp_image_alloc_planes(mp_image_t *mpi) {
35 // IF09 - allocate space for 4. plane delta info - unused
36 if (mpi->imgfmt == IMGFMT_IF09) {
37 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8+
38 mpi->chroma_width*mpi->chroma_height);
39 } else
40 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8);
41 if (mpi->flags&MP_IMGFLAG_PLANAR) {
42 int bpp = IMGFMT_IS_YUVP16(mpi->imgfmt)? 2 : 1;
43 // YV12/I420/YVU9/IF09. feel free to add other planar formats here...
44 mpi->stride[0]=mpi->stride[3]=bpp*mpi->width;
45 if(mpi->num_planes > 2){
46 mpi->stride[1]=mpi->stride[2]=bpp*mpi->chroma_width;
47 if(mpi->flags&MP_IMGFLAG_SWAPPED){
48 // I420/IYUV (Y,U,V)
49 mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height;
50 mpi->planes[2]=mpi->planes[1]+mpi->stride[1]*mpi->chroma_height;
51 if (mpi->num_planes > 3)
52 mpi->planes[3]=mpi->planes[2]+mpi->stride[2]*mpi->chroma_height;
53 } else {
54 // YV12,YVU9,IF09 (Y,V,U)
55 mpi->planes[2]=mpi->planes[0]+mpi->stride[0]*mpi->height;
56 mpi->planes[1]=mpi->planes[2]+mpi->stride[1]*mpi->chroma_height;
57 if (mpi->num_planes > 3)
58 mpi->planes[3]=mpi->planes[1]+mpi->stride[1]*mpi->chroma_height;
60 } else {
61 // NV12/NV21
62 mpi->stride[1]=mpi->chroma_width;
63 mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height;
65 } else {
66 mpi->stride[0]=mpi->width*mpi->bpp/8;
67 if (mpi->flags & MP_IMGFLAG_RGB_PALETTE)
68 mpi->planes[1] = memalign(64, 1024);
70 mpi->flags|=MP_IMGFLAG_ALLOCATED;
73 mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt) {
74 mp_image_t* mpi = new_mp_image(w,h);
76 mp_image_setfmt(mpi,fmt);
77 mp_image_alloc_planes(mpi);
79 return mpi;
82 void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) {
83 if(mpi->flags&MP_IMGFLAG_PLANAR){
84 memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h,
85 dmpi->stride[0],mpi->stride[0]);
86 memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height,
87 dmpi->stride[1],mpi->stride[1]);
88 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height,
89 dmpi->stride[2],mpi->stride[2]);
90 } else {
91 memcpy_pic(dmpi->planes[0],mpi->planes[0],
92 mpi->w*(dmpi->bpp/8), mpi->h,
93 dmpi->stride[0],mpi->stride[0]);