Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of edge cases are handled wrong #2

Merged
merged 3 commits into from
Nov 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/file-qoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++];
Expand Down Expand Up @@ -277,19 +278,18 @@ 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);
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) {
Expand Down Expand Up @@ -381,6 +381,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;
Expand Down