Skip to content

Commit

Permalink
Finish up public put/get wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
NiLuJe committed May 4, 2024
1 parent be85096 commit 01539d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 35 deletions.
40 changes: 17 additions & 23 deletions fbink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1211,46 +1211,40 @@ static void
// Public convenience wrapper around put/get pixels.
// Performance is *not* a priority for these, avoid them if at all possible!
void
fbink_put_pixel_rgba(unsigned short int x, unsigned short int y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
fbink_put_pixel_gray(uint16_t x, uint16_t y, uint8_t v)
{
#ifdef FBINK_WITH_DRAW
const FBInkCoordinates coords = { .x = x, .y = y };
FBInkPixel px;
if (deviceQuirks.isRGB) {
px.rgba.color.r = r;
px.rgba.color.g = g;
px.rgba.color.b = b;
if (vInfo.bits_per_pixel == 32U) {
px.rgba.color.a = a;
} else {
px.rgba.color.a = 0xFFu;
}
} else {
px.bgra.color.r = r;
px.bgra.color.g = g;
px.bgra.color.b = b;
if (vInfo.bits_per_pixel == 32U) {
px.bgra.color.a = a;
} else {
px.bgra.color.a = 0xFFu;
}
}
FBInkPixel px = pack_pixel_from_y8(v);
put_pixel(coords, &px, true);
#else
WARN("Drawing primitives are disabled in this FBInk build");
return ERRCODE(ENOSYS);
#endif
}

put_pixel(coords, &px, false);
void
fbink_put_pixel_rgba(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
#ifdef FBINK_WITH_DRAW
const FBInkCoordinates coords = { .x = x, .y = y };
FBInkPixel px = pack_pixel_from_rgba(r, g, b, a);
put_pixel(coords, &px, true);
#else
WARN("Drawing primitives are disabled in this FBInk build");
return ERRCODE(ENOSYS);
#endif
}

void
fbink_get_pixel(unsigned short int x, unsigned short int y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
fbink_get_pixel(uint16_t x, uint16_t y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
{
#ifdef FBINK_WITH_DRAW
const FBInkCoordinates coords = { .x = x, .y = y };
FBInkPixel px;
get_pixel(coords, &px);

// Unpack the pixel for public consumption
if (deviceQuirks.pixelFormat == FBINK_PXFMT_Y4 || deviceQuirks.pixelFormat == FBINK_PXFMT_Y8) {
*r = px.gray8;
*g = px.gray8;
Expand Down
32 changes: 20 additions & 12 deletions fbink.h
Original file line number Diff line number Diff line change
Expand Up @@ -1505,19 +1505,27 @@ FBINK_API int fbink_fill_rect_rgba(int fbfd,
uint8_t b,
uint8_t a) __attribute__((nonnull(2)));

// Convenience public wrappers for a per-pixel put/get.
// These are designed with *convenience* in mind, *not* performance.
// I'd highly recommend handling drawing yourself if you can ;).
// Returns -(ENOSYS) when drawing primitives are disabled (MINIMAL build w/o DRAW).
FBINK_API void fbink_put_pixel_rgba(unsigned short int x,
unsigned short int y,
uint8_t r,
uint8_t g,
uint8_t b,
uint8_t a);
FBINK_API void fbink_get_pixel(unsigned short int x,
unsigned short int y,
uint8_t* r,
uint8_t* g,
uint8_t* b,
uint8_t* a);
// x: x coordinates
// y: y coordinates
// v: 8-bit luminance value
FBINK_API void fbink_put_pixel_gray(uint16_t x, uint16_t y, uint8_t v);
// r: 8-bit red component value
// g: 8-bit green component value
// b: 8-bit blue component value
// a: 8-bit alpha component value (opaque is 0xFFu).
FBINK_API void fbink_put_pixel_rgba(uint16_t x, uint16_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a);
// *r: out pointer, 8-bit red component value
// *g: out pointer, 8-bit green component value
// *b: out pointer, 8-bit blue component value
// *a: out pointer, 8-bit alpha component value (opaque is 0xFFu).
// NOTE: If pixelformat is grayscale, r = g = b and a = 0xFF
// NOTE: Red always means red, if there's a BGR swap involved, it's handled for you.
// Similarly, BGR565/RBG565 is unpacked to RGB32.
FBINK_API void fbink_get_pixel(uint16_t x, uint16_t y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a);

// Forcefully wakeup the EPDC (Kobo Mk.8+ only)
// We've found this to be helpful on a few otherwise crashy devices,
Expand Down

0 comments on commit 01539d6

Please sign in to comment.