Fuck yeah bud 8)
This commit is contained in:
parent
e93fc3aad8
commit
c3dbdc387a
1 changed files with 12 additions and 13 deletions
25
src/image.c
25
src/image.c
|
@ -108,8 +108,8 @@ static inline void buf_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 depth) {
|
int depth) {
|
||||||
*r = buf[depth*stride*y + depth*x],
|
*r = buf[depth*stride*y + depth*x];
|
||||||
*g = buf[depth*stride*y + depth*x + 1],
|
*g = buf[depth*stride*y + depth*x + 1];
|
||||||
*b = buf[depth*stride*y + depth*x + 2];
|
*b = buf[depth*stride*y + depth*x + 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,14 +274,14 @@ error_open:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cammy_image *load_png(const char *file) {
|
static cammy_image *load_stb(const char *file) {
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
cammy_image *image;
|
cammy_image *image;
|
||||||
cammy_image_format format = CAMMY_IMAGE_NONE;
|
cammy_image_format format = CAMMY_IMAGE_NONE;
|
||||||
|
|
||||||
int width, height, channels;
|
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;
|
goto error_stbi_load;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,12 +340,10 @@ cammy_image *cammy_image_open(const char *file) {
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
if (memcmp(buf, CAMMY_IMAGE_MAGIC_PNG, sizeof(buf)) == 0) {
|
if (memcmp(buf, CAMMY_IMAGE_MAGIC_TILE, sizeof(buf)) == 0) {
|
||||||
loader = load_png;
|
|
||||||
} else if (memcmp(buf, CAMMY_IMAGE_MAGIC_TILE, sizeof(buf)) == 0) {
|
|
||||||
loader = load_tile;
|
loader = load_tile;
|
||||||
} else {
|
} else {
|
||||||
goto error_invalid_format;
|
loader = load_stb;
|
||||||
}
|
}
|
||||||
|
|
||||||
return loader(file);
|
return loader(file);
|
||||||
|
@ -354,7 +352,6 @@ error_read:
|
||||||
error_lseek:
|
error_lseek:
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
error_invalid_format:
|
|
||||||
error_open:
|
error_open:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -523,7 +520,8 @@ static void copy_buf(cammy_image *dest,
|
||||||
cammy_image_region *from) {
|
cammy_image_region *from) {
|
||||||
size_t x, y;
|
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++) {
|
for (y=0; y < from->height; y++) {
|
||||||
if (to->y + y > dest->height) {
|
if (to->y + y > dest->height) {
|
||||||
|
@ -540,17 +538,18 @@ static void copy_buf(cammy_image *dest,
|
||||||
buf_read(src->buf,
|
buf_read(src->buf,
|
||||||
from->x + x,
|
from->x + x,
|
||||||
from->y + y,
|
from->y + y,
|
||||||
from->width,
|
src->width,
|
||||||
&r, &g, &b, channels);
|
&r, &g, &b, channels_src);
|
||||||
|
|
||||||
buf_write(dest->buf,
|
buf_write(dest->buf,
|
||||||
to->x + x,
|
to->x + x,
|
||||||
to->y + y,
|
to->y + y,
|
||||||
dest->width,
|
dest->width,
|
||||||
r, g, b, channels);
|
r, g, b, channels_dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy_rgb_to_2bpp_tile(cammy_image *dest,
|
static void copy_rgb_to_2bpp_tile(cammy_image *dest,
|
||||||
cammy_image *src,
|
cammy_image *src,
|
||||||
cammy_image_point *to,
|
cammy_image_point *to,
|
||||||
|
|
Loading…
Add table
Reference in a new issue