comparison libmpcodecs/mp_image.c @ 23994:8572d2ef5263

Move alloc_mpi and copy_mpi from libmenu/vf_menu.c to libmpcodecs/mp_image.c. Patch by Attila tvs.
author cehoyos
date Sat, 04 Aug 2007 22:12:49 +0000
parents
children df67d03dde3b
comparison
equal deleted inserted replaced
23993:2107f38b6ca1 23994:8572d2ef5263
1
2 #include "config.h"
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #ifdef HAVE_MALLOC_H
9 #include <malloc.h>
10 #endif
11
12 #include "libmpcodecs/img_format.h"
13 #include "libmpcodecs/mp_image.h"
14
15 #include "libvo/fastmemcpy.h"
16
17 mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt) {
18 mp_image_t* mpi = new_mp_image(w,h);
19
20 mp_image_setfmt(mpi,fmt);
21 // IF09 - allocate space for 4. plane delta info - unused
22 if (mpi->imgfmt == IMGFMT_IF09)
23 {
24 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8+
25 mpi->chroma_width*mpi->chroma_height);
26 /* delta table, just for fun ;) */
27 mpi->planes[3]=mpi->planes[0]+2*(mpi->chroma_width*mpi->chroma_height);
28 }
29 else
30 mpi->planes[0]=memalign(64, mpi->bpp*mpi->width*(mpi->height+2)/8);
31 if(mpi->flags&MP_IMGFLAG_PLANAR){
32 // YV12/I420/YVU9/IF09. feel free to add other planar formats here...
33 if(!mpi->stride[0]) mpi->stride[0]=mpi->width;
34 if(!mpi->stride[1]) mpi->stride[1]=mpi->stride[2]=mpi->chroma_width;
35 if(mpi->flags&MP_IMGFLAG_SWAPPED){
36 // I420/IYUV (Y,U,V)
37 mpi->planes[1]=mpi->planes[0]+mpi->width*mpi->height;
38 mpi->planes[2]=mpi->planes[1]+mpi->chroma_width*mpi->chroma_height;
39 } else {
40 // YV12,YVU9,IF09 (Y,V,U)
41 mpi->planes[2]=mpi->planes[0]+mpi->width*mpi->height;
42 mpi->planes[1]=mpi->planes[2]+mpi->chroma_width*mpi->chroma_height;
43 }
44 } else {
45 if(!mpi->stride[0]) mpi->stride[0]=mpi->width*mpi->bpp/8;
46 }
47 mpi->flags|=MP_IMGFLAG_ALLOCATED;
48
49 return mpi;
50 }
51
52 void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) {
53 if(mpi->flags&MP_IMGFLAG_PLANAR){
54 memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h,
55 dmpi->stride[0],mpi->stride[0]);
56 memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height,
57 dmpi->stride[1],mpi->stride[1]);
58 memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height,
59 dmpi->stride[2],mpi->stride[2]);
60 } else {
61 memcpy_pic(dmpi->planes[0],mpi->planes[0],
62 mpi->w*(dmpi->bpp/8), mpi->h,
63 dmpi->stride[0],mpi->stride[0]);
64 }
65 }