Wording, whitespace

This commit is contained in:
Dominic Szablewski 2021-12-08 15:32:43 +01:00
parent 92f7ebd3f8
commit 6a73cc65c5

34
qoi.h
View File

@ -95,22 +95,21 @@ The decoder and encoder start with {r: 0, g: 0, b: 0, a: 255} as the previous
pixel value. Pixels are either encoded as pixel value. Pixels are either encoded as
- a run of the previous pixel - a run of the previous pixel
- an index into a previously seen pixel - an index into a previously seen pixel
- a difference to the previous pixel value in r,g,b,a - a difference to the previous pixel value in r,g,b
- full r,g,b,a values - full r,g,b or r,g,b,a values
A running array[64] of previously seen pixel values is maintained by the encoder A running array[64] of previously seen pixel values is maintained by the encoder
and decoder. Each pixel that is seen by the encoder and decoder is put into this and decoder. Each pixel that is seen by the encoder and decoder is put into this
array at the position (r * 3 + g * 5 + b * 7) % 64. In the encoder, if the pixel array at the position (r * 3 + g * 5 + b * 7 + a * 11) % 64. In the encoder, if
value at this index matches the current pixel, this index position is written to the pixel value at this index matches the current pixel, this index position is
the stream. written to the stream as QOI_OP_INDEX.
Each chunk starts with a 8 or 2 bit tag, followed by a number of data bits. Each chunk starts with a 2 or 8 bit tag, followed by a number of data bits. The
The bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. bit length of chunks is divisible by 8 - i.e. all chunks are byte aligned. All
All values encoded in these data bits have the most significant bit (MSB) on the values encoded in these data bits have the most significant bit on the left.
left.
The 8-bit tags have precedence over the 2-bit tags. A decoder must check the The 8-bit tags have precedence over the 2-bit tags. A decoder must check for the
8-bit tags first. presence of an 8-bit tag first.
The possible chunks are: The possible chunks are:
@ -216,15 +215,16 @@ within the stream.
extern "C" { extern "C" {
#endif #endif
// A pointer to qoi_desc struct has to be supplied to all of qoi's functions. It // A pointer to a qoi_desc struct has to be supplied to all of qoi's functions.
// describes either the input format (for qoi_write, qoi_encode), or is filled // It describes either the input format (for qoi_write and qoi_encode), or is
// with the description read from the file header (for qoi_read, qoi_decode). // 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 // The colorspace in this qoi_desc is an enum where
// 0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel // 0 = sRGB, i.e. gamma scaled RGB channels and a linear alpha channel
// 1 = all channels are linear // 1 = all channels are linear
// You may use the the constants QOI_SRGB or QOI_LINEAR. The colorspace is // You may use the constants QOI_SRGB or QOI_LINEAR. The colorspace is purely
// purely informative. It will be saved to the file header, but does not affect // informative. It will be saved to the file header, but does not affect
// en-/decoding in any way. // en-/decoding in any way.
#define QOI_SRGB 0 #define QOI_SRGB 0
@ -422,7 +422,7 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
vg > -3 && vg < 2 && vg > -3 && vg < 2 &&
vb > -3 && vb < 2 vb > -3 && vb < 2
) { ) {
bytes[p++] = QOI_OP_DIFF | ((vr + 2) << 4) | (vg + 2) << 2 | (vb + 2); bytes[p++] = QOI_OP_DIFF | (vr + 2) << 4 | (vg + 2) << 2 | (vb + 2);
} }
else if ( else if (
vg_r > -9 && vg_r < 8 && vg_r > -9 && vg_r < 8 &&