Resolve some warnings when MSVC warning level is 4

This commit is contained in:
Kuanlan 2022-08-21 10:56:29 +08:00
parent 23c790ce59
commit d5c624acc9
1 changed files with 11 additions and 11 deletions

22
qoi.h
View File

@ -339,10 +339,10 @@ typedef union {
static const unsigned char qoi_padding[8] = {0,0,0,0,0,0,0,1};
static void qoi_write_32(unsigned char *bytes, int *p, unsigned int v) {
bytes[(*p)++] = (0xff000000 & v) >> 24;
bytes[(*p)++] = (0x00ff0000 & v) >> 16;
bytes[(*p)++] = (0x0000ff00 & v) >> 8;
bytes[(*p)++] = (0x000000ff & v);
bytes[(*p)++] = (v >> 24) & 0xff;
bytes[(*p)++] = (v >> 16) & 0xff;
bytes[(*p)++] = (v >> 8) & 0xff;
bytes[(*p)++] = (v >> 0) & 0xff;
}
static unsigned int qoi_read_32(const unsigned char *bytes, int *p) {
@ -415,7 +415,7 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
if (px.v == px_prev.v) {
run++;
if (run == 62 || px_pos == px_end) {
bytes[p++] = QOI_OP_RUN | (run - 1);
bytes[p++] = QOI_OP_RUN | (unsigned char)(run - 1);
run = 0;
}
}
@ -423,14 +423,14 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
int index_pos;
if (run > 0) {
bytes[p++] = QOI_OP_RUN | (run - 1);
bytes[p++] = QOI_OP_RUN | (unsigned char)(run - 1);
run = 0;
}
index_pos = QOI_COLOR_HASH(px) % 64;
if (index[index_pos].v == px.v) {
bytes[p++] = QOI_OP_INDEX | index_pos;
bytes[p++] = QOI_OP_INDEX | (unsigned char)index_pos;
}
else {
index[index_pos] = px;
@ -566,9 +566,9 @@ void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) {
else if ((b1 & QOI_MASK_2) == QOI_OP_LUMA) {
int b2 = bytes[p++];
int vg = (b1 & 0x3f) - 32;
px.rgba.r += vg - 8 + ((b2 >> 4) & 0x0f);
px.rgba.g += vg;
px.rgba.b += vg - 8 + (b2 & 0x0f);
px.rgba.r += (signed char)(vg - 8 + ((b2 >> 4) & 0x0f));
px.rgba.g += (signed char)(vg);
px.rgba.b += (signed char)(vg - 8 + (b2 & 0x0f));
}
else if ((b1 & QOI_MASK_2) == QOI_OP_RUN) {
run = (b1 & 0x3f);
@ -637,7 +637,7 @@ void *qoi_read(const char *filename, qoi_desc *desc, int channels) {
return NULL;
}
bytes_read = fread(data, 1, size, f);
bytes_read = (int)fread(data, 1, size, f);
fclose(f);
pixels = qoi_decode(data, bytes_read, desc, channels);