diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-02 12:23:49 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-12-02 12:23:49 +0100 |
commit | 801080a6ab0c51c2b2de25a417339570d4052358 (patch) | |
tree | 7d91c4b9c9867aa46e7e525663b7143cb5b018a1 | |
parent | bcc061edaeb8676b82dba0d857cfbf66638071b5 (diff) | |
parent | ebec23d8d807e2a785075aac12466b88f7cbd3c1 (diff) |
Merge pull request #69448 from BastiaanOlij/fix_etc_rgba_bgra_issue
ETCPAK expects BGRA data for ETC
-rw-r--r-- | core/io/image.cpp | 13 | ||||
-rw-r--r-- | core/io/image.h | 1 | ||||
-rw-r--r-- | modules/etcpak/image_compress_etcpak.cpp | 3 |
3 files changed, 17 insertions, 0 deletions
diff --git a/core/io/image.cpp b/core/io/image.cpp index 21146dd80c..1b9538794a 100644 --- a/core/io/image.cpp +++ b/core/io/image.cpp @@ -3798,6 +3798,19 @@ void Image::convert_ra_rgba8_to_rg() { } } +void Image::convert_rgba8_to_bgra8() { + ERR_FAIL_COND(format != FORMAT_RGBA8); + ERR_FAIL_COND(!data.size()); + + int s = data.size(); + uint8_t *w = data.ptrw(); + for (int i = 0; i < s; i += 4) { + uint8_t r = w[i]; + w[i] = w[i + 2]; // Swap R to B + w[i + 2] = r; // Swap B to R + } +} + Error Image::_load_from_buffer(const Vector<uint8_t> &p_array, ImageMemLoadFunc p_loader) { int buffer_size = p_array.size(); diff --git a/core/io/image.h b/core/io/image.h index 62df81e7c8..ad5c0b4a04 100644 --- a/core/io/image.h +++ b/core/io/image.h @@ -391,6 +391,7 @@ public: void convert_rg_to_ra_rgba8(); void convert_ra_rgba8_to_rg(); + void convert_rgba8_to_bgra8(); Image(const uint8_t *p_mem_png_jpg, int p_len = -1); Image(const char **p_xpm); diff --git a/modules/etcpak/image_compress_etcpak.cpp b/modules/etcpak/image_compress_etcpak.cpp index 3d66b27556..e467ed60ee 100644 --- a/modules/etcpak/image_compress_etcpak.cpp +++ b/modules/etcpak/image_compress_etcpak.cpp @@ -111,13 +111,16 @@ void _compress_etcpak(EtcpakType p_compresstype, Image *r_img, float p_lossy_qua Image::Format target_format = Image::FORMAT_RGBA8; if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC1) { target_format = Image::FORMAT_ETC; + r_img->convert_rgba8_to_bgra8(); // It's badly documented but ETCPAK seems to be expected BGRA8 for ETC. } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC2) { target_format = Image::FORMAT_ETC2_RGB8; + r_img->convert_rgba8_to_bgra8(); // It's badly documented but ETCPAK seems to be expected BGRA8 for ETC. } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC2_RA_AS_RG) { target_format = Image::FORMAT_ETC2_RA_AS_RG; r_img->convert_rg_to_ra_rgba8(); } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_ETC2_ALPHA) { target_format = Image::FORMAT_ETC2_RGBA8; + r_img->convert_rgba8_to_bgra8(); // It's badly documented but ETCPAK seems to be expected BGRA8 for ETC. } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_DXT1) { target_format = Image::FORMAT_DXT1; } else if (p_compresstype == EtcpakType::ETCPAK_TYPE_DXT5_RA_AS_RG) { |