Mercurial > mplayer.hg
comparison libmpcodecs/vd_mpng.c @ 4998:c32191b02a66
mpng, libmpeg2 added, none of them finished :(
author | arpi |
---|---|
date | Sat, 09 Mar 2002 02:18:33 +0000 |
parents | |
children | 3dcbf67c0de0 |
comparison
equal
deleted
inserted
replaced
4997:5efa42dd4cd8 | 4998:c32191b02a66 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
5 #include "mp_msg.h" | |
6 | |
7 #ifdef HAVE_PNG | |
8 | |
9 #include <png.h> | |
10 | |
11 #include "bswap.h" | |
12 #include "postproc/rgb2rgb.h" | |
13 #include "libvo/fastmemcpy.h" | |
14 | |
15 #include "vd_internal.h" | |
16 | |
17 static vd_info_t info = { | |
18 "PNG Images decoder", | |
19 "mpng", | |
20 VFM_MPNG, | |
21 "A'rpi", | |
22 ".so, based on mpng.c", | |
23 "uses libpng, 8bpp modes not supported yet" | |
24 }; | |
25 | |
26 LIBVD_EXTERN(mpng) | |
27 | |
28 static unsigned int out_fmt=0; | |
29 | |
30 static int last_w=-1; | |
31 static int last_h=-1; | |
32 static int last_c=-1; | |
33 | |
34 // to set/get/query special features/parameters | |
35 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
36 return CONTROL_UNKNOWN; | |
37 } | |
38 | |
39 // init driver | |
40 static int init(sh_video_t *sh){ | |
41 last_w=-1; | |
42 return 1; | |
43 } | |
44 | |
45 // uninit driver | |
46 static void uninit(sh_video_t *sh){ | |
47 } | |
48 | |
49 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
50 | |
51 static int pngPointer; | |
52 static int pngLength; | |
53 | |
54 static void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size ) | |
55 { | |
56 char * p = pngstr->io_ptr; | |
57 if(size>pngLength-pngPointer && pngLength>=pngPointer) size=pngLength-pngPointer; | |
58 memcpy( buffer,(char *)&p[pngPointer],size ); | |
59 pngPointer+=size; | |
60 } | |
61 | |
62 // decode a frame | |
63 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
64 png_structp png; | |
65 png_infop info; | |
66 png_infop endinfo; | |
67 // png_bytep data; | |
68 png_bytep * row_p; | |
69 png_uint_32 png_width=0,png_height=0; | |
70 char * palette = NULL; | |
71 int depth,color; | |
72 png_uint_32 i; | |
73 mp_image_t* mpi; | |
74 | |
75 if(len<=0) return NULL; // skipped frame | |
76 | |
77 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL ); | |
78 info=png_create_info_struct( png ); | |
79 endinfo=png_create_info_struct( png ); | |
80 | |
81 pngPointer=8; | |
82 pngLength=len; | |
83 png_set_read_fn( png,data,pngReadFN ); | |
84 png_set_sig_bytes( png,8 ); | |
85 png_read_info( png,info ); | |
86 png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL ); | |
87 | |
88 png_set_bgr( png ); | |
89 | |
90 switch( info->color_type ) { | |
91 case PNG_COLOR_TYPE_GRAY_ALPHA: | |
92 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" ); | |
93 break; | |
94 case PNG_COLOR_TYPE_GRAY: | |
95 case PNG_COLOR_TYPE_PALETTE: | |
96 out_fmt=IMGFMT_BGR8; | |
97 break; | |
98 case PNG_COLOR_TYPE_RGB_ALPHA: | |
99 out_fmt=IMGFMT_BGR32; | |
100 break; | |
101 case PNG_COLOR_TYPE_RGB: | |
102 out_fmt=IMGFMT_BGR24; | |
103 break; | |
104 default: | |
105 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry, unsupported PNG colorspace: %d.\n" ,info->color_type); | |
106 } | |
107 | |
108 // (re)init libvo if image parameters changed (width/height/colorspace) | |
109 if(last_w!=png_width || last_h!=png_height || last_c!=out_fmt){ | |
110 last_w=png_width; last_h=png_height; last_c=out_fmt; | |
111 if(!out_fmt) return NULL; | |
112 mpcodecs_config_vo(sh,png_width,png_height,out_fmt); | |
113 } | |
114 | |
115 #if 0 | |
116 switch( info->color_type ) | |
117 { | |
118 case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break; | |
119 case PNG_COLOR_TYPE_GRAY: printf( "[png] used Gray -> rgb\n" ); break; | |
120 case PNG_COLOR_TYPE_PALETTE: printf( "[png] used palette -> rgb\n" ); break; | |
121 case PNG_COLOR_TYPE_RGB_ALPHA: printf( "[png] used RGBA -> stripping alpha channel\n" ); break; | |
122 case PNG_COLOR_TYPE_RGB: printf( "[png] read rgb datas.\n" ); break; | |
123 } | |
124 #endif | |
125 | |
126 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
127 png_width,png_height); | |
128 if(!mpi) return NULL; | |
129 | |
130 // Let's DECODE! | |
131 row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height ); | |
132 //png_get_rowbytes( png,info ) | |
133 for ( i=0; i < png_height; i++ ) row_p[i]=mpi->planes[0] + mpi->stride[0]*i; | |
134 png_read_image( png,row_p ); | |
135 free( row_p ); | |
136 | |
137 //png_get_PLTE( png,info,(png_colorp*)&pal,&cols ); | |
138 | |
139 png_read_end( png,endinfo ); | |
140 png_destroy_read_struct( &png,&info,&endinfo ); | |
141 | |
142 return mpi; | |
143 } | |
144 | |
145 #endif |