diff options
author | Juan Linietsky <reduzio@gmail.com> | 2015-06-06 10:12:09 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2015-06-06 10:12:09 -0300 |
commit | 697482328863b2790597df1efde0c3a0b4a9772e (patch) | |
tree | 64c1a03bfc9cdf8471cd8ae21c8be97b80d8709e /core | |
parent | 9acab32daaea38e09c4d74d5f0340479d3dd41bd (diff) | |
parent | 8dde67cf706ae6e6a33eefdf69aa6922fac0e909 (diff) |
Merge remote-tracking branch 'origin/master'
Conflicts:
tools/editor/io_plugins/editor_texture_import_plugin.cpp
Diffstat (limited to 'core')
-rw-r--r-- | core/image.cpp | 77 | ||||
-rw-r--r-- | core/image.h | 1 |
2 files changed, 78 insertions, 0 deletions
diff --git a/core/image.cpp b/core/image.cpp index b516790494..037018519e 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1124,6 +1124,7 @@ void Image::create( const char ** p_xpm ) { } #define DETECT_ALPHA_MAX_TRESHOLD 254 #define DETECT_ALPHA_MIN_TRESHOLD 2 + #define DETECT_ALPHA( m_value )\ { \ uint8_t value=m_value;\ @@ -1136,6 +1137,82 @@ void Image::create( const char ** p_xpm ) { }\ } +#define DETECT_NON_ALPHA( m_value )\ +{ \ + uint8_t value=m_value;\ + if (value>0) {\ + \ + detected=true;\ + break;\ + }\ +} + + +bool Image::is_invisible() const { + + if (format==FORMAT_GRAYSCALE || + format==FORMAT_RGB || + format==FORMAT_INDEXED) + return false; + + int len = data.size(); + + if (len==0) + return true; + + if (format >= FORMAT_YUV_422 && format <= FORMAT_YUV_444) + return false; + + int w,h; + _get_mipmap_offset_and_size(1,len,w,h); + + DVector<uint8_t>::Read r = data.read(); + const unsigned char *data_ptr=r.ptr(); + + bool detected=false; + + switch(format) { + case FORMAT_INTENSITY: { + + for(int i=0;i<len;i++) { + DETECT_NON_ALPHA(data_ptr[i]); + } + } break; + case FORMAT_GRAYSCALE_ALPHA: { + + + for(int i=0;i<(len>>1);i++) { + DETECT_NON_ALPHA(data_ptr[(i<<1)+1]); + } + + } break; + case FORMAT_RGBA: { + + for(int i=0;i<(len>>2);i++) { + DETECT_NON_ALPHA(data_ptr[(i<<2)+3]) + } + + } break; + case FORMAT_INDEXED: { + + return false; + } break; + case FORMAT_INDEXED_ALPHA: { + + return false; + } break; + case FORMAT_PVRTC2_ALPHA: + case FORMAT_PVRTC4_ALPHA: + case FORMAT_BC2: + case FORMAT_BC3: { + detected=true; + } break; + default: {} + } + + return !detected; +} + Image::AlphaMode Image::detect_alpha() const { if (format==FORMAT_GRAYSCALE || diff --git a/core/image.h b/core/image.h index a9eb8fd769..8ce4f22dc1 100644 --- a/core/image.h +++ b/core/image.h @@ -305,6 +305,7 @@ public: }; AlphaMode detect_alpha() const; + bool is_invisible() const; void put_indexed_pixel(int p_x, int p_y, uint8_t p_idx,int p_mipmap=0); uint8_t get_indexed_pixel(int p_x, int p_y,int p_mipmap=0) const; |