summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkarroffel <therzog@mail.de>2018-05-30 21:14:07 +0200
committerkarroffel <therzog@mail.de>2018-05-30 21:16:45 +0200
commit130bf14ac83751b5107ab49224779a19437e8615 (patch)
treecb61e0efd5209013e5367af4a49f997f14096aa5
parent28fa82c2defacca8ccad5c26022d2eeaee925f4f (diff)
added rgbe_to_srgb method to Image
-rw-r--r--core/image.cpp32
-rw-r--r--core/image.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/core/image.cpp b/core/image.cpp
index 51fbe75dec..c08b1ac39b 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> Image::rgbe_to_srgb() {
+
+ if (data.size() == 0)
+ return Ref<Image>();
+
+ ERR_FAIL_COND_V(format != FORMAT_RGBE9995, Ref<Image>());
+
+ Ref<Image> 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 80a0c339dd..e38fa19ded 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<Image> rgbe_to_srgb();
void bumpmap_to_normalmap(float bump_scale = 1.0);
void blit_rect(const Ref<Image> &p_src, const Rect2 &p_src_rect, const Point2 &p_dest);