annotate mpng.c @ 4667:95fa3901cafc

add vsync support for doublebuffering to vo_vesa
author atmos4
date Tue, 12 Feb 2002 15:06:04 +0000
parents 04880518728d
children 91a1ce283aa8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4656
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
1
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
2 #include <stdlib.h>
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
3
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
4 #include "config.h"
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
5 #include "bswap.h"
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
6 #include "postproc/rgb2rgb.h"
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
7 #include "mp_msg.h"
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
8 #include "png.h"
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
9
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
10 int pngPointer;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
11
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
12 void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size )
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
13 {
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
14 char * p = pngstr->io_ptr;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
15 memcpy( buffer,(char *)&p[pngPointer],size );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
16 pngPointer+=size;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
17 }
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
18
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
19 void decode_mpng(
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
20 unsigned char *encoded,
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
21 int encoded_size,
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
22 unsigned char *decoded,
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
23 int width,
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
24 int height,
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
25 int bytes_per_pixel)
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
26 {
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
27 png_structp png;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
28 png_infop info;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
29 png_infop endinfo;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
30 png_bytep data;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
31 png_bytep * row_p;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
32 png_uint_32 png_width,png_height;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
33 char * palette = NULL;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
34 int depth,color;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
35 png_uint_32 i;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
36 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
37 info=png_create_info_struct( png );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
38 endinfo=png_create_info_struct( png );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
39
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
40 pngPointer=8;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
41 png_set_read_fn( png,encoded,pngReadFN );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
42 png_set_sig_bytes( png,8 );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
43 png_read_info( png,info );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
44 png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
45
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
46 png_set_bgr( png );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
47
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
48 #if 0
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
49 switch( info->color_type )
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
50 {
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
51 case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
52 case PNG_COLOR_TYPE_GRAY: printf( "[png] used Gray -> rgb\n" ); break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
53 case PNG_COLOR_TYPE_PALETTE: printf( "[png] used palette -> rgb\n" ); break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
54 case PNG_COLOR_TYPE_RGB_ALPHA: printf( "[png] used RGBA -> stripping alpha channel\n" ); break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
55 case PNG_COLOR_TYPE_RGB: printf( "[png] read rgb datas.\n" ); break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
56 }
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
57 #endif
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
58
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
59 if ( info->color_type == PNG_COLOR_TYPE_RGB ) data=decoded;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
60 else data=(png_bytep)malloc( png_get_rowbytes( png,info ) * height );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
61
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
62 row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
63 for ( i=0; i < png_height; i++ ) row_p[i]=&data[png_get_rowbytes( png,info ) * i];
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
64 png_read_image( png,row_p );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
65 free( row_p );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
66
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
67 switch( info->color_type )
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
68 {
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
69 case PNG_COLOR_TYPE_GRAY_ALPHA:
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
70 mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
71 free( data );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
72 break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
73 case PNG_COLOR_TYPE_GRAY:
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
74 palette=malloc( 1024 );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
75 for ( i=0;i < 256;i++ ) palette[(i*4)]=palette[(i*4)+1]=palette[(i*4)+2]=(char)i;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
76 palette8torgb24( data,decoded,png_width * png_height,palette );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
77 free( data );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
78 break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
79 case PNG_COLOR_TYPE_PALETTE:
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
80 {
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
81 int cols;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
82 unsigned char * pal;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
83 png_get_PLTE( png,info,(png_colorp*)&pal,&cols );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
84 palette=calloc( 1,1024 );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
85 for ( i=0;i < cols;i++ )
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
86 {
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
87 palette[(i*4) ]=pal[(i*3)+2];
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
88 palette[(i*4)+1]=pal[(i*3)+1];
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
89 palette[(i*4)+2]=pal[(i*3) ];
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
90 }
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
91 }
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
92 palette8torgb24( data,decoded,png_width * png_height,palette );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
93 free( data );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
94 break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
95 case PNG_COLOR_TYPE_RGB_ALPHA:
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
96 rgb32to24( data,decoded,png_width * png_height * 4 );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
97 free( data );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
98 break;
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
99 }
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
100
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
101 if ( palette ) free( palette );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
102
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
103 png_read_end( png,endinfo );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
104 png_destroy_read_struct( &png,&info,&endinfo );
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
105 }
04880518728d add initial mPNG support
pontscho
parents:
diff changeset
106