Mercurial > mplayer.hg
annotate libmpcodecs/vd_mpng.c @ 12167:6421ebfc0018
avoid unneeded stream_reset()
aspect ratio support (rarely works ...)
author, title, ...
author | michael |
---|---|
date | Sun, 11 Apr 2004 16:48:48 +0000 |
parents | a9448dd2430c |
children | ef7349907cf4 |
rev | line source |
---|---|
4998 | 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 "A'rpi", | |
21 ".so, based on mpng.c", | |
22 "uses libpng, 8bpp modes not supported yet" | |
23 }; | |
24 | |
25 LIBVD_EXTERN(mpng) | |
26 | |
27 static unsigned int out_fmt=0; | |
28 | |
29 static int last_w=-1; | |
30 static int last_h=-1; | |
31 static int last_c=-1; | |
32 | |
33 // to set/get/query special features/parameters | |
34 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
11566
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
35 switch (cmd) |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
36 { |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
37 case VDCTRL_QUERY_FORMAT: |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
38 if (*((int *) arg) == out_fmt) return CONTROL_TRUE; |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
39 return CONTROL_FALSE; |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
40 } |
4998 | 41 return CONTROL_UNKNOWN; |
42 } | |
43 | |
44 // init driver | |
45 static int init(sh_video_t *sh){ | |
46 last_w=-1; | |
47 return 1; | |
48 } | |
49 | |
50 // uninit driver | |
51 static void uninit(sh_video_t *sh){ | |
52 } | |
53 | |
54 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
55 | |
56 static int pngPointer; | |
57 static int pngLength; | |
58 | |
59 static void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size ) | |
60 { | |
61 char * p = pngstr->io_ptr; | |
62 if(size>pngLength-pngPointer && pngLength>=pngPointer) size=pngLength-pngPointer; | |
63 memcpy( buffer,(char *)&p[pngPointer],size ); | |
64 pngPointer+=size; | |
65 } | |
66 | |
67 // decode a frame | |
68 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
69 png_structp png; | |
70 png_infop info; | |
71 png_infop endinfo; | |
72 // png_bytep data; | |
73 png_bytep * row_p; | |
74 png_uint_32 png_width=0,png_height=0; | |
75 int depth,color; | |
76 png_uint_32 i; | |
77 mp_image_t* mpi; | |
78 | |
79 if(len<=0) return NULL; // skipped frame | |
80 | |
81 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL ); | |
82 info=png_create_info_struct( png ); | |
83 endinfo=png_create_info_struct( png ); | |
84 | |
85 pngPointer=8; | |
86 pngLength=len; | |
87 png_set_read_fn( png,data,pngReadFN ); | |
88 png_set_sig_bytes( png,8 ); | |
89 png_read_info( png,info ); | |
90 png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL ); | |
91 | |
92 png_set_bgr( png ); | |
93 | |
94 switch( info->color_type ) { | |
95 case PNG_COLOR_TYPE_GRAY_ALPHA: | |
96 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" ); | |
97 break; | |
98 case PNG_COLOR_TYPE_GRAY: | |
99 case PNG_COLOR_TYPE_PALETTE: | |
100 out_fmt=IMGFMT_BGR8; | |
101 break; | |
102 case PNG_COLOR_TYPE_RGB_ALPHA: | |
103 out_fmt=IMGFMT_BGR32; | |
104 break; | |
105 case PNG_COLOR_TYPE_RGB: | |
106 out_fmt=IMGFMT_BGR24; | |
107 break; | |
108 default: | |
109 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry, unsupported PNG colorspace: %d.\n" ,info->color_type); | |
110 } | |
111 | |
112 // (re)init libvo if image parameters changed (width/height/colorspace) | |
113 if(last_w!=png_width || last_h!=png_height || last_c!=out_fmt){ | |
114 last_w=png_width; last_h=png_height; last_c=out_fmt; | |
115 if(!out_fmt) return NULL; | |
5124 | 116 if(!mpcodecs_config_vo(sh,png_width,png_height,out_fmt)) return NULL; |
4998 | 117 } |
118 | |
119 #if 0 | |
120 switch( info->color_type ) | |
121 { | |
122 case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break; | |
123 case PNG_COLOR_TYPE_GRAY: printf( "[png] used Gray -> rgb\n" ); break; | |
124 case PNG_COLOR_TYPE_PALETTE: printf( "[png] used palette -> rgb\n" ); break; | |
125 case PNG_COLOR_TYPE_RGB_ALPHA: printf( "[png] used RGBA -> stripping alpha channel\n" ); break; | |
126 case PNG_COLOR_TYPE_RGB: printf( "[png] read rgb datas.\n" ); break; | |
127 } | |
128 #endif | |
129 | |
130 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
131 png_width,png_height); | |
132 if(!mpi) return NULL; | |
133 | |
134 // Let's DECODE! | |
135 row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height ); | |
136 //png_get_rowbytes( png,info ) | |
137 for ( i=0; i < png_height; i++ ) row_p[i]=mpi->planes[0] + mpi->stride[0]*i; | |
138 png_read_image( png,row_p ); | |
139 free( row_p ); | |
140 | |
141 //png_get_PLTE( png,info,(png_colorp*)&pal,&cols ); | |
142 | |
143 png_read_end( png,endinfo ); | |
144 png_destroy_read_struct( &png,&info,&endinfo ); | |
145 | |
146 return mpi; | |
147 } | |
148 | |
149 #endif |