From 2ae9aba5e394156e7facedfabdd734fc293683da Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Sun, 19 Nov 2023 13:58:52 +0000 Subject: [PATCH 1/3] Fixed bug with immediate QOI_OP_RUNs --- src/file-qoi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/file-qoi.c b/src/file-qoi.c index 09c9fcd..25080eb 100644 --- a/src/file-qoi.c +++ b/src/file-qoi.c @@ -284,12 +284,11 @@ static bool load_image(const gchar *filename, QoiImage *result) { return false; } - // As this is a repeat of the previous pixel, there is no need to - // update the map of previously used pixels, it's already there. while (run-- != 0) { result->pixels[pixel_index++] = current_pixel; ++column_index; } + array[qoi_pixel_hash(current_pixel)] = current_pixel; } if (column_index >= result->width) { @@ -381,6 +380,7 @@ static bool save_image(QoiImage image, const gchar *filename) { run = 0; } } + array[hash] = current_pixel; } else if (qoi_pixel_equal(current_pixel, array[hash])) { file_data[file_index++] = QOI_OP_INDEX | hash; previous_pixel = current_pixel; From f777cd32fd2a9b3ccb4a0fda499c6e70b33c9c55 Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Sun, 19 Nov 2023 14:00:19 +0000 Subject: [PATCH 2/3] Fixed bug with checking end of file --- src/file-qoi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/file-qoi.c b/src/file-qoi.c index 25080eb..111695f 100644 --- a/src/file-qoi.c +++ b/src/file-qoi.c @@ -277,7 +277,7 @@ static bool load_image(const gchar *filename, QoiImage *result) { guint8 run = (tag & 0x3F) + 1; // Make sure there is enough space for all of the encoded pixels - if (pixel_index > max_pixel_index + run) { + if (pixel_index + run > max_pixel_index) { g_message("Too many encoded pixels."); g_free(result->pixels); g_free(file_data); From edb1923254881b691ac5b401f05ff40ba0d38029 Mon Sep 17 00:00:00 2001 From: Matthias Kaak Date: Sun, 19 Nov 2023 14:36:32 +0000 Subject: [PATCH 3/3] Added forgotten `column_index++;` --- src/file-qoi.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/file-qoi.c b/src/file-qoi.c index 111695f..697207d 100644 --- a/src/file-qoi.c +++ b/src/file-qoi.c @@ -222,6 +222,7 @@ static bool load_image(const gchar *filename, QoiImage *result) { result->pixels[pixel_index++] = current_pixel; array[qoi_pixel_hash(current_pixel)] = current_pixel; + ++column_index; } else if (tag == QOI_OP_RGBA) { current_pixel.red = file_data[file_index++]; current_pixel.green = file_data[file_index++];