summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-06-16 10:22:26 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-06-16 10:22:26 -0300
commit703004f830f39adcde9b9565f1aa49d1b10e8d27 (patch)
treeb8fd669af9dee07177ff658f0ebca83aff836598 /core
parent64e83bfd1404ea593f0c79b478d196a3fcde42a8 (diff)
More 3D Work
-=-=-=-=-=- -ESM Shadow Mapping for softer and less glitchy shadows -HDR Pipeline (convert to Linear on texture import, convert to SRGB at the end) -Fix to xml parse bug
Diffstat (limited to 'core')
-rw-r--r--core/color.h11
-rw-r--r--core/image.cpp39
-rw-r--r--core/image.h1
3 files changed, 51 insertions, 0 deletions
diff --git a/core/color.h b/core/color.h
index 9b5850f56b..491c72d449 100644
--- a/core/color.h
+++ b/core/color.h
@@ -30,6 +30,7 @@
#define COLOR_H
#include "ustring.h"
+#include "math_funcs.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
@@ -97,6 +98,16 @@ struct Color {
return res;
}
+ _FORCE_INLINE_ Color to_linear() const {
+
+ return Color(
+ r<0.04045 ? r * (1.0 / 12.92) : Math::pow((r + 0.055) * (1.0 / (1 + 0.055)), 2.4),
+ g<0.04045 ? g * (1.0 / 12.92) : Math::pow((g + 0.055) * (1.0 / (1 + 0.055)), 2.4),
+ b<0.04045 ? b * (1.0 / 12.92) : Math::pow((b + 0.055) * (1.0 / (1 + 0.055)), 2.4),
+ a
+ );
+ }
+
static Color hex(uint32_t p_hex);
static Color html(const String& p_color);
static bool html_is_valid(const String& p_color);
diff --git a/core/image.cpp b/core/image.cpp
index b577117f1e..e5489c06fa 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1664,6 +1664,45 @@ void Image::set_compress_bc_func(void (*p_compress_func)(Image *)) {
+void Image::srgb_to_linear() {
+
+ if (data.size()==0)
+ return;
+
+ static const uint8_t srgb2lin[256]={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 24, 25, 26, 26, 27, 27, 28, 29, 29, 30, 31, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 38, 39, 40, 41, 42, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 87, 88, 89, 90, 92, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 148, 150, 152, 153, 155, 157, 159, 160, 162, 164, 166, 167, 169, 171, 173, 175, 176, 178, 180, 182, 184, 186, 188, 190, 192, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 218, 220, 222, 224, 226, 228, 230, 232, 235, 237, 239, 241, 243, 245, 248, 250, 252};
+
+
+ ERR_FAIL_COND( format!=FORMAT_RGB && format!=FORMAT_RGBA );
+
+ if (format==FORMAT_RGBA) {
+
+ int len = data.size()/4;
+ DVector<uint8_t>::Write wp = data.write();
+ unsigned char *data_ptr=wp.ptr();
+
+ for(int i=0;i<len;i++) {
+
+ data_ptr[(i<<2)+0]=srgb2lin[ data_ptr[(i<<2)+0] ];
+ data_ptr[(i<<2)+1]=srgb2lin[ data_ptr[(i<<2)+1] ];
+ data_ptr[(i<<2)+2]=srgb2lin[ data_ptr[(i<<2)+2] ];
+ }
+
+ } else if (format==FORMAT_RGB) {
+
+ int len = data.size()/3;
+ DVector<uint8_t>::Write wp = data.write();
+ unsigned char *data_ptr=wp.ptr();
+
+ for(int i=0;i<len;i++) {
+
+ data_ptr[(i*3)+0]=srgb2lin[ data_ptr[(i*3)+0] ];
+ data_ptr[(i*3)+1]=srgb2lin[ data_ptr[(i*3)+1] ];
+ data_ptr[(i*3)+2]=srgb2lin[ data_ptr[(i*3)+2] ];
+ }
+ }
+
+}
+
void Image::premultiply_alpha() {
if (data.size()==0)
diff --git a/core/image.h b/core/image.h
index 87f851959c..ce189f330d 100644
--- a/core/image.h
+++ b/core/image.h
@@ -321,6 +321,7 @@ public:
void fix_alpha_edges();
void premultiply_alpha();
+ void srgb_to_linear();
void blit_rect(const Image& p_src, const Rect2& p_src_rect,const Point2& p_dest);
void brush_transfer(const Image& p_src, const Image& p_brush, const Point2& p_dest);