From 6f2e16306a6552d704fb2346c9abdd26e0e523b7 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 6 Feb 2017 00:38:39 -0300 Subject: Several bugfixes, improving the import workflow --- modules/etc1/image_etc.cpp | 19 ++++++++++--------- modules/squish/image_compress_squish.cpp | 5 ++--- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp index 36ff1b86df..2d883bff0f 100644 --- a/modules/etc1/image_etc.cpp +++ b/modules/etc1/image_etc.cpp @@ -95,7 +95,7 @@ static void _decompress_etc(Image *p_img) { //print_line("Re Creating ETC into regular image: w "+itos(p_img->get_width())+" h "+itos(p_img->get_height())+" mm "+itos(p_img->get_mipmaps())); *p_img=Image(p_img->get_width(),p_img->get_height(),p_img->has_mipmaps(),Image::FORMAT_RGB8,dst); if (p_img->has_mipmaps()) - p_img->generate_mipmaps(true); + p_img->generate_mipmaps(); } @@ -112,16 +112,17 @@ static void _compress_etc(Image *p_img) { img.convert(Image::FORMAT_RGB8); - int mmc=img.get_mipmap_count(); - if (mmc==0) - img.generate_mipmaps(); // force mipmaps, so it works on most hardware - - PoolVector res_data; PoolVector dst_data; PoolVector::Read r = img.get_data().read(); + int target_size = Image::get_image_data_size(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC,p_img->has_mipmaps()?-1:0); + int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(p_img->get_width(),p_img->get_height(),Image::FORMAT_ETC) : 0; + + dst_data.resize(target_size); int mc=0; + int ofs=0; + PoolVector::Write w=dst_data.write(); rg_etc1::etc1_pack_params pp; @@ -133,9 +134,9 @@ static void _compress_etc(Image *p_img) { int bh=MAX(imgh/4,1); const uint8_t *src = &r[img.get_mipmap_offset(i)]; int mmsize = MAX(bw,1)*MAX(bh,1)*8; - dst_data.resize(dst_data.size()+mmsize); - PoolVector::Write w=dst_data.write(); - uint8_t *dst = &w[dst_data.size()-mmsize]; + + uint8_t *dst = &w[ofs]; + ofs+=mmsize; //print_line("bh: "+itos(bh)+" bw: "+itos(bw)); diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index a48c1f3485..28c200596b 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -64,10 +64,9 @@ void image_compress_squish(Image *p_image) { p_image->convert(Image::FORMAT_RGBA8); //always expects rgba - int mm_count = p_image->get_mipmap_count(); - PoolVector data; - int target_size = Image::get_image_data_size(w,h,target_format,mm_count); + int target_size = Image::get_image_data_size(w,h,target_format,p_image->has_mipmaps()?-1:0); + int mm_count = p_image->has_mipmaps() ? Image::get_image_required_mipmaps(w,h,target_format) : 0; data.resize(target_size); PoolVector::Read rb = p_image->get_data().read(); -- cgit v1.2.3