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

Resolve some warnings when MSVC warning level is 4 #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions qoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -415,22 +415,22 @@ 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;
}
}
else {
int index_pos;

if (run > 0) {
bytes[p++] = QOI_OP_RUN | (run - 1);
bytes[p++] = QOI_OP_RUN | (unsigned char)(run - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not declaring run as an unsigned char ?

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as run above

}
else {
index[index_pos] = px;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down