From 525f32cefe58b853edae0b2818c3d85f3c3b9438 Mon Sep 17 00:00:00 2001 From: anon Date: Mon, 13 Dec 2021 16:34:39 +0000 Subject: [PATCH] Convert all non-RGB and non-RGBA input to RGBA. --- qoiconv.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/qoiconv.c b/qoiconv.c index 6e7ad36..1d112f6 100644 --- a/qoiconv.c +++ b/qoiconv.c @@ -58,7 +58,17 @@ int main(int argc, char **argv) { void *pixels = NULL; int w, h, channels; if (STR_ENDS_WITH(argv[1], ".png")) { - pixels = (void *)stbi_load(argv[1], &w, &h, &channels, 0); + if(!stbi_info(argv[1], &w, &h, &channels)) { + printf("Couldn't read header %s\n", argv[1]); + exit(1); + } + if(channels < 3) {// Force all odd encodings to be RGBA + channels = 4; + pixels = (void *)stbi_load(argv[1], &w, &h, NULL, 4); + } + else { + pixels = (void *)stbi_load(argv[1], &w, &h, &channels, 0); + } } else if (STR_ENDS_WITH(argv[1], ".qoi")) { qoi_desc desc;