12 #include "postproc/rgb2rgb.h"
13 #include "libvo/fastmemcpy.h"
15 #include "vd_internal.h"
17 static vd_info_t info
= {
21 ".so, based on mpng.c",
22 "uses libpng, 8bpp modes not supported yet"
27 static unsigned int out_fmt
=0;
33 // to set/get/query special features/parameters
34 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...){
37 case VDCTRL_QUERY_FORMAT
:
38 if (*((int *) arg
) == out_fmt
) return CONTROL_TRUE
;
41 return CONTROL_UNKNOWN
;
45 static int init(sh_video_t
*sh
){
51 static void uninit(sh_video_t
*sh
){
54 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
56 static int pngPointer
;
59 static void pngReadFN( png_structp pngstr
,png_bytep buffer
,png_size_t size
)
61 char * p
= pngstr
->io_ptr
;
62 if(size
>pngLength
-pngPointer
&& pngLength
>=pngPointer
) size
=pngLength
-pngPointer
;
63 memcpy( buffer
,(char *)&p
[pngPointer
],size
);
68 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
){
74 png_uint_32 png_width
=0,png_height
=0;
83 if(len
<=0) return NULL
; // skipped frame
85 png
=png_create_read_struct( PNG_LIBPNG_VER_STRING
,NULL
,NULL
,NULL
);
86 info
=png_create_info_struct( png
);
87 endinfo
=png_create_info_struct( png
);
91 png_set_read_fn( png
,data
,pngReadFN
);
92 png_set_strip_16( png
);
93 png_set_sig_bytes( png
,8 );
94 png_read_info( png
,info
);
95 png_get_IHDR( png
,info
,&png_width
,&png_height
,&depth
,&color
,NULL
,NULL
,NULL
);
98 switch( info
->color_type
) {
99 case PNG_COLOR_TYPE_GRAY_ALPHA
:
100 mp_msg( MSGT_DECVIDEO
,MSGL_INFO
,"Sorry gray scaled png with alpha channel not supported at moment.\n" );
102 case PNG_COLOR_TYPE_GRAY
:
105 case PNG_COLOR_TYPE_PALETTE
:
108 case PNG_COLOR_TYPE_RGB_ALPHA
:
109 out_fmt
=IMGFMT_BGR32
;
111 case PNG_COLOR_TYPE_RGB
:
112 out_fmt
=IMGFMT_BGR24
;
115 mp_msg( MSGT_DECVIDEO
,MSGL_INFO
,"Sorry, unsupported PNG colorspace: %d.\n" ,info
->color_type
);
118 // (re)init libvo if image parameters changed (width/height/colorspace)
119 if(last_w
!=png_width
|| last_h
!=png_height
|| last_c
!=out_fmt
){
120 last_w
=png_width
; last_h
=png_height
; last_c
=out_fmt
;
121 if(!out_fmt
) return NULL
;
122 if(!mpcodecs_config_vo(sh
,png_width
,png_height
,out_fmt
)) return NULL
;
126 switch( info
->color_type
)
128 case PNG_COLOR_TYPE_GRAY_ALPHA
: printf( "[png] used GrayA -> stripping alpha channel\n" ); break;
129 case PNG_COLOR_TYPE_GRAY
: printf( "[png] used Gray -> rgb\n" ); break;
130 case PNG_COLOR_TYPE_PALETTE
: printf( "[png] used palette -> rgb\n" ); break;
131 case PNG_COLOR_TYPE_RGB_ALPHA
: printf( "[png] used RGBA -> stripping alpha channel\n" ); break;
132 case PNG_COLOR_TYPE_RGB
: printf( "[png] read rgb datas.\n" ); break;
136 mpi
=mpcodecs_get_image(sh
, MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
137 png_width
,png_height
);
138 if(!mpi
) return NULL
;
141 row_p
=(png_bytep
*)malloc( sizeof( png_bytep
) * png_height
);
142 //png_get_rowbytes( png,info )
143 for ( i
=0; i
< png_height
; i
++ ) row_p
[i
]=mpi
->planes
[0] + mpi
->stride
[0]*i
;
144 png_read_image( png
,row_p
);
147 if (out_fmt
==IMGFMT_BGR8
) {
148 png_get_PLTE( png
,info
,&pal
,&cols
);
149 mpi
->planes
[1] = (char*)realloc(mpi
->planes
[1], 4*cols
);
151 for (i
= 0; i
< cols
; i
++) {
159 png_read_end( png
,endinfo
);
160 png_destroy_read_struct( &png
,&info
,&endinfo
);