From 9dd60534e44005aaf1b4d62626757d95f12a939b Mon Sep 17 00:00:00 2001 From: Dominic Szablewski Date: Sun, 28 Nov 2021 17:36:47 +0100 Subject: [PATCH] Use local var for channels to speed up encoding --- qoi.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qoi.h b/qoi.h index c4e13a6..d169d68 100644 --- a/qoi.h +++ b/qoi.h @@ -385,8 +385,10 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) { int px_len = desc->width * desc->height * desc->channels; int px_end = px_len - desc->channels; - for (int px_pos = 0; px_pos < px_len; px_pos += desc->channels) { - if (desc->channels == 4) { + int channels = desc->channels; + + for (int px_pos = 0; px_pos < px_len; px_pos += channels) { + if (channels == 4) { px = *(qoi_rgba_t *)(pixels + px_pos); } else {