mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 11:35:38 -04:00
[librptexture] qoi.h: Swap R/B in qoi_encode() and qoi_decode().
This eliminates the need to call rp_image::swizzle() in QoiPrivate::loadImage(). qoi.h now expects images to be in the same ARGB32 format as the rest of rom-properties. NOTE: Only adjusting what's read from or written to bytes[], not the internal pixel buffers.
This commit is contained in:
parent
4badcf4bfb
commit
a138b123e3
@ -3,6 +3,10 @@
|
||||
Copyright (c) 2021, Dominic Szablewski - https://phoboslab.org
|
||||
SPDX-License-Identifier: MIT
|
||||
|
||||
NOTE: MODIFIED VERSION:
|
||||
- Some optimizations have been applied.
|
||||
- Decodes to rom-properties ARGB32 format, which has R/B swapped compared to Qoi's usual ABGR32.
|
||||
|
||||
|
||||
QOI - The "Quite OK Image" format for fast, lossless image compression
|
||||
|
||||
@ -355,6 +359,7 @@ static unsigned int qoi_read_32(const unsigned char *bytes, int *p) {
|
||||
unsigned char u8[4];
|
||||
memcpy(u8, &bytes[*p], 4);
|
||||
*p += 4;
|
||||
|
||||
return (unsigned int)u8[0] << 24 |
|
||||
(unsigned int)u8[1] << 16 |
|
||||
(unsigned int)u8[2] << 8 |
|
||||
@ -412,9 +417,10 @@ void *qoi_encode(const void *data, const qoi_desc *desc, int *out_len) {
|
||||
channels = desc->channels;
|
||||
|
||||
for (px_pos = 0; px_pos < px_len; px_pos += channels) {
|
||||
px.rgba.r = pixels[px_pos + 0];
|
||||
// rom-properties NOTE: Swapped R/B
|
||||
px.rgba.b = pixels[px_pos + 0];
|
||||
px.rgba.g = pixels[px_pos + 1];
|
||||
px.rgba.b = pixels[px_pos + 2];
|
||||
px.rgba.r = pixels[px_pos + 2];
|
||||
|
||||
if (channels == 4) {
|
||||
px.rgba.a = pixels[px_pos + 3];
|
||||
@ -585,9 +591,10 @@ void *qoi_decode(const void *data, int size, qoi_desc *desc, int channels) {
|
||||
index[QOI_COLOR_HASH(px) & (64 - 1)] = px;
|
||||
}
|
||||
|
||||
pixels[px_pos + 0] = px.rgba.r;
|
||||
// rom-properties NOTE: Swapped R/B
|
||||
pixels[px_pos + 0] = px.rgba.b;
|
||||
pixels[px_pos + 1] = px.rgba.g;
|
||||
pixels[px_pos + 2] = px.rgba.b;
|
||||
pixels[px_pos + 2] = px.rgba.r;
|
||||
|
||||
if (channels == 4) {
|
||||
pixels[px_pos + 3] = px.rgba.a;
|
||||
|
@ -163,13 +163,6 @@ rp_image_const_ptr QoiPrivate::loadImage(void)
|
||||
}
|
||||
free(pixels);
|
||||
|
||||
// NOTE: qoi.h has the R and B channels swapped compared to what rp_image expects.
|
||||
int ret = tmp_img->swizzle("bgra");
|
||||
if (ret != 0) {
|
||||
// Swizzle failed.
|
||||
return {};
|
||||
}
|
||||
|
||||
img.reset(tmp_img);
|
||||
return img;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user