Mercurial > mplayer.hg
annotate Gui/bitmap/bmp/bmp.c @ 6486:c0d84f46d349
yvu9 support
author | alex |
---|---|
date | Fri, 21 Jun 2002 17:38:06 +0000 |
parents | 3473ca9ef158 |
children |
rev | line source |
---|---|
1693 | 1 |
2 #ifndef __MY_BMP | |
3 #define __MY_BMP | |
4 | |
5 /* | |
6 0.1 : BMP type. | |
7 2.5 : File size. | |
8 6.7 : Res. | |
9 8.9 : Res. | |
10 10.13 : Offset of bitmap. | |
11 14.17 : Header size. | |
12 18.21 : X size. | |
13 22.25 : Y size. | |
14 26.27 : Number of planes. | |
15 28.29 : Number of bits per pixel. | |
16 30.33 : Compression flag. | |
17 34.37 : Image data size in bytes. | |
18 38.41 : Res | |
19 42.45 : Res | |
20 46.49 : Res | |
21 50.53 : Res | |
22 */ | |
23 | |
2080 | 24 #include <stdio.h> |
1693 | 25 #include <stdlib.h> |
2080 | 26 #include <string.h> |
1693 | 27 |
28 #include "bmp.h" | |
29 #include "../bitmap.h" | |
30 | |
31 int bmpRead( unsigned char * fname,txSample * bF ) | |
32 { | |
33 unsigned char bmpHeader[54]; | |
34 FILE * BMP; | |
35 unsigned long i; | |
36 unsigned char * line; | |
37 int linesize; | |
38 | |
39 | |
40 if ( (BMP=fopen( fname,"rt" )) == NULL ) | |
41 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
42 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] File not found ( %s ).\n",fname ); |
1693 | 43 return 1; |
44 } | |
45 if ( (i=fread( bmpHeader,54,1,BMP )) != 1 ) | |
46 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
47 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] Header read error ( %s ).\n",fname ); |
1693 | 48 return 2; |
49 } | |
50 // memcpy( &bF->Size,&bmpHeader[2],4 ); | |
51 memcpy( &bF->Width,&bmpHeader[18],4 ); | |
52 memcpy( &bF->Height,&bmpHeader[22],4 ); | |
53 memcpy( &bF->BPP,&bmpHeader[28],2 ); | |
54 // memcpy( &bF->ImageSize,&bmpHeader[34],4 ); | |
55 bF->ImageSize=( bF->Width * bF->Height ) * ( bF->BPP / 8 ); | |
56 | |
57 if ( bF->BPP < 24 ) | |
58 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
59 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] Sorry, this loader not supported 16 bit or less ...\n" ); |
1693 | 60 return 3; |
61 } | |
62 | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
63 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] filename: %s\n",fname ); |
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
64 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] size: %dx%d bits: %d\n",bF->Width,bF->Height,bF->BPP ); |
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
65 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] imagesize: %lu\n",bF->ImageSize ); |
1693 | 66 |
67 if ( ( bF->Image=malloc( bF->ImageSize ) ) == NULL ) | |
68 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
69 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] Not enough memory for image buffer.\n" ); |
1693 | 70 return 4; |
71 } | |
72 | |
73 if ( (i=fread( bF->Image,bF->ImageSize,1,BMP )) != 1 ) | |
74 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
75 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] Image read error.\n" ); |
1693 | 76 return 5; |
77 } | |
78 | |
79 fclose( BMP ); | |
80 | |
81 linesize=bF->Width * ( bF->BPP / 8 ); | |
82 if ( (line=malloc( linesize )) == NULL ) | |
83 { | |
4818
3473ca9ef158
new gui interface, and gtk moved into mplayer process. fork ... bleh :)
pontscho
parents:
2082
diff
changeset
|
84 mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[bmp] Not enough memory for flipping.\n" ); |
1693 | 85 return 6; |
86 } | |
87 | |
88 for ( i=0;i < bF->Height / 2;i++ ) | |
89 { | |
90 memcpy( line,&bF->Image[ i * linesize ],linesize ); | |
91 memcpy( &bF->Image[ i * linesize ],&bF->Image[ ( bF->Height - i - 1 ) * linesize ],linesize ); | |
92 memcpy( &bF->Image[ ( bF->Height - i - 1 ) * linesize ],line,linesize ); | |
93 } | |
94 free( line ); | |
95 | |
96 return 0; | |
97 } | |
98 | |
2082 | 99 #endif |
100 |