annotate Gui/bitmap.c @ 7491:87197e110b4f

accepted. so we're now 110% gpl...
author arpi
date Mon, 23 Sep 2002 19:02:21 +0000
parents 757e876d36fe
children 30a9a6358ee9
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
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
6 #include "bitmap.h"
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
7
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
8 int conv24to32( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
9 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
10 unsigned char * tmpImage;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
11 int i,c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
12
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
13 if ( bf->BPP == 24 )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
14 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
15 tmpImage=bf->Image;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
16 bf->ImageSize=bf->Width * bf->Height * 4;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
17 bf->BPP=32;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
18 if ( ( bf->Image=malloc( bf->ImageSize ) ) == NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
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
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
21 return 1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
22 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
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
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
25 {
6054
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
26 #ifndef WORDS_BIGENDIAN
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
27 bf->Image[c++]=tmpImage[i++]; //red
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
28 bf->Image[c++]=tmpImage[i++]; //green
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
29 bf->Image[c++]=tmpImage[i++]; c++; //blue
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
30 #else
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
31 unsigned char t=tmpImage[i++];
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
32 bf->Image[c++]=tmpImage[i++]; //green
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
33 bf->Image[c++]=t; c++; //red
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
34 bf->Image[c++]=tmpImage[i++]; //blue
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
35 #endif
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
36 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
37 free( tmpImage );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
38 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
39 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
40 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
41
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
42 void bgr2rgb( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
43 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
44 unsigned char c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
45 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
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
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
48 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
49 c=bf->Image[i];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
50 bf->Image[i]=bf->Image[i+2];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
51 bf->Image[i+2]=c;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
52 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
53 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
54
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
55 void Normalize( txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
56 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
57 int i;
6054
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
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
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
60 #else
35689e1e6745 bigendian fix by Colin Leroy <colin@colino.net>
arpi
parents: 4818
diff changeset
61 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
62 #endif
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
63 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
64
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
65 unsigned char tmp[512];
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
66
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
67 unsigned char * fExist( unsigned char * fname )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
68 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
69 FILE * fl;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
70 unsigned char ext[][6] = { ".png\0",".PNG\0" };
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
71 int i;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
72
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
73 fl=fopen( fname,"rb" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
74 if ( fl != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
75 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
76 fclose( fl );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
77 return fname;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
78 }
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
79 for ( i=0;i<2;i++ )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
80 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
81 sprintf( tmp,"%s%s",fname,ext[i] );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
82 fl=fopen( tmp,"rb" );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
83 if ( fl != NULL )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
84 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
85 fclose( fl );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
86 return tmp;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
87 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
88 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
89 return NULL;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
90 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
91
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
92 int bpRead( char * fname, txSample * bf )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
93 {
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
94 fname=fExist( fname );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
95 if ( fname == NULL ) return -2;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
96 if ( pngRead( fname,bf ) )
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
97 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
98 mp_dbg( MSGT_GPLAYER,MSGL_FATAL,"[bitmap] Unknown file type ( %s ).\n",fname );
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
99 return -5;
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
100 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
101 if ( bf->BPP < 24 )
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
102 {
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
103 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
104 return -1;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
105 }
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
106 if ( conv24to32( bf ) ) return -8;
7265
634d93c68912 - add workaround for fuckin locale
pontscho
parents: 6159
diff changeset
107 bgr2rgb( bf );
1693
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
108 Normalize( bf );
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
109 return 0;
d237c5d4b216 GUI version n-1
arpi
parents:
diff changeset
110 }
2717
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
111
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
112 void Convert32to1( txSample * in,txSample * out,int adaptivlimit )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
113 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
114 out->Width=in->Width;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
115 out->Height=in->Height;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
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
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
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
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
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
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
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
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
127 else { tmp=tmp >> 1; buf[i]=nothaveshape=0; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
128 if ( b++ == 7 ) { out->Image[c++]=tmp; tmp=b=0; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
129 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
130 if ( b ) out->Image[c]=tmp;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
131 if ( nothaveshape ) { free( out->Image ); out->Image=NULL; }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
132 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
133 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
134
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
135 void Convert1to32( txSample * in,txSample * out )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
136 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
137 if ( in->Image == NULL ) return;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
138 out->Width=in->Width;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
139 out->Height=in->Height;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
140 out->BPP=32;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
141 out->ImageSize=out->Width * out->Height * 4;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
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
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
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
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
149 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
150 tmp=in->Image[i];
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
151 for ( b=0;b<8;b++ )
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
152 {
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
153 buf[c]=0;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
154 if ( tmp&0x1 ) buf[c]=0xffffffff;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
155 c++; tmp=tmp>>1;
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
156 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
157 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
158 }
5fa8c079ee3c fix small xshape bug
pontscho
parents: 2080
diff changeset
159 }