From 130bf14ac83751b5107ab49224779a19437e8615 Mon Sep 17 00:00:00 2001 From: karroffel Date: Wed, 30 May 2018 21:14:07 +0200 Subject: [PATCH] added rgbe_to_srgb method to Image --- core/image.cpp | 32 ++++++++++++++++++++++++++++++++ core/image.h | 1 + 2 files changed, 33 insertions(+) diff --git a/core/image.cpp b/core/image.cpp index 51fbe75decd..c08b1ac39b4 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -2301,6 +2301,7 @@ void Image::_bind_methods() { ClassDB::bind_method(D_METHOD("premultiply_alpha"), &Image::premultiply_alpha); ClassDB::bind_method(D_METHOD("srgb_to_linear"), &Image::srgb_to_linear); ClassDB::bind_method(D_METHOD("normalmap_to_xy"), &Image::normalmap_to_xy); + ClassDB::bind_method(D_METHOD("rgbe_to_srgb"), &Image::rgbe_to_srgb); ClassDB::bind_method(D_METHOD("bumpmap_to_normalmap", "bump_scale"), &Image::bumpmap_to_normalmap, DEFVAL(1.0)); ClassDB::bind_method(D_METHOD("blit_rect", "src", "src_rect", "dst"), &Image::blit_rect); @@ -2412,6 +2413,37 @@ void Image::normalmap_to_xy() { convert(Image::FORMAT_LA8); } +Ref Image::rgbe_to_srgb() { + + if (data.size() == 0) + return Ref(); + + ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref()); + + Ref new_image; + new_image.instance(); + new_image->create(width, height, 0, Image::FORMAT_RGB8); + + lock(); + + new_image->lock(); + + for (int row = 0; row < height; row++) { + for (int col = 0; col < width; col++) { + new_image->set_pixel(col, row, get_pixel(col, row).to_srgb()); + } + } + + unlock(); + new_image->unlock(); + + if (has_mipmaps()) { + new_image->generate_mipmaps(); + } + + return new_image; +} + void Image::bumpmap_to_normalmap(float bump_scale) { ERR_FAIL_COND(!_can_modify(format)); convert(Image::FORMAT_RF); diff --git a/core/image.h b/core/image.h index 80a0c339dda..e38fa19dedf 100644 --- a/core/image.h +++ b/core/image.h @@ -284,6 +284,7 @@ public: void premultiply_alpha(); void srgb_to_linear(); void normalmap_to_xy(); + Ref rgbe_to_srgb(); void bumpmap_to_normalmap(float bump_scale = 1.0); void blit_rect(const Ref &p_src, const Rect2 &p_src_rect, const Point2 &p_dest);