bad drone >:(

This commit is contained in:
XANTRONIX Development 2021-12-05 13:30:27 -05:00
parent 026ce89685
commit 2104893b80

View file

@ -105,36 +105,48 @@ static uint8_t rgb_to_2bpp(uint8_t r, uint8_t g, uint8_t b, size_t x, size_t y)
} }
static inline uint8_t bitmap_read_channel(uint8_t *buf, static inline uint8_t bitmap_read_channel(uint8_t *buf,
size_t x, size_t y, size_t stride, size_t stride,
int channels, int channels,
int channel) { int channel,
size_t x,
size_t y) {
return buf[channels*stride*y + channels*x + 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 stride,
uint8_t *r, uint8_t *g, uint8_t *b, int channels,
int channels) { size_t x,
*r = bitmap_read_channel(buf, x, y, stride, channels, 0); size_t y,
*g = bitmap_read_channel(buf, x, y, stride, channels, 1); uint8_t *r,
*b = bitmap_read_channel(buf, x, y, stride, channels, 2); uint8_t *g,
uint8_t *b) {
*r = bitmap_read_channel(buf, stride, channels, 0, x, y);
*g = bitmap_read_channel(buf, stride, channels, 1, x, y);
*b = bitmap_read_channel(buf, stride, channels, 2, x, y);
} }
static inline void bitmap_write_channel(uint8_t *buf, static inline void bitmap_write_channel(uint8_t *buf,
size_t x, size_t y, size_t stride, size_t stride,
int channels, int channels,
int channel, int channel,
size_t x,
size_t y,
uint8_t v) { uint8_t v) {
buf[channels*stride*y + channels*x + channel] = 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 stride,
int channels, int channels,
uint8_t r, uint8_t g, uint8_t b) { size_t x,
bitmap_write_channel(buf, x, y, stride, channels, 0, r); size_t y,
bitmap_write_channel(buf, x, y, stride, channels, 1, g); uint8_t r,
bitmap_write_channel(buf, x, y, stride, channels, 2, b); uint8_t g,
uint8_t b) {
bitmap_write_channel(buf, stride, channels, 0, x, y, r);
bitmap_write_channel(buf, stride, channels, 1, x, y, g);
bitmap_write_channel(buf, stride, channels, 2, x, y, 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) {
@ -477,9 +489,9 @@ int cammy_image_save(cammy_image *image, const char *filename) {
} }
static inline uint8_t tile_read(cammy_tile *tiles, static inline uint8_t tile_read(cammy_tile *tiles,
size_t stride,
size_t x, size_t x,
size_t y, size_t y) {
int stride) {
cammy_tile *tile = CAMMY_TILE_INDEXED(tiles, x, y, stride); cammy_tile *tile = CAMMY_TILE_INDEXED(tiles, x, y, stride);
int tile_x = x & 7, int tile_x = x & 7,
@ -491,9 +503,9 @@ static inline uint8_t tile_read(cammy_tile *tiles,
} }
static inline void tile_write(cammy_tile *tiles, static inline void tile_write(cammy_tile *tiles,
size_t stride,
size_t x, size_t x,
size_t y, size_t y,
int stride,
uint8_t value) { uint8_t value) {
cammy_tile *tile = CAMMY_TILE_INDEXED(tiles, x, y, stride); cammy_tile *tile = CAMMY_TILE_INDEXED(tiles, x, y, stride);
@ -511,22 +523,36 @@ static void tile_copy(cammy_image *dest,
cammy_image *src, cammy_image *src,
cammy_image_point *to, cammy_image_point *to,
cammy_image_region *from) { cammy_image_region *from) {
size_t x, size_t x, y;
y;
for (y=from->y; y<from->y + from->height; y++) { for (y=0; y<from->height; y++) {
if (y > dest->height) { size_t y_src = y + from->y,
y_dest = y + to->y;
if (y_src >= src->height || y_dest >= dest->height) {
break; break;
} }
for (x=from->x; x<from->x + from->width; x++) { for (x=0; x<from->width; x++) {
uint8_t value = tile_read((cammy_tile *)src->buf, x, y, src->width); size_t x_src = x + from->x,
x_dest = x + to->x;
if (to->x + x > dest->width) { uint8_t v;
if (x_src >= src->width || x_dest >= dest->width) {
break; break;
} }
tile_write((cammy_tile *)dest->buf, x, y, dest->width, value); v = tile_read((cammy_tile *)src->buf,
src->width,
x_src,
y_src);
tile_write((cammy_tile *)dest->buf,
dest->width,
x_dest,
y_dest,
v);
} }
} }
} }
@ -540,29 +566,36 @@ static void bitmap_copy(cammy_image *dest,
int channels_dest = depth_channels(dest->depth), int channels_dest = depth_channels(dest->depth),
channels_src = depth_channels(src->depth); channels_src = depth_channels(src->depth);
for (y=from->y; y<from->y + from->height; y++) { for (y=0; y<from->height; y++) {
if (y > dest->height) { size_t y_src = y + from->y,
y_dest = y + to->y;
if (y_src >= src->height || y_dest >= dest->height) {
break; break;
} }
for (x=from->x; x<from->x + from->width; x++) { for (x=0; x<from->width; x++) {
size_t x_src = x + from->x,
x_dest = x + to->x;
uint8_t r, g, b; uint8_t r, g, b;
if (x > from->width) { if (x_src >= src->width || x_dest >= dest->width) {
break; break;
} }
bitmap_read(src->buf, bitmap_read(src->buf,
from->x + x,
from->y + y,
src->width, src->width,
&r, &g, &b, channels_src); channels_src,
x_src,
y_src,
&r, &g, &b);
bitmap_write(dest->buf, bitmap_write(dest->buf,
to->x + x,
to->y + y,
dest->width, dest->width,
channels_dest, channels_dest,
x_dest,
y_dest,
r, g, b); r, g, b);
} }
} }
@ -576,28 +609,35 @@ static void bitmap_copy_to_tile(cammy_image *dest,
int channels = depth_channels(src->depth); int channels = depth_channels(src->depth);
for (y=from->y; y<from->y + from->height; y++) { for (y=0; y<from->height; y++) {
if (y > dest->height) { size_t y_src = y + from->y,
y_dest = y + to->y;
if (y_src >= src->height || y_dest >= dest->height) {
break; break;
} }
for (x=from->x; x<from->x + from->width; x++) { for (x=from->x; x<from->x + from->width; x++) {
uint8_t r, g, b; uint8_t r, g, b;
if (x > from->width) { size_t x_src = x + from->x,
x_dest = x + to->x;
if (x_src >= src->width || x_dest >= dest->width) {
break; break;
} }
bitmap_read(src->buf, bitmap_read(src->buf,
from->x + x, src->width,
from->y + y, channels,
from->width, x_src,
&r, &g, &b, channels); y_src,
&r, &g, &b);
tile_write((cammy_tile *)dest->buf, tile_write((cammy_tile *)dest->buf,
to->x + x,
to->y + y,
dest->width, dest->width,
x_dest,
y_dest,
rgb_to_2bpp(r, g, b, to->x + x, rgb_to_2bpp(r, g, b, to->x + x,
to->y + y)); to->y + y));
} }
@ -612,28 +652,37 @@ static void tile_copy_to_bitmap(cammy_image *dest,
int channels = depth_channels(dest->depth); int channels = depth_channels(dest->depth);
for (y=from->y; y<from->y + from->height; y++) { for (y=0; y<from->height; y++) {
if (y > dest->height) { size_t y_src = y + from->y,
y_dest = y + to->y;
if (y_src >= src->height || y_dest >= dest->height) {
break; break;
} }
for (x=from->x; x<from->x + from->width; x++) { for (x=0; x<from->width; x++) {
uint8_t c; size_t x_src = x + from->x,
x_dest = x + to->x;
if (x > from->width) { uint8_t v;
if (x_src >= src->width || x_dest >= dest->width) {
break; break;
} }
c = tile_read((cammy_tile *)src->buf, x, y, from->width); v = tile_read((cammy_tile *)src->buf,
from->width,
x_src,
y_src);
bitmap_write(dest->buf, bitmap_write(dest->buf,
x,
y,
from->width, from->width,
channels, channels,
src->palette[c].r, x_dest,
src->palette[c].g, y_dest,
src->palette[c].b); src->palette[v].r,
src->palette[v].g,
src->palette[v].b);
} }
} }
} }
@ -690,22 +739,45 @@ static void bitmap_copy_channel(cammy_image *dest,
int channels_dest = depth_channels(dest->depth), int channels_dest = depth_channels(dest->depth),
channels_src = depth_channels(src->depth); channels_src = depth_channels(src->depth);
for (y=from->y; y<from->y + from->height; y++) { for (y=0; y<from->height; y++) {
if (y >= dest->height) { size_t y_src = y + from->y,
y_dest = y + to->y;
if (y_src >= src->height || y_dest >= dest->height) {
break; break;
} }
for (x=0; x<from->x + from->width; x++) { for (x=0; x<from->width; x++) {
size_t x_src = x + from->x,
x_dest = x + to->x;
uint8_t v; uint8_t v;
if (x >= dest->width) { if (x_src >= src->width || x_dest >= dest->width) {
break; break;
} }
v = bitmap_read_channel(src->buf, x, y, src->width, channels_src, channel); v = bitmap_read_channel(src->buf,
src->width,
channels_src,
channel,
x_src,
y_src);
bitmap_write(dest->buf, x, y, from->width, channels_dest, 0, 0, 0); bitmap_write(dest->buf,
bitmap_write_channel(dest->buf, x, y, from->width, channels_dest, channel, v); dest->width,
channels_dest,
x_dest,
y_dest,
0, 0, 0);
bitmap_write_channel(dest->buf,
dest->width,
channels_dest,
channel,
x_dest,
y_dest,
v);
} }
} }
} }