Mercurial > mplayer.hg
annotate Gui/bitmap/bitmap.c @ 7789:17956aff04e1
bypass palette from bih, when codec cannot give it in o_bih
author | arpi |
---|---|
date | Sat, 19 Oct 2002 00:57:44 +0000 |
parents | 757e876d36fe |
children | 30a9a6358ee9 |
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 int conv24to32( txSample * bf ) | |
9 { | |
10 unsigned char * tmpImage; | |
11 int i,c; | |
12 | |
13 if ( bf->BPP == 24 ) | |
14 { | |
15 tmpImage=bf->Image; | |
16 bf->ImageSize=bf->Width * bf->Height * 4; | |
17 bf->BPP=32; | |
18 if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL ) | |
19 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
20 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] Not enough memory for image.\n" ); |
1693 | 21 return 1; |
22 } | |
23 memset( bf->Image,0,bf->ImageSize ); | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
24 for ( c=0,i=0;i < (int)(bf->Width * bf->Height * 3); ) |
1693 | 25 { |
6054 | 26 #ifndef WORDS_BIGENDIAN |
27 bf->Image[c++]=tmpImage[i++]; //red | |
28 bf->Image[c++]=tmpImage[i++]; //green | |
29 bf->Image[c++]=tmpImage[i++]; c++; //blue | |
30 #else | |
31 unsigned char t=tmpImage[i++]; | |
32 bf->Image[c++]=tmpImage[i++]; //green | |
33 bf->Image[c++]=t; c++; //red | |
34 bf->Image[c++]=tmpImage[i++]; //blue | |
35 #endif | |
1693 | 36 } |
37 free( tmpImage ); | |
38 } | |
39 return 0; | |
40 } | |
41 | |
42 void bgr2rgb( txSample * bf ) | |
43 { | |
44 unsigned char c; | |
45 int i; | |
46 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
47 for ( i=0;i < (int)bf->ImageSize;i+=4 ) |
1693 | 48 { |
49 c=bf->Image[i]; | |
50 bf->Image[i]=bf->Image[i+2]; | |
51 bf->Image[i+2]=c; | |
52 } | |
53 } | |
54 | |
55 void Normalize( txSample * bf ) | |
56 { | |
57 int i; | |
6054 | 58 #ifndef WORDS_BIGENDIAN |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
59 for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i+3]=0; |
6054 | 60 #else |
61 for ( i=0;i < (int)bf->ImageSize;i+=4 ) bf->Image[i]=0; | |
62 #endif | |
1693 | 63 } |
64 | |
65 unsigned char tmp[512]; | |
66 | |
67 unsigned char * fExist( unsigned char * fname ) | |
68 { | |
69 FILE * fl; | |
7265 | 70 unsigned char ext[][6] = { ".png\0",".PNG\0" }; |
1693 | 71 int i; |
72 | |
73 fl=fopen( fname,"rb" ); | |
74 if ( fl != NULL ) | |
75 { | |
76 fclose( fl ); | |
77 return fname; | |
78 } | |
7265 | 79 for ( i=0;i<2;i++ ) |
1693 | 80 { |
7265 | 81 sprintf( tmp,"%s%s",fname,ext[i] ); |
1693 | 82 fl=fopen( tmp,"rb" ); |
83 if ( fl != NULL ) | |
84 { | |
85 fclose( fl ); | |
86 return tmp; | |
87 } | |
88 } | |
89 return NULL; | |
90 } | |
91 | |
92 int bpRead( char * fname, txSample * bf ) | |
93 { | |
94 fname=fExist( fname ); | |
95 if ( fname == NULL ) return -2; | |
7265 | 96 if ( pngRead( fname,bf ) ) |
1693 | 97 { |
7265 | 98 mp_dbg( MSGT_GPLAYER,MSGL_FATAL,"[bitmap] Unknown file type ( %s ).\n",fname ); |
99 return -5; | |
1693 | 100 } |
101 if ( bf->BPP < 24 ) | |
102 { | |
7265 | 103 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bitmap] sorry, 16 or less bitmaps not supported.\n" ); |
1693 | 104 return -1; |
105 } | |
106 if ( conv24to32( bf ) ) return -8; | |
7265 | 107 bgr2rgb( bf ); |
1693 | 108 Normalize( bf ); |
109 return 0; | |
110 } | |
2717 | 111 |
112 void Convert32to1( txSample * in,txSample * out,int adaptivlimit ) | |
113 { | |
114 out->Width=in->Width; | |
115 out->Height=in->Height; | |
116 out->BPP=1; | |
7352
757e876d36fe
Off-by-one error allocating bitmap, when (width*height) % 8 != 0
jkeil
parents:
7265
diff
changeset
|
117 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
|
118 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[c1to32] imagesize: %d\n",out->ImageSize ); |
2717 | 119 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
|
120 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"nem van ram baze\n" ); |
2717 | 121 { |
6145
26cb8736927b
Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents:
6054
diff
changeset
|
122 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
|
123 buf=(unsigned int *)in->Image; |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
124 for ( b=0,i=0;i < (int)(out->Width * out->Height);i++ ) |
2717 | 125 { |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
126 if ( (int)buf[i] != adaptivlimit ) tmp=( tmp >> 1 )|128; |
2717 | 127 else { tmp=tmp >> 1; buf[i]=nothaveshape=0; } |
128 if ( b++ == 7 ) { out->Image[c++]=tmp; tmp=b=0; } | |
129 } | |
130 if ( b ) out->Image[c]=tmp; | |
131 if ( nothaveshape ) { free( out->Image ); out->Image=NULL; } | |
132 } | |
133 } | |
134 | |
135 void Convert1to32( txSample * in,txSample * out ) | |
136 { | |
137 if ( in->Image == NULL ) return; | |
138 out->Width=in->Width; | |
139 out->Height=in->Height; | |
140 out->BPP=32; | |
141 out->ImageSize=out->Width * out->Height * 4; | |
142 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
|
143 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
|
144 if ( out->Image == NULL ) mp_msg( MSGT_GPLAYER,MSGL_STATUS,"nem van ram baze\n" ); |
2717 | 145 { |
6145
26cb8736927b
Gui and 64-bit issues patch from Gui and 64-bit issues
pontscho
parents:
6054
diff
changeset
|
146 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
|
147 buf=(unsigned int *)out->Image; |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2717
diff
changeset
|
148 for ( c=0,i=0;i < (int)(in->Width * in->Height / 8);i++ ) |
2717 | 149 { |
150 tmp=in->Image[i]; | |
151 for ( b=0;b<8;b++ ) | |
152 { | |
153 buf[c]=0; | |
154 if ( tmp&0x1 ) buf[c]=0xffffffff; | |
155 c++; tmp=tmp>>1; | |
156 } | |
157 } | |
158 } | |
159 } |