From 0112e3d5552019ac2eea0d1f24bb29e8db03e478 Mon Sep 17 00:00:00 2001 From: Dominic Szablewski Date: Tue, 14 Dec 2021 20:54:37 +0100 Subject: [PATCH] Whitespace, cosmetics --- qoi.h | 12 ++++++------ qoibench.c | 6 ++++-- qoiconv.c | 10 +++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/qoi.h b/qoi.h index 7cc40944..dee0d6ef 100644 --- a/qoi.h +++ b/qoi.h @@ -111,7 +111,7 @@ the color value. In the encoder, if the pixel value at the index matches the current pixel, this index position is written to the stream as QOI_OP_INDEX. The hash function for the index is: - index_position = (r * 3 + g * 5 + b * 7 + a * 11) % 64 + index_position = (r * 3 + g * 5 + b * 7 + a * 11) % 64 Each chunk starts with a 2- or 8-bit tag, followed by a number of data bits. The bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All @@ -242,8 +242,8 @@ filled with the description read from the file header (for qoi_read and qoi_decode). The colorspace in this qoi_desc is an enum where - 0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel - 1 = all channels are linear + 0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel + 1 = all channels are linear You may use the constants QOI_SRGB or QOI_LINEAR. The colorspace is purely informative. It will be saved to the file header, but does not affect en-/decoding in any way. */ @@ -325,7 +325,7 @@ Implementation */ #define QOI_FREE(p) free(p) #endif #ifndef QOI_ZEROARR - #define QOI_ZEROARR(_arr) memset((_arr),0,sizeof(_arr)) + #define QOI_ZEROARR(a) memset((a),0,sizeof(a)) #endif #define QOI_OP_INDEX 0x00 /* 00xxxxxx */ @@ -361,7 +361,7 @@ unsigned int qoi_read_32(const unsigned char *bytes, int *p) { unsigned int b = bytes[(*p)++]; unsigned int c = bytes[(*p)++]; unsigned int d = bytes[(*p)++]; - return (a << 24) | (b << 16) | (c << 8) | d; + return a << 24 | b << 16 | c << 8 | d; } void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) { @@ -430,7 +430,7 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) { run = 0; } } - else { + else { int index_pos; if (run > 0) { diff --git a/qoibench.c b/qoibench.c index 30868d44..27f1ec3a 100644 --- a/qoibench.c +++ b/qoibench.c @@ -152,7 +152,7 @@ void *libpng_encode(void *pixels, int w, int h, int channels, int *out_len) { info, w, h, 8, - (channels==3)?PNG_COLOR_TYPE_RGB:PNG_COLOR_TYPE_RGBA, + channels == 3 ? PNG_COLOR_TYPE_RGB : PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT @@ -417,7 +417,9 @@ benchmark_result_t benchmark_image(const char *path) { ERROR("Error decoding header %s", path); } - channels = (channels == 3) ? 3 : 4; + if (channels != 3) { + channels = 4; + } void *pixels = (void *)stbi_load(path, &w, &h, NULL, channels); void *encoded_png = fload(path, &encoded_png_size); diff --git a/qoiconv.c b/qoiconv.c index 1d112f63..f22513c4 100644 --- a/qoiconv.c +++ b/qoiconv.c @@ -62,13 +62,13 @@ int main(int argc, char **argv) { printf("Couldn't read header %s\n", argv[1]); exit(1); } - if(channels < 3) {// Force all odd encodings to be RGBA + + // Force all odd encodings to be RGBA + if(channels != 3) { channels = 4; - pixels = (void *)stbi_load(argv[1], &w, &h, NULL, 4); - } - else { - pixels = (void *)stbi_load(argv[1], &w, &h, &channels, 0); } + + pixels = (void *)stbi_load(argv[1], &w, &h, NULL, channels); } else if (STR_ENDS_WITH(argv[1], ".qoi")) { qoi_desc desc;