annotate libmpcodecs/vd_mpng.c @ 16593:1c13fb2ba5a9

Allow specifying a custom (ppm) texture for texture unit 3
author reimar
date Sun, 25 Sep 2005 16:31:58 +0000
parents ef7349907cf4
children 3469899beb42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
1 #include <stdio.h>
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
2 #include <stdlib.h>
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
3
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
4 #include "config.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
5 #include "mp_msg.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
6
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
7 #ifdef HAVE_PNG
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
8
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
9 #include <png.h>
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
10
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
11 #include "bswap.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
12 #include "postproc/rgb2rgb.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
13 #include "libvo/fastmemcpy.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
14
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
15 #include "vd_internal.h"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
16
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
17 static vd_info_t info = {
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
18 "PNG Images decoder",
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
19 "mpng",
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
20 "A'rpi",
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
21 ".so, based on mpng.c",
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
22 "uses libpng, 8bpp modes not supported yet"
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
23 };
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
24
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
25 LIBVD_EXTERN(mpng)
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
26
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
27 static unsigned int out_fmt=0;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
28
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
29 static int last_w=-1;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
30 static int last_h=-1;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
31 static int last_c=-1;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
32
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
33 // to set/get/query special features/parameters
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
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
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
41 return CONTROL_UNKNOWN;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
42 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
43
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
44 // init driver
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
45 static int init(sh_video_t *sh){
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
46 last_w=-1;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
47 return 1;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
48 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
49
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
50 // uninit driver
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
51 static void uninit(sh_video_t *sh){
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
52 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
53
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
54 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
55
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
56 static int pngPointer;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
57 static int pngLength;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
58
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
59 static void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size )
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
60 {
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
61 char * p = pngstr->io_ptr;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
62 if(size>pngLength-pngPointer && pngLength>=pngPointer) size=pngLength-pngPointer;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
63 memcpy( buffer,(char *)&p[pngPointer],size );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
64 pngPointer+=size;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
65 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
66
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
67 // decode a frame
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
68 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
69 png_structp png;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
70 png_infop info;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
71 png_infop endinfo;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
72 // png_bytep data;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
73 png_bytep * row_p;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
74 png_uint_32 png_width=0,png_height=0;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
75 int depth,color;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
76 png_uint_32 i;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
77 mp_image_t* mpi;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
78
15502
ef7349907cf4 8bit palette mode support (and spurious ^M removal)
henry
parents: 11566
diff changeset
79 int cols;
ef7349907cf4 8bit palette mode support (and spurious ^M removal)
henry
parents: 11566
diff changeset
80 png_colorp pal;
ef7349907cf4 8bit palette mode support (and spurious ^M removal)
henry
parents: 11566
diff changeset
81 unsigned char *p;
ef7349907cf4 8bit palette mode support (and spurious ^M removal)
henry
parents: 11566
diff changeset
82
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
83 if(len<=0) return NULL; // skipped frame
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
84
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
85 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
86 info=png_create_info_struct( png );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
87 endinfo=png_create_info_struct( png );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
88
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
89 pngPointer=8;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
90 pngLength=len;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
91 png_set_read_fn( png,data,pngReadFN );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
92 png_set_sig_bytes( png,8 );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
93 png_read_info( png,info );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
94 png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
95 png_set_bgr( png );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
96
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
97 switch( info->color_type ) {
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
98 case PNG_COLOR_TYPE_GRAY_ALPHA:
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
99 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
100 break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
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
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
104 case PNG_COLOR_TYPE_PALETTE:
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
105 out_fmt=IMGFMT_BGR8;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
106 break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
107 case PNG_COLOR_TYPE_RGB_ALPHA:
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
108 out_fmt=IMGFMT_BGR32;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
109 break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
110 case PNG_COLOR_TYPE_RGB:
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
111 out_fmt=IMGFMT_BGR24;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
112 break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
113 default:
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
114 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry, unsupported PNG colorspace: %d.\n" ,info->color_type);
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
115 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
116
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
117 // (re)init libvo if image parameters changed (width/height/colorspace)
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
118 if(last_w!=png_width || last_h!=png_height || last_c!=out_fmt){
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
119 last_w=png_width; last_h=png_height; last_c=out_fmt;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
120 if(!out_fmt) return NULL;
5124
3dcbf67c0de0 handle error from mpcodecs_config_vo()
arpi
parents: 4998
diff changeset
121 if(!mpcodecs_config_vo(sh,png_width,png_height,out_fmt)) return NULL;
4998
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
122 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
123
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
124 #if 0
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
125 switch( info->color_type )
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
126 {
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
127 case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
128 case PNG_COLOR_TYPE_GRAY: printf( "[png] used Gray -> rgb\n" ); break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
129 case PNG_COLOR_TYPE_PALETTE: printf( "[png] used palette -> rgb\n" ); break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
130 case PNG_COLOR_TYPE_RGB_ALPHA: printf( "[png] used RGBA -> stripping alpha channel\n" ); break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
131 case PNG_COLOR_TYPE_RGB: printf( "[png] read rgb datas.\n" ); break;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
132 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
133 #endif
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
134
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
135 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
136 png_width,png_height);
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
137 if(!mpi) return NULL;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
138
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
139 // Let's DECODE!
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
140 row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
141 //png_get_rowbytes( png,info )
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
142 for ( i=0; i < png_height; i++ ) row_p[i]=mpi->planes[0] + mpi->stride[0]*i;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
143 png_read_image( png,row_p );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
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
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
157
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
158 png_read_end( png,endinfo );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
159 png_destroy_read_struct( &png,&info,&endinfo );
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
160
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
161 return mpi;
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
162 }
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
163
c32191b02a66 mpng, libmpeg2 added, none of them finished :(
arpi
parents:
diff changeset
164 #endif