Skip to content

Commit dcdc968

Browse files
committed
Temporary push. Partial Bitmap handling added
1 parent 11633af commit dcdc968

File tree

5 files changed

+51
-10
lines changed

5 files changed

+51
-10
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
# build stuff
55
build/*
66
!build/.keep
7+
8+
# documentation
9+
doc/*

src/formats/bitmap/bitmap.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

src/formats/bitmap/bitmap.h

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
unsigned char detectBitmap(unsigned char *buffer, unsigned long bufferSize);
4+
unsigned long *getBitmqpOffsets(unsigned char *buffer, unsigned long bufferSize);

src/formats/formats.c

+7-9
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,25 @@
22
#include <stdlib.h>
33
#include <string.h>
44
#include "wav/wav.h"
5+
#include "bitmap/bitmap.h"
56

67
FORMAT getFormat(unsigned char *buffer, unsigned long bufferSize) {
78
if (detectWAV(buffer, bufferSize)) return WAV;
9+
if (detectBitmap(buffer, bufferSize)) return BITMAP;
810
return NULLFORMAT;
911
}
1012

1113
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;
1415

15-
unsigned long *tmpOffsets;
1616
switch (format) {
1717
case WAV:
18-
tmpOffsets = getWAVOffsets(buffer, bufferSize);
18+
offsets = getWAVOffsets(buffer, bufferSize);
19+
case BITMAP:
20+
offsets = getBitmapOffsets(buffer, bufferSize);
1921
}
2022

21-
if (!tmpOffsets) {
22-
return NULL;
23-
}
23+
if (!offsets) return NULL;
2424

25-
memcpy(offsets, tmpOffsets, 2 * sizeof(unsigned long));
26-
free(tmpOffsets);
2725
return offsets;
2826
}

src/formats/formats.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
typedef enum {
44
NULLFORMAT,
5-
WAV
5+
WAV,
6+
BITMAP
67
} FORMAT;
78

89
FORMAT getFormat(unsigned char *buffer, unsigned long bufferSize);

0 commit comments

Comments
 (0)