annotate Gui/bitmap.c @ 10308:b27f7db9bccb

DivX4Linux and XVID can be used together
author gabucino
date Wed, 18 Jun 2003 16:12:29 +0000
parents 46badb3d0b1c
children c30e193ac112
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2080
f91ad6d23ce9 gcc3 warning fixed
arpi
parents: 1693
diff changeset
1 #include <stdio.h>
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
2 #include <stdlib.h>
2080
f91ad6d23ce9 gcc3 warning fixed
arpi
parents: 1693
diff changeset
3 #include <string.h>
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
4
8046
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
5 #include <png.h>
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
6
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
7 #include "../../mp_msg.h"
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
8 #include "bitmap.h"
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
9
8046
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
10 int pngRead( unsigned char * fname,txSample * bf )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
11 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
12 unsigned char header[8];
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
13 png_structp png;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
14 png_infop info;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
15 png_infop endinfo;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
16 png_bytep * row_p;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
17 png_bytep palette = NULL;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
18 int color;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
19 png_uint_32 i;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
20
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
21 FILE *fp=fopen( fname,"rb" );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
22 if ( !fp )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
23 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
24 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] file read error ( %s ).\n",fname );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
25 return 1;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
26 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
27
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
28 fread( header,1,8,fp );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
29 if ( !png_check_sig( header,8 ) ) return 1;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
30
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
31 png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
32 info=png_create_info_struct( png );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
33 endinfo=png_create_info_struct( png );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
34
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
35 png_init_io( png,fp );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
36 png_set_sig_bytes( png,8 );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
37 png_read_info( png,info );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
38 png_get_IHDR( png,info,&bf->Width,&bf->Height,&bf->BPP,&color,NULL,NULL,NULL );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
39
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
40 row_p=(png_bytep *)malloc( sizeof( png_bytep ) * bf->Height );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
41 if ( !row_p )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
42 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
43 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] Not enough memory for row buffer.\n" );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
44 return 2;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
45 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
46 bf->Image=(png_bytep)malloc( png_get_rowbytes( png,info ) * bf->Height );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
47 if ( !bf->Image )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
48 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
49 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] Not enough memory for image buffer.\n" );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
50 return 2;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
51 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
52 for ( i=0; i < bf->Height; i++ ) row_p[i]=&bf->Image[png_get_rowbytes( png,info ) * i];
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
53
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
54 png_read_image( png,row_p );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
55 free( row_p );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
56
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
57 #if 0
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
58 if ( color == PNG_COLOR_TYPE_PALETTE )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
59 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
60 int cols;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
61 png_get_PLTE( png,info,(png_colorp *)&palette,&cols );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
62 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
63 #endif
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
64
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
65 if ( color&PNG_COLOR_MASK_ALPHA )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
66 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
67 if ( color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY_ALPHA ) bf->BPP*=2;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
68 else bf->BPP*=4;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
69 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
70 else
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
71 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
72 if ( color&PNG_COLOR_MASK_PALETTE || color == PNG_COLOR_TYPE_GRAY ) bf->BPP*=1;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
73 else bf->BPP*=3;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
74 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
75
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
76 png_read_end( png,endinfo );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
77 png_destroy_read_struct( &png,&info,&endinfo );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
78
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
79 if ( fclose( fp ) != 0 )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
80 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
81 free( bf->Image );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
82 free( palette );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
83 return 1;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
84 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
85 bf->ImageSize=bf->Width * bf->Height * ( bf->BPP / 8 );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
86
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
87 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] filename: %s.\n",fname );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
88 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] size: %dx%d bits: %d\n",bf->Width,bf->Height,bf->BPP );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
89 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] imagesize: %lu\n",bf->ImageSize );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
90 return 0;
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
91 }
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
92
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
93 int conv24to32( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
94 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
95 unsigned char * tmpImage;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
96 int i,c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
97
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
98 if ( bf->BPP == 24 )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
99 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
100 tmpImage=bf->Image;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
101 bf->ImageSize=bf->Width * bf->Height * 4;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
102 bf->BPP=32;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
103 if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
104 {
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
105 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] Not enough memory for image.\n" );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
106 return 1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
107 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
108 memset( bf->Image,0,bf->ImageSize );
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
109 for ( c=0,i=0;i < (int)(bf->Width * bf->Height * 3); )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
110 {
6054
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
111 bf->Image[c++]=tmpImage[i++]; //red
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
112 bf->Image[c++]=tmpImage[i++]; //green
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
113 bf->Image[c++]=tmpImage[i++]; c++; //blue
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
114 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
115 free( tmpImage );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
116 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
117 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
118 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
119
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
120 void bgr2rgb( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
121 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
122 unsigned char c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
123 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
124
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
125 for ( i=0;i < (int)bf->ImageSize;i+=4 )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
126 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
127 c=bf->Image[i];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
128 bf->Image[i]=bf->Image[i+2];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
129 bf->Image[i+2]=c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
130 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
131 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
132
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
133 void Normalize( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
134 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
135 int i;
6054
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
136 #ifndef WORDS_BIGENDIAN
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
137 for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i+3]=0;
6054
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
138 #else
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
139 for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i]=0;
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
140 #endif
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
141 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
142
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
143 unsigned char tmp[512];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
144
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
145 unsigned char * fExist( unsigned char * fname )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
146 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
147 FILE * fl;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
148 unsigned char ext[][6] = { ".png\0",".PNG\0" };
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
149 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
150
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
151 fl=fopen( fname,"rb" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
152 if ( fl != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
153 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
154 fclose( fl );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
155 return fname;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
156 }
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
157 for ( i=0;i<2;i++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
158 {
10168
22572f1dafa3 some fixes and bigendian fix for 32bpp pngs
alex
parents: 8046
diff changeset
159 snprintf( tmp,511,"%s%s",fname,ext[i] );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
160 fl=fopen( tmp,"rb" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
161 if ( fl != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
162 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
163 fclose( fl );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
164 return tmp;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
165 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
166 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
167 return NULL;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
168 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
169
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
170 int bpRead( char * fname, txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
171 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
172 fname=fExist( fname );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
173 if ( fname == NULL ) return -2;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
174 if ( pngRead( fname,bf ) )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
175 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
176 mp_dbg( MSGT_GPLAYER,MSGL_FATAL,"[bitmap] Unknown file type ( %s ).\n",fname );
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
177 return -5;
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
178 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
179 if ( bf->BPP < 24 )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
180 {
10168
22572f1dafa3 some fixes and bigendian fix for 32bpp pngs
alex
parents: 8046
diff changeset
181 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] Sorry, only 24 and 32 bpp bitmaps are supported.\n" );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
182 return -1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
183 }
10169
46badb3d0b1c simplyfied it and fixed some 10ls (but sadly xshape still don't works)
alex
parents: 10168
diff changeset
184 if ( conv24to32( bf ) ) return -8;
10168
22572f1dafa3 some fixes and bigendian fix for 32bpp pngs
alex
parents: 8046
diff changeset
185 #ifdef WORDS_BIGENDIAN
10169
46badb3d0b1c simplyfied it and fixed some 10ls (but sadly xshape still don't works)
alex
parents: 10168
diff changeset
186 swab(bf->Image, bf->Image, bf->ImageSize);
10168
22572f1dafa3 some fixes and bigendian fix for 32bpp pngs
alex
parents: 8046
diff changeset
187 #endif
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
188 bgr2rgb( bf );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
189 Normalize( bf );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
190 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
191 }
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
192
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
193 void Convert32to1( txSample * in,txSample * out,int adaptivlimit )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
194 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
195 out->Width=in->Width;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
196 out->Height=in->Height;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
197 out->BPP=1;
7352
757e876d36fe Off-by-one error allocating bitmap, when (width*height) % 8 != 0
jkeil
parents: 7265
diff changeset
198 out->ImageSize=(out->Width * out->Height + 7) / 8;
10169
46badb3d0b1c simplyfied it and fixed some 10ls (but sadly xshape still don't works)
alex
parents: 10168
diff changeset
199 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c32to1] imagesize: %d\n",out->ImageSize );
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
200 out->Image=(char *)calloc( 1,out->ImageSize );
10168
22572f1dafa3 some fixes and bigendian fix for 32bpp pngs
alex
parents: 8046
diff changeset
201 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[c32to1] Not enough memory for image.\n" );
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
202 {
6145
26cb8736927b Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents: 6054
diff changeset
203 int i,b,c=0; unsigned int * buf = NULL; unsigned char tmp = 0; int nothaveshape = 1;
26cb8736927b Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents: 6054
diff changeset
204 buf=(unsigned int *)in->Image;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
205 for ( b=0,i=0;i < (int)(out->Width * out->Height);i++ )
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
206 {
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
207 if ( (int)buf[i] != adaptivlimit ) tmp=( tmp >> 1 )|128;
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
208 else { tmp=tmp >> 1; buf[i]=nothaveshape=0; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
209 if ( b++ == 7 ) { out->Image[c++]=tmp; tmp=b=0; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
210 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
211 if ( b ) out->Image[c]=tmp;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
212 if ( nothaveshape ) { free( out->Image ); out->Image=NULL; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
213 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
214 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
215
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
216 void Convert1to32( txSample * in,txSample * out )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
217 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
218 if ( in->Image == NULL ) return;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
219 out->Width=in->Width;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
220 out->Height=in->Height;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
221 out->BPP=32;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
222 out->ImageSize=out->Width * out->Height * 4;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
223 out->Image=(char *)calloc( 1,out->ImageSize );
10169
46badb3d0b1c simplyfied it and fixed some 10ls (but sadly xshape still don't works)
alex
parents: 10168
diff changeset
224 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c1to32] imagesize: %d\n",out->ImageSize );
10168
22572f1dafa3 some fixes and bigendian fix for 32bpp pngs
alex
parents: 8046
diff changeset
225 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"[c1to32] Not enough memory for image.\n" );
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
226 {
6145
26cb8736927b Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents: 6054
diff changeset
227 int i,b,c=0; unsigned int * buf = NULL; unsigned char tmp = 0;
26cb8736927b Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents: 6054
diff changeset
228 buf=(unsigned int *)out->Image;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
229 for ( c=0,i=0;i < (int)(in->Width * in->Height / 8);i++ )
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
230 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
231 tmp=in->Image[i];
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
232 for ( b=0;b<8;b++ )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
233 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
234 buf[c]=0;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
235 if ( tmp&0x1 ) buf[c]=0xffffffff;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
236 c++; tmp=tmp>>1;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
237 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
238 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
239 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
240 }