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/hdr | |
parent | 0a6faeb4f5914061c29d946eaa29f2c50b8472fb (diff) |
Several fixes related to PBR and Environment
Diffstat (limited to 'modules/hdr')
-rw-r--r-- | modules/hdr/image_loader_hdr.cpp | 24 | ||||
-rw-r--r-- | modules/hdr/image_loader_hdr.h | 2 |
2 files changed, 18 insertions, 8 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(); }; |