summaryrefslogtreecommitdiff
path: root/core/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/image.cpp')
-rw-r--r--core/image.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/core/image.cpp b/core/image.cpp
index f547d7e973..99d5eab864 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1266,7 +1266,8 @@ void Image::shrink_x2() {
case FORMAT_RGBAH: _generate_po2_mipmap<uint16_t, 4, false, Image::average_4_half, Image::renormalize_half>(reinterpret_cast<const uint16_t *>(r.ptr()), reinterpret_cast<uint16_t *>(w.ptr()), width, height); break;
case FORMAT_RGBE9995: _generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(r.ptr()), reinterpret_cast<uint32_t *>(w.ptr()), width, height); break;
- default: {}
+ default: {
+ }
}
}
@@ -1398,7 +1399,8 @@ Error Image::generate_mipmaps(bool p_renormalize) {
_generate_po2_mipmap<uint32_t, 1, false, Image::average_4_rgbe9995, Image::renormalize_rgbe9995>(reinterpret_cast<const uint32_t *>(&wp[prev_ofs]), reinterpret_cast<uint32_t *>(&wp[ofs]), prev_w, prev_h);
break;
- default: {}
+ default: {
+ }
}
prev_ofs = ofs;
@@ -1612,7 +1614,8 @@ void Image::create(const char **p_xpm) {
if (y == (size_height - 1))
status = DONE;
} break;
- default: {}
+ default: {
+ }
}
line++;
@@ -1685,7 +1688,8 @@ bool Image::is_invisible() const {
case FORMAT_DXT5: {
detected = true;
} break;
- default: {}
+ default: {
+ }
}
return !detected;
@@ -1729,7 +1733,8 @@ Image::AlphaMode Image::detect_alpha() const {
case FORMAT_DXT5: {
detected = true;
} break;
- default: {}
+ default: {
+ }
}
if (detected)
@@ -1871,7 +1876,7 @@ Image::Image(int p_width, int p_height, bool p_mipmaps, Format p_format, const P
Rect2 Image::get_used_rect() const {
- if (format != FORMAT_LA8 && format != FORMAT_RGBA8)
+ if (format != FORMAT_LA8 && format != FORMAT_RGBA8 && format != FORMAT_RGBAF && format != FORMAT_RGBAH && format != FORMAT_RGBA4444 && format != FORMAT_RGBA5551)
return Rect2(Point2(), Size2(width, height));
int len = data.size();
@@ -1879,17 +1884,13 @@ Rect2 Image::get_used_rect() const {
if (len == 0)
return Rect2();
- //int data_size = len;
- PoolVector<uint8_t>::Read r = data.read();
- const unsigned char *rptr = r.ptr();
-
- int ps = format == FORMAT_LA8 ? 2 : 4;
+ const_cast<Image *>(this)->lock();
int minx = 0xFFFFFF, miny = 0xFFFFFFF;
int maxx = -1, maxy = -1;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
- bool opaque = rptr[(j * width + i) * ps + (ps - 1)] > 2;
+ bool opaque = get_pixel(i, j).a > 0.99;
if (!opaque)
continue;
if (i > maxx)
@@ -1903,6 +1904,8 @@ Rect2 Image::get_used_rect() const {
}
}
+ const_cast<Image *>(this)->unlock();
+
if (maxx == -1)
return Rect2();
else