Mercurial > mplayer.hg
comparison Gui/bitmap/bmp/bmp.c @ 1693:d237c5d4b216
GUI version n-1
author | arpi |
---|---|
date | Sat, 25 Aug 2001 21:04:29 +0000 |
parents | |
children | f91ad6d23ce9 |
comparison
equal
deleted
inserted
replaced
1692:6c98e425c091 | 1693:d237c5d4b216 |
---|---|
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 | |
24 #include <stdlib.h> | |
25 #include <stdio.h> | |
26 | |
27 #include "bmp.h" | |
28 #include "../bitmap.h" | |
29 #include "../../error.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 { | |
42 #ifdef DEBUG | |
43 dbprintf( 4,"[bmp] File not found ( %s ).\n",fname ); | |
44 #endif | |
45 return 1; | |
46 } | |
47 if ( (i=fread( bmpHeader,54,1,BMP )) != 1 ) | |
48 { | |
49 #ifdef DEBUG | |
50 dbprintf( 4,"[bmp] Header read error ( %s ).\n",fname ); | |
51 #endif | |
52 return 2; | |
53 } | |
54 // memcpy( &bF->Size,&bmpHeader[2],4 ); | |
55 memcpy( &bF->Width,&bmpHeader[18],4 ); | |
56 memcpy( &bF->Height,&bmpHeader[22],4 ); | |
57 memcpy( &bF->BPP,&bmpHeader[28],2 ); | |
58 // memcpy( &bF->ImageSize,&bmpHeader[34],4 ); | |
59 bF->ImageSize=( bF->Width * bF->Height ) * ( bF->BPP / 8 ); | |
60 | |
61 if ( bF->BPP < 24 ) | |
62 { | |
63 #ifdef DEBUG | |
64 dbprintf( 4,"[bmp] Sorry, this loader not supported 16 bit or less ...\n" ); | |
65 #endif | |
66 return 3; | |
67 } | |
68 | |
69 #ifdef DEBUG | |
70 dbprintf( 4,"[bmp] filename: %s\n",fname ); | |
71 dbprintf( 4,"[bmp] size: %dx%d bits: %d\n",bF->Width,bF->Height,bF->BPP ); | |
72 dbprintf( 4,"[bmp] imagesize: %lu\n",bF->ImageSize ); | |
73 #endif | |
74 | |
75 if ( ( bF->Image=malloc( bF->ImageSize ) ) == NULL ) | |
76 { | |
77 #ifdef DEBUG | |
78 dbprintf( 4,"[bmp] Not enough memory for image buffer.\n" ); | |
79 #endif | |
80 return 4; | |
81 } | |
82 | |
83 if ( (i=fread( bF->Image,bF->ImageSize,1,BMP )) != 1 ) | |
84 { | |
85 #ifdef DEBUG | |
86 dbprintf( 4,"[bmp] Image read error.\n" ); | |
87 #endif | |
88 return 5; | |
89 } | |
90 | |
91 fclose( BMP ); | |
92 | |
93 linesize=bF->Width * ( bF->BPP / 8 ); | |
94 if ( (line=malloc( linesize )) == NULL ) | |
95 { | |
96 #ifdef DEBUG | |
97 dbprintf( 4,"[bmp] Not enough memory for flipping.\n" ); | |
98 #endif | |
99 return 6; | |
100 } | |
101 | |
102 for ( i=0;i < bF->Height / 2;i++ ) | |
103 { | |
104 memcpy( line,&bF->Image[ i * linesize ],linesize ); | |
105 memcpy( &bF->Image[ i * linesize ],&bF->Image[ ( bF->Height - i - 1 ) * linesize ],linesize ); | |
106 memcpy( &bF->Image[ ( bF->Height - i - 1 ) * linesize ],line,linesize ); | |
107 } | |
108 free( line ); | |
109 | |
110 return 0; | |
111 } | |
112 | |
113 #endif |