annotate Gui/bitmap.c @ 9367:f107fcf6fdea

10l
author jonas
date Sun, 09 Feb 2003 13:13:00 +0000
parents 30a9a6358ee9
children 22572f1dafa3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
1
2080
f91ad6d23ce9 gcc3 warning fixed
arpi
parents: 1693
diff changeset
2 #include <stdio.h>
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
3 #include <stdlib.h>
2080
f91ad6d23ce9 gcc3 warning fixed
arpi
parents: 1693
diff changeset
4 #include <string.h>
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
5
8046
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
6 #include <png.h>
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
7
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
8 #include "../../mp_msg.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 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
25 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] file read error ( %s ).\n",fname );
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
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
41 row_p=(png_bytep *)malloc( sizeof( png_bytep ) * bf->Height );
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
42 if ( !row_p )
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
43 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
44 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] Not enough memory for row buffer.\n" );
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 {
30a9a6358ee9 cleanup - round 2.
pontscho
parents: 7352
diff changeset
50 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[png] Not enough memory for image buffer.\n" );
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 {
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
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 #ifndef WORDS_BIGENDIAN
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
113 bf->Image[c++]=tmpImage[i++]; //red
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
114 bf->Image[c++]=tmpImage[i++]; //green
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
115 bf->Image[c++]=tmpImage[i++]; c++; //blue
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
116 #else
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
117 unsigned char t=tmpImage[i++];
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
118 bf->Image[c++]=tmpImage[i++]; //green
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
119 bf->Image[c++]=t; c++; //red
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
120 bf->Image[c++]=tmpImage[i++]; //blue
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
121 #endif
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
122 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
123 free( tmpImage );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
124 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
125 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
126 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
127
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
128 void bgr2rgb( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
129 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
130 unsigned char c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
131 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
132
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
133 for ( i=0;i < (int)bf->ImageSize;i+=4 )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
134 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
135 c=bf->Image[i];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
136 bf->Image[i]=bf->Image[i+2];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
137 bf->Image[i+2]=c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
138 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
139 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
140
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
141 void Normalize( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
142 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
143 int i;
6054
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
144 #ifndef WORDS_BIGENDIAN
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
145 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
146 #else
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
147 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
148 #endif
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
149 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
150
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
151 unsigned char tmp[512];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
152
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
153 unsigned char * fExist( unsigned char * fname )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
154 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
155 FILE * fl;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
156 unsigned char ext[][6] = { ".png\0",".PNG\0" };
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
157 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
158
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
159 fl=fopen( fname,"rb" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
160 if ( fl != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
161 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
162 fclose( fl );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
163 return fname;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
164 }
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
165 for ( i=0;i<2;i++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
166 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
167 sprintf( tmp,"%s%s",fname,ext[i] );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
168 fl=fopen( tmp,"rb" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
169 if ( fl != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
170 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
171 fclose( fl );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
172 return tmp;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
173 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
174 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
175 return NULL;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
176 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
177
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
178 int bpRead( char * fname, txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
179 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
180 fname=fExist( fname );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
181 if ( fname == NULL ) return -2;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
182 if ( pngRead( fname,bf ) )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
183 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
184 mp_dbg( MSGT_GPLAYER,MSGL_FATAL,"[bitmap] Unknown file type ( %s ).\n",fname );
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
185 return -5;
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
186 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
187 if ( bf->BPP < 24 )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
188 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
189 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] sorry, 16 or less bitmaps not supported.\n" );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
190 return -1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
191 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
192 if ( conv24to32( bf ) ) return -8;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
193 bgr2rgb( bf );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
194 Normalize( bf );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
195 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
196 }
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
197
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
198 void Convert32to1( txSample * in,txSample * out,int adaptivlimit )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
199 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
200 out->Width=in->Width;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
201 out->Height=in->Height;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
202 out->BPP=1;
7352
757e876d36fe Off-by-one error allocating bitmap, when (width*height) % 8 != 0
jkeil
parents: 7265
diff changeset
203 out->ImageSize=(out->Width * out->Height + 7) / 8;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
204 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c1to32] imagesize: %d\n",out->ImageSize );
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
205 out->Image=(char *)calloc( 1,out->ImageSize );
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
206 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"nem van ram baze\n" );
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
207 {
6145
26cb8736927b Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents: 6054
diff changeset
208 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
209 buf=(unsigned int *)in->Image;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
210 for ( b=0,i=0;i < (int)(out->Width * out->Height);i++ )
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
211 {
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
212 if ( (int)buf[i] != adaptivlimit ) tmp=( tmp >> 1 )|128;
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
213 else { tmp=tmp >> 1; buf[i]=nothaveshape=0; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
214 if ( b++ == 7 ) { out->Image[c++]=tmp; tmp=b=0; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
215 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
216 if ( b ) out->Image[c]=tmp;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
217 if ( nothaveshape ) { free( out->Image ); out->Image=NULL; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
218 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
219 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
220
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
221 void Convert1to32( txSample * in,txSample * out )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
222 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
223 if ( in->Image == NULL ) return;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
224 out->Width=in->Width;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
225 out->Height=in->Height;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
226 out->BPP=32;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
227 out->ImageSize=out->Width * out->Height * 4;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
228 out->Image=(char *)calloc( 1,out->ImageSize );
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
229 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c32to1] imagesize: %d\n",out->ImageSize );
6159
dcf195b784bf applied 64bit patch from Ulrich Hecht <uli@suse.de>
pontscho
parents: 6145
diff changeset
230 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"nem van ram baze\n" );
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
231 {
6145
26cb8736927b Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents: 6054
diff changeset
232 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
233 buf=(unsigned int *)out->Image;
4818
3473ca9ef158 new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents: 2717
diff changeset
234 for ( c=0,i=0;i < (int)(in->Width * in->Height / 8);i++ )
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
235 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
236 tmp=in->Image[i];
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
237 for ( b=0;b<8;b++ )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
238 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
239 buf[c]=0;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
240 if ( tmp&0x1 ) buf[c]=0xffffffff;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
241 c++; tmp=tmp>>1;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
242 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
243 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
244 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
245 }