From 7673f7e239c021deff151f9ea2d9c4ae47bca2d0 Mon Sep 17 00:00:00 2001 From: hkc Date: Thu, 3 Feb 2022 01:16:10 +0300 Subject: [PATCH] Nothing changed. Really. Dithering is still pretty much fvcked up on 256colors mode. Iunno why --- src/colors.c | 12 ++++++------ src/image.c | 16 ++++++++-------- src/mod_blocks.c | 1 - 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/colors.c b/src/colors.c index c88646e..0c44a59 100644 --- a/src/colors.c +++ b/src/colors.c @@ -91,17 +91,17 @@ int closest_color(palette_t pal, rgba8 color) int closest_256(palette_t pal, rgba8 color) { - (void)pal; (void)color; + (void)pal; if (color.r == color.g && color.g == color.b) { if (color.r < 8) return 16; if (color.r > 248) return 231; - return 232 + ceil((color.r - 8.0) / 247.0 * 24.0); + return 232 + (int)ceil((color.r - 8.0) / 247.0 * 24.0); } - uint8_t oc = 16; - oc += 36 * ceil(color.r / 255.0 * 5.0); - oc += 6 * ceil(color.g / 255.0 * 5.0); - oc += ceil(color.b / 255.0 * 5.0); + int oc = 16; + oc += 36 * (int)ceil(color.r / 255.0 * 5.0); + oc += 6 * (int)ceil(color.g / 255.0 * 5.0); + oc += (int)ceil(color.b / 255.0 * 5.0); return oc; } diff --git a/src/image.c b/src/image.c index e9b696d..450e6bd 100644 --- a/src/image.c +++ b/src/image.c @@ -32,15 +32,15 @@ image_t *image_resize(image_t *img, int width, int height) void __dither_update_pixel(image_t *img, int x, int y, int err[3], float bias) { if (x < 0 || x >= img->width || y < 0 || y >= img->height) return; - rgba8 pix = img->pixels[x + y * img->width]; + int i = x + y * img->width; + rgba8 pix = img->pixels[i]; int dst[3] = { pix.r, pix.g, pix.b }; - dst[0] += (int)((float)err[0] * bias); - dst[1] += (int)((float)err[1] * bias); - dst[2] += (int)((float)err[2] * bias); - pix.r = (dst[0] > 255 ? 255 : (dst[0] < 0 ? 0 : dst[0])); - pix.g = (dst[1] > 255 ? 255 : (dst[1] < 0 ? 0 : dst[1])); - pix.b = (dst[2] > 255 ? 255 : (dst[2] < 0 ? 0 : dst[2])); - memcpy(&img->pixels[x + y * img->width], &pix, sizeof(rgba8)); + dst[0] += (int)(((float)err[0]) * bias); + dst[1] += (int)(((float)err[1]) * bias); + dst[2] += (int)(((float)err[2]) * bias); + img->pixels[i].r = (dst[0] > 255 ? 255 : (dst[0] < 0 ? 0 : dst[0])); + img->pixels[i].g = (dst[1] > 255 ? 255 : (dst[1] < 0 ? 0 : dst[1])); + img->pixels[i].b = (dst[2] > 255 ? 255 : (dst[2] < 0 ? 0 : dst[2])); } diff --git a/src/mod_blocks.c b/src/mod_blocks.c index baa31fc..0181751 100644 --- a/src/mod_blocks.c +++ b/src/mod_blocks.c @@ -57,7 +57,6 @@ void mod_blocks_prepare(asc_state_t *state) case ASC_STL_TRUECOLOR: case ASC_STL_ENDL: break; - } if (res != NULL) {