From 8815700322c0c10cb0528b047b2c7604c2eeb053 Mon Sep 17 00:00:00 2001 From: Dien-Nhung Nguyen-Phu Date: Sun, 9 Jun 2024 12:59:34 +0700 Subject: Add support for .xbm bitmap file .xbm is easy to include in C as source file. It could be viewed and edited directly without need to be converted between images and C array. --- src/res/bluetooth.xbm | 20 +++++++++++++++ src/res/foss-asia-1.xbm | 14 +++++++++++ src/res/foss-asia-2.xbm | 14 +++++++++++ src/res/fossasia.xbm | 14 +++++++++++ src/resource.c | 18 +++++++++++++ src/resource.h | 10 ++++++++ src/xbm.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ src/xbm.h | 18 +++++++++++++ 8 files changed, 175 insertions(+) create mode 100644 src/res/bluetooth.xbm create mode 100644 src/res/foss-asia-1.xbm create mode 100644 src/res/foss-asia-2.xbm create mode 100644 src/res/fossasia.xbm create mode 100644 src/resource.c create mode 100644 src/resource.h create mode 100644 src/xbm.c create mode 100644 src/xbm.h diff --git a/src/res/bluetooth.xbm b/src/res/bluetooth.xbm new file mode 100644 index 0000000..fa8ba8d --- /dev/null +++ b/src/res/bluetooth.xbm @@ -0,0 +1,20 @@ +#define bluetooth_width 24 +#define bluetooth_height 66 +static unsigned char bluetooth_bits[] = { + 0x04, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x14, 0x00, 0x00, 0x25, 0x00, 0x00, + 0x16, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x16, 0x00, 0x00, 0x25, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x14, 0x00, 0x00, 0x25, 0x00, 0x00, 0x16, 0x01, 0x00, + 0x0c, 0x02, 0x00, 0x16, 0x01, 0x00, 0x25, 0x00, 0x00, 0x14, 0x00, 0x00, + 0x0c, 0x00, 0x00, 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0c, 0x00, 0x00, + 0x14, 0x00, 0x00, 0x25, 0x08, 0x00, 0x16, 0x11, 0x00, 0x0c, 0x12, 0x00, + 0x16, 0x11, 0x00, 0x25, 0x08, 0x00, 0x14, 0x00, 0x00, 0x0c, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x04, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x14, 0x40, 0x00, + 0x25, 0x88, 0x00, 0x16, 0x11, 0x01, 0x0c, 0x12, 0x01, 0x16, 0x11, 0x01, + 0x25, 0x88, 0x00, 0x14, 0x40, 0x00, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x04, 0x00, 0x00, 0x0c, 0x00, 0x02, 0x14, 0x40, 0x04, 0x25, 0x88, 0x08, + 0x16, 0x11, 0x09, 0x0c, 0x12, 0x09, 0x16, 0x11, 0x09, 0x25, 0x88, 0x08, + 0x14, 0x40, 0x04, 0x0c, 0x00, 0x02, 0x04, 0x00, 0x00, 0x04, 0x00, 0x10, + 0x0c, 0x00, 0x22, 0x14, 0x40, 0x44, 0x25, 0x88, 0x88, 0x16, 0x11, 0x89, + 0x0c, 0x12, 0x89, 0x16, 0x11, 0x89, 0x25, 0x88, 0x88, 0x14, 0x40, 0x44, + 0x0c, 0x00, 0x22, 0x04, 0x00, 0x10 }; diff --git a/src/res/foss-asia-1.xbm b/src/res/foss-asia-1.xbm new file mode 100644 index 0000000..d769f19 --- /dev/null +++ b/src/res/foss-asia-1.xbm @@ -0,0 +1,14 @@ +#define foss_asia_1_width 44 +#define foss_asia_1_height 22 +static unsigned char foss_asia_1_bits[] = { + 0xf8, 0xf3, 0x1f, 0xff, 0xf9, 0x0f, 0xfc, 0xfb, 0xbf, 0xff, 0xfd, 0x0f, + 0x0c, 0x18, 0xb0, 0x01, 0x0c, 0x00, 0x0c, 0x18, 0xb0, 0x01, 0x0c, 0x00, + 0xff, 0x1b, 0xb0, 0xff, 0xfc, 0x07, 0xff, 0x1b, 0x30, 0xff, 0xf9, 0x0f, + 0x0c, 0x18, 0x30, 0x80, 0x01, 0x0c, 0x0c, 0x18, 0x30, 0x80, 0x01, 0x0c, + 0x0c, 0xf8, 0xbf, 0xff, 0xfd, 0x0f, 0x0c, 0xf0, 0x9f, 0xff, 0xfc, 0x07, + 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, + 0xff, 0x81, 0xff, 0x00, 0xfc, 0x07, 0xff, 0xc3, 0xff, 0x30, 0xfc, 0x0f, + 0x00, 0xc3, 0x00, 0x30, 0x00, 0x0c, 0x00, 0xc3, 0x00, 0x30, 0x00, 0x0c, + 0xfe, 0xc3, 0x7f, 0x30, 0xf8, 0x0f, 0xff, 0x83, 0xff, 0x30, 0xfc, 0x0f, + 0x03, 0x03, 0xc0, 0x30, 0x0c, 0x0c, 0x03, 0x03, 0xc0, 0x30, 0x0c, 0x0c, + 0xff, 0xc3, 0xff, 0x30, 0xfc, 0x0f, 0xfe, 0xc3, 0x7f, 0x30, 0xf8, 0x0f }; diff --git a/src/res/foss-asia-2.xbm b/src/res/foss-asia-2.xbm new file mode 100644 index 0000000..5a75f5d --- /dev/null +++ b/src/res/foss-asia-2.xbm @@ -0,0 +1,14 @@ +#define foss_asia_2_width 44 +#define foss_asia_2_height 22 +static unsigned char foss_asia_2_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xf9, 0x8f, 0xff, 0xfc, 0x07, + 0xfe, 0xfd, 0xdf, 0xff, 0xfe, 0x07, 0x06, 0x0c, 0xd8, 0x00, 0x06, 0x00, + 0xff, 0x0d, 0xd8, 0x7f, 0xfe, 0x03, 0xff, 0x0d, 0x98, 0xff, 0xfc, 0x07, + 0x06, 0x0c, 0x18, 0xc0, 0x00, 0x06, 0x06, 0xfc, 0xdf, 0xff, 0xfe, 0x07, + 0x06, 0xf8, 0xcf, 0x7f, 0xfe, 0x03, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x18, 0x00, 0x00, 0x06, 0x00, 0x00, 0x18, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x87, 0xff, 0x99, 0xff, 0x01, + 0xfe, 0xcf, 0xff, 0x99, 0xff, 0x03, 0x00, 0xcc, 0x00, 0x18, 0x00, 0x03, + 0xfc, 0xcf, 0xff, 0x18, 0xff, 0x03, 0xfe, 0x8f, 0xff, 0x99, 0xff, 0x03, + 0x06, 0x0c, 0x80, 0x99, 0x01, 0x03, 0xfe, 0xcf, 0xff, 0x99, 0xff, 0x03, + 0xfc, 0xcf, 0xff, 0x18, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; diff --git a/src/res/fossasia.xbm b/src/res/fossasia.xbm new file mode 100644 index 0000000..e6a5a00 --- /dev/null +++ b/src/res/fossasia.xbm @@ -0,0 +1,14 @@ +#define fossasia_width 44 +#define fossasia_height 22 +static unsigned char fossasia_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x9c, 0xc7, 0xf3, 0x1c, 0x2f, 0x07, 0x42, 0x28, 0x08, 0xa0, 0x20, 0x08, + 0x42, 0x28, 0x08, 0xa0, 0x20, 0x08, 0x5f, 0xc8, 0x71, 0x3c, 0x27, 0x0f, + 0x42, 0x08, 0x82, 0x22, 0xa8, 0x08, 0x42, 0x08, 0x82, 0x22, 0xa8, 0x08, + 0x82, 0xe7, 0x79, 0xbc, 0x27, 0x0f, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xdf, 0x0f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x63, 0x38, 0x0c, 0xe3, 0xd0, 0x08, + 0xbd, 0xd7, 0xf7, 0x5f, 0xdf, 0x07, 0xbd, 0xd7, 0xf7, 0x5f, 0xdf, 0x07, + 0xa0, 0x37, 0x8e, 0xc3, 0xd8, 0x00, 0xbd, 0xf7, 0x7d, 0xdd, 0x57, 0x07, + 0xbd, 0xf7, 0x7d, 0xdd, 0x57, 0x07, 0x7d, 0x18, 0x86, 0x43, 0xd8, 0x00, + 0xfd, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x0f }; diff --git a/src/resource.c b/src/resource.c new file mode 100644 index 0000000..ed4766b --- /dev/null +++ b/src/resource.c @@ -0,0 +1,18 @@ +#include "resource.h" + +#include "res/bluetooth.xbm" +#include "res/foss-asia-2.xbm" + +xbm_t bluetooth = { + .bits = bluetooth_bits, + .w = bluetooth_width, + .h = bluetooth_height, + .fh = 11 +}; + +xbm_t splash = { + .bits = foss_asia_2_bits, + .w = foss_asia_2_width, + .h = foss_asia_2_height, + .fh = 11 +}; \ No newline at end of file diff --git a/src/resource.h b/src/resource.h new file mode 100644 index 0000000..df91e37 --- /dev/null +++ b/src/resource.h @@ -0,0 +1,10 @@ +#ifndef __RES_H__ +#define __RES_H__ + +#include +#include "xbm.h" + +extern xbm_t bluetooth; +extern xbm_t splash; + +#endif /* __RES_H__ */ diff --git a/src/xbm.c b/src/xbm.c new file mode 100644 index 0000000..9c16811 --- /dev/null +++ b/src/xbm.c @@ -0,0 +1,67 @@ +#include "xbm.h" +#include +#include + +#define ALIGNBIT(x) (((x % 8)>0)*8 + (x / 8) * 8) + +/** + * Draw bitmap file to fb at (col, row) + * if bitmap file larger than fb, it will be stripped out + */ +void xbm2fb(xbm_t *xbm, uint16_t *fb, int col, int row) +{ + int W = ALIGNBIT(xbm->w); + uint16_t *tmpfb = malloc(W * sizeof(uint16_t)); + memset(tmpfb, 0, W * sizeof(uint16_t)); + + if ((xbm->h + row) >= 0 && col >= 0) { + + for (int h = 0; h < xbm->h; h++) { + for (int w = 0; w < W; w++) { + tmpfb[w] |= ((xbm->bits[h*(W/8) + w/8] >> (w % 8)) & 0x01) + << (h+row); + } + } + } + for (int i=0; i < xbm->w; i++) { + fb[col+i] = tmpfb[i]; + } +} + +void xbm2fb_dirty(xbm_t *xbm, uint16_t *fb, int col, int row) +{ + // Byte align for xbm bytes + int W = ALIGNBIT(xbm->w); + + for (int h = 0; h < xbm->h; h++) { + for (int w = 0; w < W; w++) { + fb[w] |= ((xbm->bits[h*(W/8) + w/8] >> (w % 8)) & 0x01) << (h+row); + } + } +} + +/** + * Crop image horizontaly + * TODO: vertical crop + * + */ +xbm_t *xbm_croph(xbm_t *xbm, xbm_t *frame, int from_row, int to_row) +{ + int rb = xbm->w / 8 + ((xbm->w % 8)>0); // Number of bytes in a row + if (to_row * rb > rb * xbm->h) + return NULL; + + frame->bits = &xbm->bits[rb * from_row]; + frame->w = xbm->w; + frame->h = to_row - from_row; + frame->fh = xbm->fh; + + return frame; +} + +xbm_t *extract_frame(xbm_t *xbm, xbm_t *frame, int frame_index) +{ + int from = frame_index * xbm->fh; + int to = from + xbm->fh; + return xbm_croph(xbm, frame, from, to); +} \ No newline at end of file diff --git a/src/xbm.h b/src/xbm.h new file mode 100644 index 0000000..b3f2c52 --- /dev/null +++ b/src/xbm.h @@ -0,0 +1,18 @@ +#ifndef __XBM_H__ +#define __XBM_H__ + +#include + +typedef struct { + uint8_t *bits; + int w; // Width + int h; // Height + int fh; // Frame height +} xbm_t; + +void xbm2fb(xbm_t *xbm, uint16_t *fb, int col, int row); +void xbm2fb_dirty(xbm_t *xbm, uint16_t *fb, int col, int row); +xbm_t *xbm_croph(xbm_t *xbm, xbm_t *frame, int from_row, int to_row); +xbm_t *extract_frame(xbm_t *xbm, xbm_t *frame, int frame_index); + +#endif /* __XBM_H__ */ -- cgit v1.2.3