neaten up the code for reading bitmap pixels :)

This commit is contained in:
XANTRONIX Development 2021-12-04 17:13:14 -05:00
parent ea96b298b3
commit 0fca3e3d43

View file

@ -104,22 +104,37 @@ static uint8_t rgb_to_2bpp(uint8_t r, uint8_t g, uint8_t b, size_t x, size_t y)
return (slot & (0x8000 >> ((y & 3) << 2) >> (x & 3)))? to: from; return (slot & (0x8000 >> ((y & 3) << 2) >> (x & 3)))? to: from;
} }
static inline uint8_t bitmap_read_channel(uint8_t *buf,
size_t x, size_t y, size_t stride,
int channels,
int channel) {
return buf[channels*stride*y + channels*x + channel];
}
static inline void bitmap_read(uint8_t *buf, static inline void bitmap_read(uint8_t *buf,
size_t x, size_t y, size_t stride, size_t x, size_t y, size_t stride,
uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *r, uint8_t *g, uint8_t *b,
int channels) { int channels) {
*r = buf[channels*stride*y + channels*x]; *r = bitmap_read_channel(buf, x, y, stride, channels, 0);
*g = buf[channels*stride*y + channels*x + 1]; *r = bitmap_read_channel(buf, x, y, stride, channels, 1);
*b = buf[channels*stride*y + channels*x + 2]; *r = bitmap_read_channel(buf, x, y, stride, channels, 2);
}
static inline void bitmap_write_channel(uint8_t *buf,
size_t x, size_t y, size_t stride,
int channels,
int channel,
uint8_t v) {
buf[channels*stride*y + channels*x + channel] = v;
} }
static inline void bitmap_write(uint8_t *buf, static inline void bitmap_write(uint8_t *buf,
size_t x, size_t y, size_t stride, size_t x, size_t y, size_t stride,
uint8_t r, uint8_t g, uint8_t b, int channels,
int channels) { uint8_t r, uint8_t g, uint8_t b) {
buf[channels*stride*y + channels*x] = r; bitmap_write_channel(buf, x, y, stride, channels, 0, r);
buf[channels*stride*y + channels*x + 1] = g; bitmap_write_channel(buf, x, y, stride, channels, 1, g);
buf[channels*stride*y + channels*x + 2] = b; bitmap_write_channel(buf, x, y, stride, channels, 2, b);
} }
static inline size_t size_2bpp_tile(size_t width, size_t height) { static inline size_t size_2bpp_tile(size_t width, size_t height) {
@ -547,7 +562,8 @@ static void bitmap_copy(cammy_image *dest,
to->x + x, to->x + x,
to->y + y, to->y + y,
dest->width, dest->width,
r, g, b, channels_dest); channels_dest,
r, g, b);
} }
} }
} }
@ -614,10 +630,10 @@ static void tile_copy_to_bitmap(cammy_image *dest,
x, x,
y, y,
from->width, from->width,
channels,
src->palette[c].r, src->palette[c].r,
src->palette[c].g, src->palette[c].g,
src->palette[c].b, src->palette[c].b);
channels);
} }
} }
} }