From 6995a4cc46cd0b058245061eb48aacf56577aaa0 Mon Sep 17 00:00:00 2001
From: Ivan Avdeev <me@provod.works>
Date: Thu, 6 Feb 2025 13:55:58 -0500
Subject: [PATCH] force RGB components for all images in imagecompare

Imagemagick produces 1-bit grayscale pngs for fully black pictures. This
makes imagecompare unhappy. Enforce the 3-component RGB type for
consistency.
---
 render/imagecompare.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/render/imagecompare.c b/render/imagecompare.c
index c1635c7..8a8fcee 100644
--- a/render/imagecompare.c
+++ b/render/imagecompare.c
@@ -24,7 +24,9 @@ typedef struct {
 } image_t;
 
 static int imageLoad(image_t* img, const char *f) {
-	img->data = stbi_load(f, &img->w, &img->h, &img->comp, 0);
+	const int components = 3; // enforce RGB, as magick/png will save empty images as 1-bit grayscale
+	img->data = stbi_load(f, &img->w, &img->h, &img->comp, components);
+	img->comp = components;
 	if (!img->data)
 		fprintf(stderr, "Unable to load image \"%s\"\n", f);
 	return !!(img->data);