summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/image.cpp9
-rw-r--r--core/image.h1
-rw-r--r--modules/squish/image_compress_squish.cpp7
3 files changed, 14 insertions, 3 deletions
diff --git a/core/image.cpp b/core/image.cpp
index 172f5e517a..698a0b0b98 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -1766,6 +1766,15 @@ int Image::get_image_required_mipmaps(int p_width, int p_height, Format p_format
return mm;
}
+int Image::get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap) {
+
+ if (p_mipmap <= 0) {
+ return 0;
+ }
+ int mm;
+ return _get_dst_image_size(p_width, p_height, p_format, mm, p_mipmap - 1);
+}
+
bool Image::is_compressed() const {
return format > FORMAT_RGBE9995;
}
diff --git a/core/image.h b/core/image.h
index 11f9380c3c..0770eb953e 100644
--- a/core/image.h
+++ b/core/image.h
@@ -286,6 +286,7 @@ public:
static int get_image_data_size(int p_width, int p_height, Format p_format, bool p_mipmaps = false);
static int get_image_required_mipmaps(int p_width, int p_height, Format p_format);
+ static int get_image_mipmap_offset(int p_width, int p_height, Format p_format, int p_mipmap);
enum CompressMode {
COMPRESS_S3TC,
diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp
index 26cb76011c..a08ac7bd28 100644
--- a/modules/squish/image_compress_squish.cpp
+++ b/modules/squish/image_compress_squish.cpp
@@ -64,12 +64,13 @@ void image_decompress_squish(Image *p_image) {
return;
}
- int dst_ofs = 0;
-
for (int i = 0; i <= mm_count; i++) {
int src_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0;
p_image->get_mipmap_offset_size_and_dimensions(i, src_ofs, mipmap_size, mipmap_w, mipmap_h);
- squish::DecompressImage(&wb[dst_ofs], mipmap_w, mipmap_h, &rb[src_ofs], squish_flags);
+ int dst_ofs = Image::get_image_mipmap_offset(p_image->get_width(), p_image->get_height(), target_format, i);
+ squish::DecompressImage(&wb[dst_ofs], w, h, &rb[src_ofs], squish_flags);
+ w >>= 1;
+ h >>= 1;
}
p_image->create(p_image->get_width(), p_image->get_height(), p_image->has_mipmaps(), target_format, data);