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