annotate Gui/bitmap.c @ 22747:65c3b647408c

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