Mercurial > mplayer.hg
annotate libmpcodecs/vd_mpng.c @ 18759:04ed79acda15
simplify
author | diego |
---|---|
date | Tue, 20 Jun 2006 10:08:19 +0000 |
parents | 497ebe3ecc2b |
children | a1807995e2ab |
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 "libvo/fastmemcpy.h" | |
13 | |
14 #include "vd_internal.h" | |
15 | |
16 static vd_info_t info = { | |
17 "PNG Images decoder", | |
18 "mpng", | |
19 "A'rpi", | |
20 ".so, based on mpng.c", | |
21 "uses libpng, 8bpp modes not supported yet" | |
22 }; | |
23 | |
24 LIBVD_EXTERN(mpng) | |
25 | |
26 static unsigned int out_fmt=0; | |
27 | |
28 static int last_w=-1; | |
29 static int last_h=-1; | |
30 static int last_c=-1; | |
31 | |
32 // to set/get/query special features/parameters | |
33 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
|
34 switch (cmd) |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
35 { |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
36 case VDCTRL_QUERY_FORMAT: |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
37 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
|
38 return CONTROL_FALSE; |
a9448dd2430c
query_format support by Matthias Goerner <m.goerner@iu-bremen.de>
alex
parents:
7472
diff
changeset
|
39 } |
4998 | 40 return CONTROL_UNKNOWN; |
41 } | |
42 | |
43 // init driver | |
44 static int init(sh_video_t *sh){ | |
45 last_w=-1; | |
46 return 1; | |
47 } | |
48 | |
49 // uninit driver | |
50 static void uninit(sh_video_t *sh){ | |
51 } | |
52 | |
53 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
54 | |
55 static int pngPointer; | |
56 static int pngLength; | |
57 | |
58 static void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size ) | |
59 { | |
60 char * p = pngstr->io_ptr; | |
61 if(size>pngLength-pngPointer && pngLength>=pngPointer) size=pngLength-pngPointer; | |
62 memcpy( buffer,(char *)&p[pngPointer],size ); | |
63 pngPointer+=size; | |
64 } | |
65 | |
66 // decode a frame | |
67 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
68 png_structp png; | |
69 png_infop info; | |
70 png_infop endinfo; | |
71 // png_bytep data; | |
72 png_bytep * row_p; | |
73 png_uint_32 png_width=0,png_height=0; | |
74 int depth,color; | |
75 png_uint_32 i; | |
76 mp_image_t* mpi; | |
77 | |
15502
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
78 int cols; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
79 png_colorp pal; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
80 unsigned char *p; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
81 |
4998 | 82 if(len<=0) return NULL; // skipped frame |
83 | |
84 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL ); | |
85 info=png_create_info_struct( png ); | |
86 endinfo=png_create_info_struct( png ); | |
87 | |
88 pngPointer=8; | |
89 pngLength=len; | |
90 png_set_read_fn( png,data,pngReadFN ); | |
17552
3469899beb42
Fix mpng to work correctly with 16 bit png's. don't have any files to test
ods15
parents:
15502
diff
changeset
|
91 png_set_strip_16( png ); |
4998 | 92 png_set_sig_bytes( png,8 ); |
93 png_read_info( png,info ); | |
94 png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL ); | |
95 png_set_bgr( png ); | |
96 | |
97 switch( info->color_type ) { | |
98 case PNG_COLOR_TYPE_GRAY_ALPHA: | |
99 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" ); | |
100 break; | |
101 case PNG_COLOR_TYPE_GRAY: | |
15502
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
102 out_fmt=IMGFMT_Y800; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
103 break; |
4998 | 104 case PNG_COLOR_TYPE_PALETTE: |
105 out_fmt=IMGFMT_BGR8; | |
106 break; | |
107 case PNG_COLOR_TYPE_RGB_ALPHA: | |
108 out_fmt=IMGFMT_BGR32; | |
109 break; | |
110 case PNG_COLOR_TYPE_RGB: | |
111 out_fmt=IMGFMT_BGR24; | |
112 break; | |
113 default: | |
114 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry, unsupported PNG colorspace: %d.\n" ,info->color_type); | |
115 } | |
116 | |
117 // (re)init libvo if image parameters changed (width/height/colorspace) | |
118 if(last_w!=png_width || last_h!=png_height || last_c!=out_fmt){ | |
119 last_w=png_width; last_h=png_height; last_c=out_fmt; | |
120 if(!out_fmt) return NULL; | |
5124 | 121 if(!mpcodecs_config_vo(sh,png_width,png_height,out_fmt)) return NULL; |
4998 | 122 } |
123 | |
124 #if 0 | |
125 switch( info->color_type ) | |
126 { | |
127 case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break; | |
128 case PNG_COLOR_TYPE_GRAY: printf( "[png] used Gray -> rgb\n" ); break; | |
129 case PNG_COLOR_TYPE_PALETTE: printf( "[png] used palette -> rgb\n" ); break; | |
130 case PNG_COLOR_TYPE_RGB_ALPHA: printf( "[png] used RGBA -> stripping alpha channel\n" ); break; | |
131 case PNG_COLOR_TYPE_RGB: printf( "[png] read rgb datas.\n" ); break; | |
132 } | |
133 #endif | |
134 | |
135 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
136 png_width,png_height); | |
137 if(!mpi) return NULL; | |
138 | |
139 // Let's DECODE! | |
140 row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height ); | |
141 //png_get_rowbytes( png,info ) | |
142 for ( i=0; i < png_height; i++ ) row_p[i]=mpi->planes[0] + mpi->stride[0]*i; | |
143 png_read_image( png,row_p ); | |
144 free( row_p ); | |
15502
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
145 |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
146 if (out_fmt==IMGFMT_BGR8) { |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
147 png_get_PLTE( png,info,&pal,&cols ); |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
148 mpi->planes[1] = (char*)realloc(mpi->planes[1], 4*cols); |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
149 p = mpi->planes[1]; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
150 for (i = 0; i < cols; i++) { |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
151 *p++ = pal[i].blue; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
152 *p++ = pal[i].green; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
153 *p++ = pal[i].red; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
154 *p++ = 0; |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
155 } |
ef7349907cf4
8bit palette mode support (and spurious ^M removal)
henry
parents:
11566
diff
changeset
|
156 } |
4998 | 157 |
158 png_read_end( png,endinfo ); | |
159 png_destroy_read_struct( &png,&info,&endinfo ); | |
160 | |
161 return mpi; | |
162 } | |
163 | |
164 #endif |