From b36e41cb7117757011e6f1ccc476ccc806219a58 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 6 Apr 2015 21:48:20 -0300 Subject: Added a PVRTC encoder for iOS --- drivers/pvr/texture_loader_pvr.cpp | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'drivers/pvr/texture_loader_pvr.cpp') diff --git a/drivers/pvr/texture_loader_pvr.cpp b/drivers/pvr/texture_loader_pvr.cpp index b12e0c28b8..5268b953f4 100644 --- a/drivers/pvr/texture_loader_pvr.cpp +++ b/drivers/pvr/texture_loader_pvr.cpp @@ -1,6 +1,8 @@ #include "texture_loader_pvr.h" #include "os/file_access.h" #include +#include "PvrTcEncoder.h" +#include "RgbaBitmap.h" static void _pvrtc_decompress(Image* p_img); @@ -154,10 +156,59 @@ String ResourceFormatPVR::get_resource_type(const String &p_path) const { } + +static void _compress_pvrtc4(Image * p_img) { + + Image img = *p_img; + + bool make_mipmaps=false; + if (img.get_width()%8 || img.get_height()%8) { + make_mipmaps=img.get_mipmaps()>0; + img.resize(img.get_width()+(8-(img.get_width()%8)),img.get_height()+(8-(img.get_height()%8))); + } + img.convert(Image::FORMAT_RGBA); + if (img.get_mipmaps()==0 && make_mipmaps) + img.generate_mipmaps(); + + bool use_alpha=img.detect_alpha(); + + Image new_img; + new_img.create(img.get_width(),img.get_height(),true,use_alpha?Image::FORMAT_PVRTC4_ALPHA:Image::FORMAT_PVRTC4); + DVector data=new_img.get_data(); + { + DVector::Write wr=data.write(); + DVector::Read r=img.get_data().read(); + + + for(int i=0;i<=new_img.get_mipmaps();i++) { + + int ofs,size,w,h; + img.get_mipmap_offset_size_and_dimensions(i,ofs,size,w,h); + Javelin::RgbaBitmap bm(w,h); + copymem(bm.GetData(),&r[ofs],size); + { + Javelin::ColorRgba *dp = bm.GetData(); + for(int j=0;j