File tree 5 files changed +51
-10
lines changed
5 files changed +51
-10
lines changed Original file line number Diff line number Diff line change 4
4
# build stuff
5
5
build /*
6
6
! build /.keep
7
+
8
+ # documentation
9
+ doc /*
Original file line number Diff line number Diff line change
1
+ #include "bitmap.h"
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+
5
+ unsigned char detectBitmap (unsigned char * buffer , unsigned long bufferSize ) {
6
+ // TODO: Add Detection
7
+ return 0 ;
8
+ }
9
+
10
+ unsigned long * getBitmapOffsets (unsigned char * buffer , unsigned long bufferSize ) {
11
+ unsigned long * offsets = (unsigned long * )calloc (2 , sizeof (unsigned long ));
12
+ if (!offsets ) return NULL ;
13
+
14
+ // Extract pixel data start from header
15
+ memcpy (& offsets [0 ], buffer + 0x0A , 4 );
16
+
17
+ // Get end offset
18
+ // Get image width and height
19
+ unsigned long width = 0 , height = 0 ;
20
+ memcpy (& width , buffer + 0x12 , 4 );
21
+ if (width % 4 != 0 ) width += 4 - (width % 4 );
22
+ memcpy (& height , buffer + 0x16 , 4 );
23
+
24
+ unsigned long pixels = width * height ;
25
+
26
+ // Get bits per pixel
27
+ unsigned short bitsPerPixel = 0 ;
28
+ memcpy (& bitsPerPixel , buffer + 0x1C , 2 );
29
+
30
+ // Get end offset
31
+ unsigned long pixelDataBytes = pixels * (bitsPerPixel / 8 );
32
+ offsets [1 ] = offsets [0 ] + pixelDataBytes ;
33
+
34
+ return offsets ;
35
+ }
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ unsigned char detectBitmap (unsigned char * buffer , unsigned long bufferSize );
4
+ unsigned long * getBitmqpOffsets (unsigned char * buffer , unsigned long bufferSize );
Original file line number Diff line number Diff line change 2
2
#include <stdlib.h>
3
3
#include <string.h>
4
4
#include "wav/wav.h"
5
+ #include "bitmap/bitmap.h"
5
6
6
7
FORMAT getFormat (unsigned char * buffer , unsigned long bufferSize ) {
7
8
if (detectWAV (buffer , bufferSize )) return WAV ;
9
+ if (detectBitmap (buffer , bufferSize )) return BITMAP ;
8
10
return NULLFORMAT ;
9
11
}
10
12
11
13
unsigned long * getFormatOffsets (unsigned char * buffer , unsigned long bufferSize , FORMAT format ) {
12
- unsigned long * offsets = (unsigned long * )calloc (2 , sizeof (unsigned long ));
13
- if (!offsets ) return NULL ;
14
+ unsigned long * offsets = NULL ;
14
15
15
- unsigned long * tmpOffsets ;
16
16
switch (format ) {
17
17
case WAV :
18
- tmpOffsets = getWAVOffsets (buffer , bufferSize );
18
+ offsets = getWAVOffsets (buffer , bufferSize );
19
+ case BITMAP :
20
+ offsets = getBitmapOffsets (buffer , bufferSize );
19
21
}
20
22
21
- if (!tmpOffsets ) {
22
- return NULL ;
23
- }
23
+ if (!offsets ) return NULL ;
24
24
25
- memcpy (offsets , tmpOffsets , 2 * sizeof (unsigned long ));
26
- free (tmpOffsets );
27
25
return offsets ;
28
26
}
Original file line number Diff line number Diff line change 2
2
3
3
typedef enum {
4
4
NULLFORMAT ,
5
- WAV
5
+ WAV ,
6
+ BITMAP
6
7
} FORMAT ;
7
8
8
9
FORMAT getFormat (unsigned char * buffer , unsigned long bufferSize );
You can’t perform that action at this time.
0 commit comments