home | blog | art | now | git gpg | email | rss

morph

Generate xresources colors from an image.
git clone https://pollux.codes/git/morph.git
Log | Files | Refs | README | LICENSE
commit bbef204c44bd91ff358d8fd72fd898e79f376b4a
parent 3d0a8d9cf57a0122030028a7681ee33e14ac74ed
Author: Pollux <pollux@pollux.codes>
Date:   Mon, 21 Jul 2025 20:35:15 -0500

feat: Shrink image before processing

Signed-off-by: Pollux <pollux@pollux.codes>

Diffstat:
Mmorph.c | 27++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/morph.c b/morph.c @@ -15,6 +15,9 @@ #define PRIMARY_COLOR_COUNT 32 #define PI 3.1415926535 +#define WORKING_IMG_WIDTH 500 +#define WORKING_IMG_HEIGHT 500 + #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) @@ -189,22 +192,29 @@ lab_to_rgb(col_lab_t lab) { col_rgb_t * get_image_pixel_data(const char *path, int *pixel_count) { - int image_width, image_height; + int source_width, source_height; col_rgb_t *image_pixels; DATA32 *image_data, c; - Imlib_Image image; + Imlib_Image source, image; - image = imlib_load_image(path); + source = imlib_load_image(path); - if(image == NULL) + if(source == NULL) return NULL; + imlib_context_set_image(source); + + source_width = imlib_image_get_width(); + source_height = imlib_image_get_height(); + + image = imlib_create_image(WORKING_IMG_WIDTH, WORKING_IMG_HEIGHT); imlib_context_set_image(image); - image_width = imlib_image_get_width(); - image_height = imlib_image_get_height(); + imlib_blend_image_onto_image(source, 0, 0, 0, source_width, + source_height, 0, 0, WORKING_IMG_WIDTH, + WORKING_IMG_HEIGHT); - *pixel_count = image_width * image_height; + *pixel_count = WORKING_IMG_WIDTH * WORKING_IMG_HEIGHT; image_pixels = malloc(*pixel_count * sizeof(col_rgb_t)); @@ -221,6 +231,9 @@ get_image_pixel_data(const char *path, int *pixel_count) { imlib_free_image(); + imlib_context_set_image(source); + imlib_free_image(); + return image_pixels; }