Fuck yeah bud 8)

This commit is contained in:
XANTRONIX Development 2021-12-01 13:04:48 -05:00
parent e93fc3aad8
commit c3dbdc387a

View file

@ -108,8 +108,8 @@ static inline void buf_read(uint8_t *buf,
size_t x, size_t y, size_t stride,
uint8_t *r, uint8_t *g, uint8_t *b,
int depth) {
*r = buf[depth*stride*y + depth*x],
*g = buf[depth*stride*y + depth*x + 1],
*r = buf[depth*stride*y + depth*x];
*g = buf[depth*stride*y + depth*x + 1];
*b = buf[depth*stride*y + depth*x + 2];
}
@ -274,14 +274,14 @@ error_open:
return NULL;
}
static cammy_image *load_png(const char *file) {
static cammy_image *load_stb(const char *file) {
uint8_t *buf;
cammy_image *image;
cammy_image_format format = CAMMY_IMAGE_NONE;
int width, height, channels;
if ((buf = stbi_load(file, &width, &height, &channels, 4)) == NULL) {
if ((buf = stbi_load(file, &width, &height, &channels, 0)) == NULL) {
goto error_stbi_load;
}
@ -340,12 +340,10 @@ cammy_image *cammy_image_open(const char *file) {
close(fd);
if (memcmp(buf, CAMMY_IMAGE_MAGIC_PNG, sizeof(buf)) == 0) {
loader = load_png;
} else if (memcmp(buf, CAMMY_IMAGE_MAGIC_TILE, sizeof(buf)) == 0) {
if (memcmp(buf, CAMMY_IMAGE_MAGIC_TILE, sizeof(buf)) == 0) {
loader = load_tile;
} else {
goto error_invalid_format;
loader = load_stb;
}
return loader(file);
@ -354,7 +352,6 @@ error_read:
error_lseek:
close(fd);
error_invalid_format:
error_open:
return NULL;
}
@ -523,7 +520,8 @@ static void copy_buf(cammy_image *dest,
cammy_image_region *from) {
size_t x, y;
int channels = format_channels(dest->format);
int channels_dest = format_channels(dest->format),
channels_src = format_channels(src->format);
for (y=0; y < from->height; y++) {
if (to->y + y > dest->height) {
@ -540,17 +538,18 @@ static void copy_buf(cammy_image *dest,
buf_read(src->buf,
from->x + x,
from->y + y,
from->width,
&r, &g, &b, channels);
src->width,
&r, &g, &b, channels_src);
buf_write(dest->buf,
to->x + x,
to->y + y,
dest->width,
r, g, b, channels);
r, g, b, channels_dest);
}
}
}
static void copy_rgb_to_2bpp_tile(cammy_image *dest,
cammy_image *src,
cammy_image_point *to,