diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-05-29 22:11:33 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-05-30 08:56:19 -0300 |
commit | 5567e898d1052c1e2c2d32d3c37dfd957f4dc4bd (patch) | |
tree | e0df9b88b6c485f846dab9ae51369288f191cab8 /modules | |
parent | 0a6faeb4f5914061c29d946eaa29f2c50b8472fb (diff) |
Several fixes related to PBR and Environment
Diffstat (limited to 'modules')
-rw-r--r-- | modules/hdr/image_loader_hdr.cpp | 24 | ||||
-rw-r--r-- | modules/hdr/image_loader_hdr.h | 2 | ||||
-rw-r--r-- | modules/jpg/image_loader_jpegd.cpp | 2 | ||||
-rw-r--r-- | modules/jpg/image_loader_jpegd.h | 2 | ||||
-rw-r--r-- | modules/tinyexr/image_loader_tinyexr.cpp | 16 | ||||
-rw-r--r-- | modules/tinyexr/image_loader_tinyexr.h | 2 | ||||
-rw-r--r-- | modules/webp/image_loader_webp.cpp | 2 | ||||
-rw-r--r-- | modules/webp/image_loader_webp.h | 2 |
8 files changed, 35 insertions, 17 deletions
diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index 4c897e66af..85819104cf 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -34,17 +34,23 @@ #include "thirdparty/tinyexr/tinyexr.h" -Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f) { +Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { String header = f->get_token(); print_line("HEADER: " + header); - ERR_FAIL_COND_V(header != "#?RADIANCE", ERR_FILE_UNRECOGNIZED); - - String format = f->get_token(); - print_line("FORMAT: " + format); - - ERR_FAIL_COND_V(format != "FORMAT=32-bit_rle_rgbe", ERR_FILE_UNRECOGNIZED); + ERR_FAIL_COND_V(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED); + + while (true) { + String format = f->get_token(); + ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED); + if (format.begins_with("FORMAT=") && format != "FORMAT=32-bit_rle_rgbe") { + ERR_EXPLAIN("Only 32-bit_rle_rgbe is supported for .hdr files."); + return ERR_FILE_UNRECOGNIZED; + } + if (format == "FORMAT=32-bit_rle_rgbe") + break; + } String token = f->get_token(); @@ -132,6 +138,10 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f) { ptr[1] * exp / 255.0, ptr[2] * exp / 255.0); + if (p_force_linear) { + c = c.to_linear(); + } + *(uint32_t *)ptr = c.to_rgbe9995(); ptr += 4; } diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h index 93bb0fdc03..9bc1fadd13 100644 --- a/modules/hdr/image_loader_hdr.h +++ b/modules/hdr/image_loader_hdr.h @@ -38,7 +38,7 @@ class ImageLoaderHDR : public ImageFormatLoader { public: - virtual Error load_image(Ref<Image> p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderHDR(); }; diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index 0741dd198a..8c73b69f1b 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -89,7 +89,7 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p return OK; } -Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f) { +Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { PoolVector<uint8_t> src_image; int src_image_len = f->get_len(); diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index 57d7a2bb1c..aa073b493d 100644 --- a/modules/jpg/image_loader_jpegd.h +++ b/modules/jpg/image_loader_jpegd.h @@ -38,7 +38,7 @@ class ImageLoaderJPG : public ImageFormatLoader { public: - virtual Error load_image(Ref<Image> p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderJPG(); }; diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp index fbf5dea15e..4eb91da10b 100644 --- a/modules/tinyexr/image_loader_tinyexr.cpp +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -34,7 +34,7 @@ #include "thirdparty/tinyexr/tinyexr.h" -Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f) { +Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { PoolVector<uint8_t> src_image; int src_image_len = f->get_len(); @@ -133,9 +133,17 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f) { // Assume `out_rgba` have enough memory allocated. for (int i = 0; i < exr_image.width * exr_image.height; i++) { - *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxR][i]); - *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxG][i]); - *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxB][i]); + Color color( + reinterpret_cast<float **>(exr_image.images)[idxR][i], + reinterpret_cast<float **>(exr_image.images)[idxG][i], + reinterpret_cast<float **>(exr_image.images)[idxB][i]); + + if (p_force_linear) + color = color.to_linear(); + + *iw++ = Math::make_half_float(color.r); + *iw++ = Math::make_half_float(color.g); + *iw++ = Math::make_half_float(color.b); if (idxA > 0) { *iw++ = Math::make_half_float(reinterpret_cast<float **>(exr_image.images)[idxA][i]); diff --git a/modules/tinyexr/image_loader_tinyexr.h b/modules/tinyexr/image_loader_tinyexr.h index 328ac2a385..a52894b12b 100644 --- a/modules/tinyexr/image_loader_tinyexr.h +++ b/modules/tinyexr/image_loader_tinyexr.h @@ -38,7 +38,7 @@ class ImageLoaderTinyEXR : public ImageFormatLoader { public: - virtual Error load_image(Ref<Image> p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderTinyEXR(); }; diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 7313cb6c7c..87c2e811b3 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -115,7 +115,7 @@ static Ref<Image> _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) { return img; } -Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f) { +Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear) { uint32_t size = f->get_len(); PoolVector<uint8_t> src_image; diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h index ba817e0ecd..1ac2196a71 100644 --- a/modules/webp/image_loader_webp.h +++ b/modules/webp/image_loader_webp.h @@ -38,7 +38,7 @@ class ImageLoaderWEBP : public ImageFormatLoader { public: - virtual Error load_image(Ref<Image> p_image, FileAccess *f); + virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear); virtual void get_recognized_extensions(List<String> *p_extensions) const; ImageLoaderWEBP(); }; |