26 #include "simplegfx.h"
30 void drawBitmap(
screen_t *dev,
char *imgdir,
int x,
int y) {
33 FILE* fp = fopen(imgdir,
"r");
35 fread(imgdat, 1, 30, fp);
37 int img_width = imgdat[18] | (imgdat[19] << 8) | (imgdat[20] << 16) | (imgdat[21] << 24);
38 int img_height = imgdat[22] | (imgdat[23] << 8) | (imgdat[24] << 16) | (imgdat[25] << 24);
39 int img_color_depth = ((imgdat[28] | (imgdat[29] << 8)) >> 3);
40 if (img_color_depth < 2 || img_color_depth > 4)
return;
45 int img_offset = imgdat[10];
46 fseek(fp, img_offset - 30, SEEK_CUR);
56 for (
int k = img_height; k >= 0; k--) {
59 if (flip) y0 += img_height - 1 - k;
62 if (y0 >= 0 && y0 < getDisplayHeight(dev)) {
64 for(
int j = 0; j < img_width; j++) {
67 if (x0 >= 0 && x0 < getDisplayWidth(dev)) {
68 fread(imgdat, 1, img_color_depth, fp);
70 if (img_color_depth == 2) {
72 drawPixel(dev, x0, y0, (imgdat[1] << 8) | imgdat[0]);
74 drawPixel(dev, x0, y0, ((((imgdat[1] >> 5) + (imgdat[1] & 0b111) + ((imgdat[0] >> 2) & 0b111)) > 10) ? 1 : 0));
77 drawPixel(dev, x0, y0, ((imgdat[2] >> 3) << 11) | ((imgdat[1] >> 2) << 5) | (imgdat[0] >> 3));
79 drawPixel(dev, x0, y0, (((((
int) imgdat[2]) + ((
int) imgdat[1]) + ((
int) imgdat[0])) > 381) ? 1 : 0));
84 fseek(fp, img_color_depth, SEEK_CUR);
88 fseek(fp, img_color_depth * img_width, SEEK_CUR);