aboutsummaryrefslogtreecommitdiff
path: root/modules/etc1
diff options
context:
space:
mode:
Diffstat (limited to 'modules/etc1')
-rw-r--r--modules/etc1/image_etc.cpp153
-rw-r--r--modules/etc1/image_etc.h1
-rw-r--r--modules/etc1/register_types.cpp2
-rw-r--r--modules/etc1/texture_loader_pkm.cpp46
-rw-r--r--modules/etc1/texture_loader_pkm.h9
5 files changed, 94 insertions, 117 deletions
diff --git a/modules/etc1/image_etc.cpp b/modules/etc1/image_etc.cpp
index 2d883bff0..642ec027f 100644
--- a/modules/etc1/image_etc.cpp
+++ b/modules/etc1/image_etc.cpp
@@ -28,175 +28,154 @@
/*************************************************************************/
#include "image_etc.h"
#include "image.h"
-#include "rg_etc1.h"
-#include "print_string.h"
#include "os/copymem.h"
+#include "print_string.h"
+#include "rg_etc1.h"
static void _decompress_etc(Image *p_img) {
- ERR_FAIL_COND(p_img->get_format()!=Image::FORMAT_ETC);
+ ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_ETC);
int imgw = p_img->get_width();
int imgh = p_img->get_height();
- PoolVector<uint8_t> src=p_img->get_data();
+ PoolVector<uint8_t> src = p_img->get_data();
PoolVector<uint8_t> dst;
PoolVector<uint8_t>::Read r = src.read();
- int mmc=p_img->get_mipmap_count();
+ int mmc = p_img->get_mipmap_count();
+ for (int i = 0; i <= mmc; i++) {
- for(int i=0;i<=mmc;i++) {
-
- dst.resize(dst.size()+imgw*imgh*3);
- const uint8_t *srcbr=&r[p_img->get_mipmap_offset(i)];
+ dst.resize(dst.size() + imgw * imgh * 3);
+ const uint8_t *srcbr = &r[p_img->get_mipmap_offset(i)];
PoolVector<uint8_t>::Write w = dst.write();
- uint8_t *wptr = &w[dst.size()-imgw*imgh*3];
-
- int bw=MAX(imgw/4,1);
- int bh=MAX(imgh/4,1);
-
- for(int y=0;y<bh;y++) {
+ uint8_t *wptr = &w[dst.size() - imgw * imgh * 3];
- for(int x=0;x<bw;x++) {
+ int bw = MAX(imgw / 4, 1);
+ int bh = MAX(imgh / 4, 1);
- uint8_t block[4*4*4];
+ for (int y = 0; y < bh; y++) {
+ for (int x = 0; x < bw; x++) {
- rg_etc1::unpack_etc1_block(srcbr,(unsigned int*)block);
- srcbr+=8;
+ uint8_t block[4 * 4 * 4];
- int maxx=MIN(imgw,4);
- int maxy=MIN(imgh,4);
+ rg_etc1::unpack_etc1_block(srcbr, (unsigned int *)block);
+ srcbr += 8;
- for(int yy=0;yy<maxy;yy++) {
+ int maxx = MIN(imgw, 4);
+ int maxy = MIN(imgh, 4);
- for(int xx=0;xx<maxx;xx++) {
+ for (int yy = 0; yy < maxy; yy++) {
- uint32_t src_ofs = (yy*4+xx)*4;
- uint32_t dst_ofs = ((y*4+yy)*imgw+x*4+xx)*3;
- wptr[dst_ofs+0]=block[src_ofs+0];
- wptr[dst_ofs+1]=block[src_ofs+1];
- wptr[dst_ofs+2]=block[src_ofs+2];
+ for (int xx = 0; xx < maxx; xx++) {
+ uint32_t src_ofs = (yy * 4 + xx) * 4;
+ uint32_t dst_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3;
+ wptr[dst_ofs + 0] = block[src_ofs + 0];
+ wptr[dst_ofs + 1] = block[src_ofs + 1];
+ wptr[dst_ofs + 2] = block[src_ofs + 2];
}
}
-
}
-
}
- imgw=MAX(1,imgw/2);
- imgh=MAX(1,imgh/2);
+ imgw = MAX(1, imgw / 2);
+ imgh = MAX(1, imgh / 2);
}
-
- r=PoolVector<uint8_t>::Read();
+ r = PoolVector<uint8_t>::Read();
//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);
+ *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();
-
-
}
static void _compress_etc(Image *p_img) {
Image img = *p_img;
- int imgw=img.get_width(),imgh=img.get_height();
+ int imgw = img.get_width(), imgh = img.get_height();
- ERR_FAIL_COND( nearest_power_of_2(imgw)!=imgw || nearest_power_of_2(imgh)!=imgh );
+ ERR_FAIL_COND(nearest_power_of_2(imgw) != imgw || nearest_power_of_2(imgh) != imgh);
- if (img.get_format()!=Image::FORMAT_RGB8)
+ if (img.get_format() != Image::FORMAT_RGB8)
img.convert(Image::FORMAT_RGB8);
-
PoolVector<uint8_t> res_data;
PoolVector<uint8_t> dst_data;
PoolVector<uint8_t>::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;
+ 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<uint8_t>::Write w=dst_data.write();
-
+ int mc = 0;
+ int ofs = 0;
+ PoolVector<uint8_t>::Write w = dst_data.write();
rg_etc1::etc1_pack_params pp;
- pp.m_quality=rg_etc1::cLowQuality;
- for(int i=0;i<=mmc;i++) {
-
+ pp.m_quality = rg_etc1::cLowQuality;
+ for (int i = 0; i <= mmc; i++) {
- int bw=MAX(imgw/4,1);
- int bh=MAX(imgh/4,1);
+ int bw = MAX(imgw / 4, 1);
+ 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;
+ int mmsize = MAX(bw, 1) * MAX(bh, 1) * 8;
uint8_t *dst = &w[ofs];
- ofs+=mmsize;
-
+ ofs += mmsize;
//print_line("bh: "+itos(bh)+" bw: "+itos(bw));
- for(int y=0;y<bh;y++) {
+ for (int y = 0; y < bh; y++) {
- for(int x=0;x<bw;x++) {
+ for (int x = 0; x < bw; x++) {
//print_line("x: "+itos(x)+" y: "+itos(y));
- uint8_t block[4*4*4];
- zeromem(block,4*4*4);
+ uint8_t block[4 * 4 * 4];
+ zeromem(block, 4 * 4 * 4);
uint8_t cblock[8];
- int maxy = MIN(imgh,4);
- int maxx = MIN(imgw,4);
-
-
- for(int yy=0;yy<maxy;yy++) {
-
- for(int xx=0;xx<maxx;xx++) {
+ int maxy = MIN(imgh, 4);
+ int maxx = MIN(imgw, 4);
+ for (int yy = 0; yy < maxy; yy++) {
- uint32_t dst_ofs = (yy*4+xx)*4;
- uint32_t src_ofs = ((y*4+yy)*imgw+x*4+xx)*3;
- block[dst_ofs+0]=src[src_ofs+0];
- block[dst_ofs+1]=src[src_ofs+1];
- block[dst_ofs+2]=src[src_ofs+2];
- block[dst_ofs+3]=255;
+ for (int xx = 0; xx < maxx; xx++) {
+ uint32_t dst_ofs = (yy * 4 + xx) * 4;
+ uint32_t src_ofs = ((y * 4 + yy) * imgw + x * 4 + xx) * 3;
+ block[dst_ofs + 0] = src[src_ofs + 0];
+ block[dst_ofs + 1] = src[src_ofs + 1];
+ block[dst_ofs + 2] = src[src_ofs + 2];
+ block[dst_ofs + 3] = 255;
}
}
- rg_etc1::pack_etc1_block(cblock, (const unsigned int*)block, pp);
- for(int j=0;j<8;j++) {
+ rg_etc1::pack_etc1_block(cblock, (const unsigned int *)block, pp);
+ for (int j = 0; j < 8; j++) {
- dst[j]=cblock[j];
+ dst[j] = cblock[j];
}
- dst+=8;
+ dst += 8;
}
-
}
- imgw=MAX(1,imgw/2);
- imgh=MAX(1,imgh/2);
+ imgw = MAX(1, imgw / 2);
+ imgh = MAX(1, imgh / 2);
mc++;
-
}
- *p_img=Image(p_img->get_width(),p_img->get_height(),(mc-1)?true:false,Image::FORMAT_ETC,dst_data);
-
-
+ *p_img = Image(p_img->get_width(), p_img->get_height(), (mc - 1) ? true : false, Image::FORMAT_ETC, dst_data);
}
void _register_etc1_compress_func() {
rg_etc1::pack_etc1_block_init();
- Image::_image_compress_etc_func=_compress_etc;
- Image::_image_decompress_etc=_decompress_etc;
-
-
+ Image::_image_compress_etc_func = _compress_etc;
+ Image::_image_decompress_etc = _decompress_etc;
}
diff --git a/modules/etc1/image_etc.h b/modules/etc1/image_etc.h
index 6ab10126f..18461819d 100644
--- a/modules/etc1/image_etc.h
+++ b/modules/etc1/image_etc.h
@@ -29,7 +29,6 @@
#ifndef IMAGE_ETC1_H
#define IMAGE_ETC1_H
-
void _register_etc1_compress_func();
#endif // IMAGE_ETC_H
diff --git a/modules/etc1/register_types.cpp b/modules/etc1/register_types.cpp
index d02ef8347..b3b6419d2 100644
--- a/modules/etc1/register_types.cpp
+++ b/modules/etc1/register_types.cpp
@@ -35,7 +35,7 @@ static ResourceFormatPKM *resource_loader_pkm = NULL;
void register_etc1_types() {
- resource_loader_pkm = memnew( ResourceFormatPKM );
+ resource_loader_pkm = memnew(ResourceFormatPKM);
ResourceLoader::add_resource_format_loader(resource_loader_pkm);
_register_etc1_compress_func();
diff --git a/modules/etc1/texture_loader_pkm.cpp b/modules/etc1/texture_loader_pkm.cpp
index b00e71c48..bce10e691 100644
--- a/modules/etc1/texture_loader_pkm.cpp
+++ b/modules/etc1/texture_loader_pkm.cpp
@@ -32,38 +32,38 @@
#include <string.h>
struct ETC1Header {
- char tag[6]; // "PKM 10"
- uint16_t format; // Format == number of mips (== zero)
- uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian)
- uint16_t texHeight;
- uint16_t origWidth; // Original dimensions (big-endian)
- uint16_t origHeight;
+ char tag[6]; // "PKM 10"
+ uint16_t format; // Format == number of mips (== zero)
+ uint16_t texWidth; // Texture dimensions, multiple of 4 (big-endian)
+ uint16_t texHeight;
+ uint16_t origWidth; // Original dimensions (big-endian)
+ uint16_t origHeight;
};
-RES ResourceFormatPKM::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error) {
if (r_error)
- *r_error=ERR_CANT_OPEN;
+ *r_error = ERR_CANT_OPEN;
Error err;
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ,&err);
+ FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
if (!f)
return RES();
FileAccessRef fref(f);
if (r_error)
- *r_error=ERR_FILE_CORRUPT;
+ *r_error = ERR_FILE_CORRUPT;
- ERR_EXPLAIN("Unable to open PKM texture file: "+p_path);
- ERR_FAIL_COND_V(err!=OK,RES());
+ ERR_EXPLAIN("Unable to open PKM texture file: " + p_path);
+ ERR_FAIL_COND_V(err != OK, RES());
// big endian
f->set_endian_swap(true);
ETC1Header h;
- ERR_EXPLAIN("Invalid or Unsupported PKM texture file: "+p_path);
- f->get_buffer((uint8_t *) &h.tag, sizeof(h.tag));
- if(strncmp(h.tag, "PKM 10", sizeof(h.tag)))
+ ERR_EXPLAIN("Invalid or Unsupported PKM texture file: " + p_path);
+ f->get_buffer((uint8_t *)&h.tag, sizeof(h.tag));
+ if (strncmp(h.tag, "PKM 10", sizeof(h.tag)))
ERR_FAIL_V(RES());
h.format = f->get_16();
@@ -77,20 +77,20 @@ RES ResourceFormatPKM::load(const String &p_path, const String& p_original_path,
uint32_t size = h.texWidth * h.texHeight / 2;
src_data.resize(size);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
- wb=PoolVector<uint8_t>::Write();
+ f->get_buffer(wb.ptr(), size);
+ wb = PoolVector<uint8_t>::Write();
int mipmaps = h.format;
int width = h.origWidth;
int height = h.origHeight;
- Image img(width,height,mipmaps,Image::FORMAT_ETC,src_data);
+ Image img(width, height, mipmaps, Image::FORMAT_ETC, src_data);
- Ref<ImageTexture> texture = memnew( ImageTexture );
+ Ref<ImageTexture> texture = memnew(ImageTexture);
texture->create_from_image(img);
if (r_error)
- *r_error=OK;
+ *r_error = OK;
return texture;
}
@@ -100,14 +100,14 @@ void ResourceFormatPKM::get_recognized_extensions(List<String> *p_extensions) co
p_extensions->push_back("pkm");
}
-bool ResourceFormatPKM::handles_type(const String& p_type) const {
+bool ResourceFormatPKM::handles_type(const String &p_type) const {
- return ClassDB::is_parent_class(p_type,"Texture");
+ return ClassDB::is_parent_class(p_type, "Texture");
}
String ResourceFormatPKM::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="pkm")
+ if (p_path.get_extension().to_lower() == "pkm")
return "ImageTexture";
return "";
}
diff --git a/modules/etc1/texture_loader_pkm.h b/modules/etc1/texture_loader_pkm.h
index 9be7b051d..19d15d21f 100644
--- a/modules/etc1/texture_loader_pkm.h
+++ b/modules/etc1/texture_loader_pkm.h
@@ -29,15 +29,14 @@
#ifndef TEXTURE_LOADER_PKM_H
#define TEXTURE_LOADER_PKM_H
-#include "scene/resources/texture.h"
#include "io/resource_loader.h"
+#include "scene/resources/texture.h"
-class ResourceFormatPKM : public ResourceFormatLoader{
+class ResourceFormatPKM : public ResourceFormatLoader {
public:
-
- virtual RES load(const String &p_path,const String& p_original_path="",Error *r_error=NULL);
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *p_extensions) const;
- virtual bool handles_type(const String& p_type) const;
+ virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
virtual ~ResourceFormatPKM() {}