Mercurial > mplayer.hg
annotate Gui/bitmap.c @ 7038:bfb03691fb4b
skip blocks with small chroma dc support
author | michael |
---|---|
date | Sat, 17 Aug 2002 20:48:23 +0000 |
parents | dcf195b784bf |
children | 634d93c68912 |
rev | line source |
---|---|
1693 | 1 |
2080 | 2 #include <stdio.h> |
1693 | 3 #include <stdlib.h> |
2080 | 4 #include <string.h> |
1693 | 5 |
6 #include "bitmap.h" | |
7 | |
8 #define BMP 1 | |
9 #define TGA 2 | |
10 #define PNG 3 | |
11 #define TGAPACKED 4 | |
12 | |
13 extern char * strcat( char * dest,const char * src ); | |
14 | |
15 int conv24to32( txSample * bf ) | |
16 { | |
17 unsigned char * tmpImage; | |
18 int i,c; | |
19 | |
20 if ( bf->BPP == 24 ) | |
21 { | |
22 tmpImage=bf->Image; | |
23 bf->ImageSize=bf->Width * bf->Height * 4; | |
24 bf->BPP=32; | |
25 if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL ) | |
26 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
27 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] Not enough memory for image.\n" ); |
1693 | 28 return 1; |
29 } | |
30 memset( bf->Image,0,bf->ImageSize ); | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
31 for ( c=0,i=0;i < (int)(bf->Width * bf->Height * 3); ) |
1693 | 32 { |
6054 | 33 #ifndef WORDS_BIGENDIAN |
34 bf->Image[c++]=tmpImage[i++]; //red | |
35 bf->Image[c++]=tmpImage[i++]; //green | |
36 bf->Image[c++]=tmpImage[i++]; c++; //blue | |
37 #else | |
38 unsigned char t=tmpImage[i++]; | |
39 bf->Image[c++]=tmpImage[i++]; //green | |
40 bf->Image[c++]=t; c++; //red | |
41 bf->Image[c++]=tmpImage[i++]; //blue | |
42 #endif | |
1693 | 43 } |
44 free( tmpImage ); | |
45 } | |
46 return 0; | |
47 } | |
48 | |
49 void bgr2rgb( txSample * bf ) | |
50 { | |
51 unsigned char c; | |
52 int i; | |
53 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
54 for ( i=0;i < (int)bf->ImageSize;i+=4 ) |
1693 | 55 { |
56 c=bf->Image[i]; | |
57 bf->Image[i]=bf->Image[i+2]; | |
58 bf->Image[i+2]=c; | |
59 } | |
60 } | |
61 | |
62 void Normalize( txSample * bf ) | |
63 { | |
64 int i; | |
6054 | 65 #ifndef WORDS_BIGENDIAN |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
66 for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i+3]=0; |
6054 | 67 #else |
68 for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i]=0; | |
69 #endif | |
1693 | 70 } |
71 | |
72 unsigned char tmp[512]; | |
73 | |
74 unsigned char * fExist( unsigned char * fname ) | |
75 { | |
76 FILE * fl; | |
77 unsigned char ext[][6] = { ".tga\0",".TGA\0",".png\0",".PNG\0",".bmp\0",".BMP\0" }; | |
78 int i; | |
79 | |
80 fl=fopen( fname,"rb" ); | |
81 if ( fl != NULL ) | |
82 { | |
83 fclose( fl ); | |
84 return fname; | |
85 } | |
86 for ( i=0;i<10;i++ ) | |
87 { | |
88 strcpy( tmp,fname ); | |
89 strcat( tmp,ext[i] ); | |
90 fl=fopen( tmp,"rb" ); | |
91 if ( fl != NULL ) | |
92 { | |
93 fclose( fl ); | |
94 return tmp; | |
95 } | |
96 } | |
97 return NULL; | |
98 } | |
99 | |
100 int aComp( unsigned char * b1,unsigned char * b2,int size ) | |
101 { | |
102 int i; | |
103 for( i=0;i<size;i++ ) if ( b1[i] != b2[i] ) return 0; | |
104 return 1; | |
105 } | |
106 | |
107 int GetFileType( char * fname ) | |
108 { | |
109 FILE * fl; | |
110 unsigned char buffer[10]; | |
111 unsigned char bmp[2] = { 0x42,0x4d }; | |
112 unsigned char tga[7] = { 0x00,0x02,0x00,0x00,0x00,0x00,0x00 }; | |
113 unsigned char ptga[7] = { 0x00,0x0a,0x00,0x00,0x00,0x00,0x00 }; | |
114 unsigned char png[8] = { 0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a }; | |
115 | |
116 if ( ( fl=fopen( fname,"rb" ) ) == NULL ) return -1; | |
117 fread( buffer,1,10,fl ); | |
118 fclose( fl ); | |
119 | |
120 if ( aComp( buffer,bmp,2 ) ) return BMP; // --- bmp | |
121 if ( aComp( &buffer[1],tga,8 ) ) return TGA; // --- tga | |
122 if ( aComp( &buffer[1],ptga,7 ) ) return TGAPACKED; // --- tga | |
123 if ( aComp( buffer,png,8 ) ) return PNG; // --- png | |
124 return 0; // --- others | |
125 } | |
126 | |
127 int bpRead( char * fname, txSample * bf ) | |
128 { | |
129 int bgr = 0; | |
130 int i; | |
131 | |
132 fname=fExist( fname ); | |
133 if ( fname == NULL ) return -2; | |
134 switch ( GetFileType( fname ) ) | |
135 { | |
136 case BMP: | |
137 i=bmpRead( fname,bf ); | |
138 switch ( i ) | |
139 { | |
140 case 0: break; | |
141 case 3: return -1; | |
142 default: return -3; | |
143 } | |
144 break; | |
145 case TGA: | |
146 i=tgaRead( fname,bf ); | |
147 switch ( i ) | |
148 { | |
149 case 0: break; | |
150 case 3: return -1; | |
151 default: return -4; | |
152 } | |
153 break; | |
154 case PNG: | |
155 if ( pngRead( fname,bf ) ) return -5; | |
156 bgr=1; | |
157 break; | |
158 case TGAPACKED: | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
159 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] sorry, packed TGA not supported.\n" ); |
1693 | 160 return -6; |
161 default: | |
162 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
163 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] Unknown file type ( %s ).\n",fname ); |
1693 | 164 return -7; |
165 } | |
166 } | |
167 if ( bf->BPP < 24 ) | |
168 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
169 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] sorry, 16 or less bitmaps not supported.\n" ); |
1693 | 170 return -1; |
171 } | |
172 if ( conv24to32( bf ) ) return -8; | |
173 if ( bgr ) bgr2rgb( bf ); | |
174 Normalize( bf ); | |
175 return 0; | |
176 } | |
2717 | 177 |
178 void Convert32to1( txSample * in,txSample * out,int adaptivlimit ) | |
179 { | |
180 out->Width=in->Width; | |
181 out->Height=in->Height; | |
182 out->BPP=1; | |
183 out->ImageSize=out->Width * out->Height / 8; | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
184 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c1to32] imagesize: %d\n",out->ImageSize ); |
2717 | 185 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
|
186 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"nem van ram baze\n" ); |
2717 | 187 { |
6145
26cb8736927b
Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents:
6054
diff
changeset
|
188 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
|
189 buf=(unsigned int *)in->Image; |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
190 for ( b=0,i=0;i < (int)(out->Width * out->Height);i++ ) |
2717 | 191 { |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
192 if ( (int)buf[i] != adaptivlimit ) tmp=( tmp >> 1 )|128; |
2717 | 193 else { tmp=tmp >> 1; buf[i]=nothaveshape=0; } |
194 if ( b++ == 7 ) { out->Image[c++]=tmp; tmp=b=0; } | |
195 } | |
196 if ( b ) out->Image[c]=tmp; | |
197 if ( nothaveshape ) { free( out->Image ); out->Image=NULL; } | |
198 } | |
199 } | |
200 | |
201 void Convert1to32( txSample * in,txSample * out ) | |
202 { | |
203 if ( in->Image == NULL ) return; | |
204 out->Width=in->Width; | |
205 out->Height=in->Height; | |
206 out->BPP=32; | |
207 out->ImageSize=out->Width * out->Height * 4; | |
208 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
|
209 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
|
210 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"nem van ram baze\n" ); |
2717 | 211 { |
6145
26cb8736927b
Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents:
6054
diff
changeset
|
212 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
|
213 buf=(unsigned int *)out->Image; |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
214 for ( c=0,i=0;i < (int)(in->Width * in->Height / 8);i++ ) |
2717 | 215 { |
216 tmp=in->Image[i]; | |
217 for ( b=0;b<8;b++ ) | |
218 { | |
219 buf[c]=0; | |
220 if ( tmp&0x1 ) buf[c]=0xffffffff; | |
221 c++; tmp=tmp>>1; | |
222 } | |
223 } | |
224 } | |
225 } |