Compare commits

...

4 Commits

Author SHA1 Message Date
璀境石 9084990600
Merge d5c624acc9 into d4fc9d1edf 2024-03-31 19:03:11 +01:00
Dominic Szablewski d4fc9d1edf
Merge pull request #299 from Kakadus/master
Support supplying additional LDFLAGS via environment
2024-03-24 19:43:09 +01:00
Jonas Dittrich e8e15ed132
apply 010-qoi-use-arch-flags.patch 2024-03-24 18:50:47 +01:00
Kuanlan d5c624acc9 Resolve some warnings when MSVC warning level is 4 2022-08-21 10:56:29 +08:00
2 changed files with 14 additions and 13 deletions

View File

@ -1,7 +1,8 @@
CC ?= gcc
CFLAGS_BENCH ?= -std=gnu99 -O3
LFLAGS_BENCH ?= -lpng
LFLAGS_BENCH ?= -lpng $(LDFLAGS)
CFLAGS_CONV ?= -std=c99 -O3
LFLAGS_CONV ?= $(LDFLAGS)
TARGET_BENCH ?= qoibench
TARGET_CONV ?= qoiconv
@ -14,7 +15,7 @@ $(TARGET_BENCH):$(TARGET_BENCH).c qoi.h
conv: $(TARGET_CONV)
$(TARGET_CONV):$(TARGET_CONV).c qoi.h
$(CC) $(CFLAGS_CONV) $(CFLAGS) $(TARGET_CONV).c -o $(TARGET_CONV)
$(CC) $(CFLAGS_CONV) $(CFLAGS) $(TARGET_CONV).c -o $(TARGET_CONV) $(LFLAGS_CONV)
.PHONY: clean
clean:

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);
@ -638,7 +638,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 = (bytes_read != size) ? NULL : qoi_decode(data, bytes_read, desc, channels);
QOI_FREE(data);