Mercurial > mplayer.hg
annotate Gui/bitmap/png/png.c @ 5935:5074aa8fae5a
printf to mp_msg
author | albeu |
---|---|
date | Thu, 02 May 2002 10:49:55 +0000 |
parents | 3473ca9ef158 |
children |
rev | line source |
---|---|
1693 | 1 |
2 #include <stdlib.h> | |
3 | |
4 #include "./png.h" | |
5 #include <png.h> | |
6 | |
7 typedef struct | |
8 { | |
9 unsigned int Width; | |
10 unsigned int Height; | |
11 unsigned int Depth; | |
12 unsigned int Alpha; | |
13 | |
14 unsigned int Components; | |
15 unsigned char * Data; | |
16 unsigned char * Palette; | |
17 } pngRawInfo; | |
18 | |
19 int pngLoadRawF( FILE *fp,pngRawInfo *pinfo ) | |
20 { | |
21 unsigned char header[8]; | |
22 png_structp png; | |
23 png_infop info; | |
24 png_infop endinfo; | |
25 png_bytep data; | |
26 png_bytep * row_p; | |
27 png_uint_32 width,height; | |
28 int depth,color; | |
29 png_uint_32 i; | |
30 | |
31 if ( !pinfo ) return 1; | |
32 | |
33 fread( header,1,8,fp ); | |
34 if ( !png_check_sig( header,8 ) ) return 1; | |
35 | |
36 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL ); | |
37 info=png_create_info_struct( png ); | |
38 endinfo=png_create_info_struct( png ); | |
39 | |
40 png_init_io( png,fp ); | |
41 png_set_sig_bytes( png,8 ); | |
42 png_read_info( png,info ); | |
43 png_get_IHDR( png,info,&width,&height,&depth,&color,NULL,NULL,NULL ); | |
44 | |
45 pinfo->Width=width; | |
46 pinfo->Height=height; | |
47 pinfo->Depth=depth; | |
48 | |
49 data=( png_bytep ) malloc( png_get_rowbytes( png,info )*height ); | |
50 row_p=( png_bytep * ) malloc( sizeof( png_bytep )*height ); | |
51 for ( i=0; i < height; i++ ) row_p[i]=&data[png_get_rowbytes( png,info )*i]; | |
52 | |
53 png_read_image( png,row_p ); | |
54 free( row_p ); | |
55 | |
56 if ( color == PNG_COLOR_TYPE_PALETTE ) | |
57 { | |
58 int cols; | |
59 png_get_PLTE( png,info,( png_colorp * ) &pinfo->Palette,&cols ); | |
60 } | |
61 else pinfo->Palette=NULL; | |
62 | |
63 if ( color&PNG_COLOR_MASK_ALPHA ) | |
64 { | |
65 if ( color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY_ALPHA ) pinfo->Components=2; | |
66 else pinfo->Components=4; | |
67 pinfo->Alpha=8; | |
68 } | |
69 else | |
70 { | |
71 if ( color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY ) pinfo->Components=1; | |
72 else pinfo->Components=3; | |
73 pinfo->Alpha=0; | |
74 } | |
75 pinfo->Data=data; | |
76 | |
77 png_read_end( png,endinfo ); | |
78 png_destroy_read_struct( &png,&info,&endinfo ); | |
79 | |
80 return 0; | |
81 } | |
82 | |
83 int pngLoadRaw( const char * filename,pngRawInfo * pinfo ) | |
84 { | |
85 int result; | |
86 FILE *fp=fopen( filename,"rb" ); | |
87 | |
88 if ( !fp ) return 1; | |
89 result=pngLoadRawF( fp,pinfo ); | |
90 if ( fclose( fp ) != 0 ) | |
91 { | |
92 if ( result ) | |
93 { | |
94 free( pinfo->Data ); | |
95 free( pinfo->Palette ); | |
96 } | |
97 return 1; | |
98 } | |
99 return 0; | |
100 } | |
101 | |
102 int pngRead( unsigned char * fname,txSample * bf ) | |
103 { | |
104 pngRawInfo raw; | |
105 | |
106 if ( pngLoadRaw( fname,&raw ) ) | |
107 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4237
diff
changeset
|
108 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] file read error ( %s ).\n",fname ); |
1693 | 109 return 1; |
110 } | |
111 bf->Width=raw.Width; | |
112 bf->Height=raw.Height; | |
4237 | 113 bf->BPP=( raw.Depth * raw.Components ); |
1693 | 114 bf->ImageSize=bf->Width * bf->Height * ( bf->BPP / 8 ); |
115 if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL ) | |
116 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4237
diff
changeset
|
117 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] Not enough memory for image buffer.\n" ); |
1693 | 118 return 2; |
119 } | |
120 memcpy( bf->Image,raw.Data,bf->ImageSize ); | |
121 free( raw.Data ); | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4237
diff
changeset
|
122 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] filename: %s.\n",fname ); |
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4237
diff
changeset
|
123 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] size: %dx%d bits: %d\n",bf->Width,bf->Height,bf->BPP ); |
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
4237
diff
changeset
|
124 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] imagesize: %lu\n",bf->ImageSize ); |
1693 | 125 return 0; |
126 } |