summaryrefslogtreecommitdiff
path: root/modules/dds
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /modules/dds
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'modules/dds')
-rw-r--r--modules/dds/register_types.cpp2
-rw-r--r--modules/dds/texture_loader_dds.cpp345
-rw-r--r--modules/dds/texture_loader_dds.h9
3 files changed, 169 insertions, 187 deletions
diff --git a/modules/dds/register_types.cpp b/modules/dds/register_types.cpp
index 917305f543..d0eaf3f995 100644
--- a/modules/dds/register_types.cpp
+++ b/modules/dds/register_types.cpp
@@ -34,7 +34,7 @@ static ResourceFormatDDS *resource_loader_dds = NULL;
void register_dds_types() {
- resource_loader_dds = memnew( ResourceFormatDDS );
+ resource_loader_dds = memnew(ResourceFormatDDS);
ResourceLoader::add_resource_format_loader(resource_loader_dds);
}
diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp
index 600cae991e..9c976179fa 100644
--- a/modules/dds/texture_loader_dds.cpp
+++ b/modules/dds/texture_loader_dds.cpp
@@ -29,18 +29,17 @@
#include "texture_loader_dds.h"
#include "os/file_access.h"
-
enum {
- DDS_MAGIC=0x20534444,
- DDSD_CAPS=0x00000001,
- DDSD_PIXELFORMAT=0x00001000,
- DDSD_PITCH=0x00000008,
- DDSD_LINEARSIZE=0x00080000,
- DDSD_MIPMAPCOUNT=0x00020000,
- DDPF_FOURCC=0x00000004,
- DDPF_ALPHAPIXELS=0x00000001,
- DDPF_INDEXED=0x00000020,
- DDPF_RGB=0x00000040,
+ DDS_MAGIC = 0x20534444,
+ DDSD_CAPS = 0x00000001,
+ DDSD_PIXELFORMAT = 0x00001000,
+ DDSD_PITCH = 0x00000008,
+ DDSD_LINEARSIZE = 0x00080000,
+ DDSD_MIPMAPCOUNT = 0x00020000,
+ DDPF_FOURCC = 0x00000004,
+ DDPF_ALPHAPIXELS = 0x00000001,
+ DDPF_INDEXED = 0x00000020,
+ DDPF_RGB = 0x00000040,
};
enum DDSFormat {
@@ -72,41 +71,39 @@ struct DDSFormatInfo {
Image::Format format;
};
-
-static const DDSFormatInfo dds_format_info[DDS_MAX]={
- {"DXT1",true,false,4,8,Image::FORMAT_DXT1},
- {"DXT3",true,false,4,16,Image::FORMAT_DXT3},
- {"DXT5",true,false,4,16,Image::FORMAT_DXT5},
- {"ATI1",true,false,4,8,Image::FORMAT_ATI1},
- {"ATI2",true,false,4,16,Image::FORMAT_ATI2},
- {"BGRA8",false,false,1,4,Image::FORMAT_RGBA8},
- {"BGR8",false,false,1,3,Image::FORMAT_RGB8},
- {"RGBA8",false,false,1,4,Image::FORMAT_RGBA8},
- {"RGB8",false,false,1,3,Image::FORMAT_RGB8},
- {"BGR5A1",false,false,1,2,Image::FORMAT_RGBA8},
- {"BGR565",false,false,1,2,Image::FORMAT_RGB8},
- {"BGR10A2",false,false,1,4,Image::FORMAT_RGBA8},
- {"GRAYSCALE",false,false,1,1,Image::FORMAT_L8},
- {"GRAYSCALE_ALPHA",false,false,1,2,Image::FORMAT_LA8}
+static const DDSFormatInfo dds_format_info[DDS_MAX] = {
+ { "DXT1", true, false, 4, 8, Image::FORMAT_DXT1 },
+ { "DXT3", true, false, 4, 16, Image::FORMAT_DXT3 },
+ { "DXT5", true, false, 4, 16, Image::FORMAT_DXT5 },
+ { "ATI1", true, false, 4, 8, Image::FORMAT_ATI1 },
+ { "ATI2", true, false, 4, 16, Image::FORMAT_ATI2 },
+ { "BGRA8", false, false, 1, 4, Image::FORMAT_RGBA8 },
+ { "BGR8", false, false, 1, 3, Image::FORMAT_RGB8 },
+ { "RGBA8", false, false, 1, 4, Image::FORMAT_RGBA8 },
+ { "RGB8", false, false, 1, 3, Image::FORMAT_RGB8 },
+ { "BGR5A1", false, false, 1, 2, Image::FORMAT_RGBA8 },
+ { "BGR565", false, false, 1, 2, Image::FORMAT_RGB8 },
+ { "BGR10A2", false, false, 1, 4, Image::FORMAT_RGBA8 },
+ { "GRAYSCALE", false, false, 1, 1, Image::FORMAT_L8 },
+ { "GRAYSCALE_ALPHA", false, false, 1, 2, Image::FORMAT_LA8 }
};
-
-RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path, Error *r_error) {
+RES ResourceFormatDDS::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 DDS texture file: "+p_path);
- ERR_FAIL_COND_V(err!=OK,RES());
+ ERR_EXPLAIN("Unable to open DDS texture file: " + p_path);
+ ERR_FAIL_COND_V(err != OK, RES());
uint32_t magic = f->get_32();
uint32_t hsize = f->get_32();
@@ -118,18 +115,17 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path,
uint32_t mipmaps = f->get_32();
//skip 11
- for(int i=0;i<11;i++)
+ for (int i = 0; i < 11; i++)
f->get_32();
//validate
- if (magic!=DDS_MAGIC || hsize!=124 || !(flags&DDSD_PIXELFORMAT) || !(flags&DDSD_CAPS)) {
+ if (magic != DDS_MAGIC || hsize != 124 || !(flags & DDSD_PIXELFORMAT) || !(flags & DDSD_CAPS)) {
- ERR_EXPLAIN("Invalid or Unsupported DDS texture file: "+p_path);
+ ERR_EXPLAIN("Invalid or Unsupported DDS texture file: " + p_path);
ERR_FAIL_V(RES());
}
-
/* uint32_t format_size = */ f->get_32();
uint32_t format_flags = f->get_32();
uint32_t format_fourcc = f->get_32();
@@ -155,258 +151,249 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path,
//printf("rmask: %x gmask: %x, bmask: %x, amask: %x\n",format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask);
//must avoid this later
- while(f->get_pos()<128)
+ while (f->get_pos() < 128)
f->get_8();
-
DDSFormat dds_format;
- if (format_flags&DDPF_FOURCC && format_fourcc==0x31545844) { //'1TXD'
+ if (format_flags & DDPF_FOURCC && format_fourcc == 0x31545844) { //'1TXD'
- dds_format=DDS_DXT1;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x33545844) { //'3TXD'
+ dds_format = DDS_DXT1;
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x33545844) { //'3TXD'
- dds_format=DDS_DXT3;
+ dds_format = DDS_DXT3;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x35545844) { //'5TXD'
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x35545844) { //'5TXD'
- dds_format=DDS_DXT5;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x31495441) { //'1ITA'
+ dds_format = DDS_DXT5;
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x31495441) { //'1ITA'
- dds_format=DDS_ATI1;
- } else if (format_flags&DDPF_FOURCC && format_fourcc==0x32495441) { //'2ITA'
+ dds_format = DDS_ATI1;
+ } else if (format_flags & DDPF_FOURCC && format_fourcc == 0x32495441) { //'2ITA'
- dds_format=DDS_ATI2;
+ dds_format = DDS_ATI2;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==32 && format_red_mask==0xff0000 && format_green_mask==0xff00 && format_blue_mask==0xff && format_alpha_mask==0xff000000) {
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0xff0000 && format_green_mask == 0xff00 && format_blue_mask == 0xff && format_alpha_mask == 0xff000000) {
- dds_format=DDS_BGRA8;
- } else if (format_flags&DDPF_RGB && !(format_flags&DDPF_ALPHAPIXELS ) && format_rgb_bits==24 && format_red_mask==0xff0000 && format_green_mask==0xff00 && format_blue_mask==0xff) {
+ dds_format = DDS_BGRA8;
+ } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 24 && format_red_mask == 0xff0000 && format_green_mask == 0xff00 && format_blue_mask == 0xff) {
- dds_format=DDS_BGR8;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==32 && format_red_mask==0xff && format_green_mask==0xff00 && format_blue_mask==0xff0000 && format_alpha_mask==0xff000000) {
+ dds_format = DDS_BGR8;
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0xff && format_green_mask == 0xff00 && format_blue_mask == 0xff0000 && format_alpha_mask == 0xff000000) {
- dds_format=DDS_RGBA8;
- } else if (format_flags&DDPF_RGB && !(format_flags&DDPF_ALPHAPIXELS ) && format_rgb_bits==24 && format_red_mask==0xff && format_green_mask==0xff00 && format_blue_mask==0xff0000) {
+ dds_format = DDS_RGBA8;
+ } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 24 && format_red_mask == 0xff && format_green_mask == 0xff00 && format_blue_mask == 0xff0000) {
- dds_format=DDS_RGB8;
+ dds_format = DDS_RGB8;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==16 && format_red_mask==0x00007c00 && format_green_mask==0x000003e0 && format_blue_mask==0x0000001f && format_alpha_mask==0x00008000) {
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 16 && format_red_mask == 0x00007c00 && format_green_mask == 0x000003e0 && format_blue_mask == 0x0000001f && format_alpha_mask == 0x00008000) {
- dds_format=DDS_BGR5A1;
- } else if (format_flags&DDPF_RGB && format_flags&DDPF_ALPHAPIXELS && format_rgb_bits==32 && format_red_mask==0x3ff00000 && format_green_mask==0xffc00 && format_blue_mask==0x3ff && format_alpha_mask==0xc0000000) {
+ dds_format = DDS_BGR5A1;
+ } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0x3ff00000 && format_green_mask == 0xffc00 && format_blue_mask == 0x3ff && format_alpha_mask == 0xc0000000) {
- dds_format=DDS_BGR10A2;
- } else if (format_flags&DDPF_RGB && !(format_flags&DDPF_ALPHAPIXELS) && format_rgb_bits==16 && format_red_mask==0x0000f800 && format_green_mask==0x000007e0 && format_blue_mask==0x0000001f) {
+ dds_format = DDS_BGR10A2;
+ } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 16 && format_red_mask == 0x0000f800 && format_green_mask == 0x000007e0 && format_blue_mask == 0x0000001f) {
- dds_format=DDS_BGR565;
- } else if (!(format_flags&DDPF_ALPHAPIXELS) && format_rgb_bits==8 && format_red_mask==0xff && format_green_mask==0xff && format_blue_mask==0xff) {
+ dds_format = DDS_BGR565;
+ } else if (!(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 8 && format_red_mask == 0xff && format_green_mask == 0xff && format_blue_mask == 0xff) {
- dds_format=DDS_LUMINANCE;
- } else if ((format_flags&DDPF_ALPHAPIXELS) && format_rgb_bits==16 && format_red_mask==0xff && format_green_mask==0xff && format_blue_mask==0xff && format_alpha_mask==0xff00) {
+ dds_format = DDS_LUMINANCE;
+ } else if ((format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 16 && format_red_mask == 0xff && format_green_mask == 0xff && format_blue_mask == 0xff && format_alpha_mask == 0xff00) {
- dds_format=DDS_LUMINANCE_ALPHA;
- } else if (format_flags&DDPF_INDEXED && format_rgb_bits==8) {
+ dds_format = DDS_LUMINANCE_ALPHA;
+ } else if (format_flags & DDPF_INDEXED && format_rgb_bits == 8) {
- dds_format=DDS_BGR565;
+ dds_format = DDS_BGR565;
} else {
- printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n",format_fourcc,format_flags,format_rgb_bits,format_red_mask,format_green_mask,format_blue_mask,format_alpha_mask);
- ERR_EXPLAIN("Unrecognized or Unsupported color layout in DDS: "+p_path);
+ printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n", format_fourcc, format_flags, format_rgb_bits, format_red_mask, format_green_mask, format_blue_mask, format_alpha_mask);
+ ERR_EXPLAIN("Unrecognized or Unsupported color layout in DDS: " + p_path);
ERR_FAIL_V(RES());
-
}
- if (!(flags&DDSD_MIPMAPCOUNT))
- mipmaps=1;
+ if (!(flags & DDSD_MIPMAPCOUNT))
+ mipmaps = 1;
//print_line("found format: "+String(dds_format_info[dds_format].name));
PoolVector<uint8_t> src_data;
- const DDSFormatInfo &info=dds_format_info[dds_format];
+ const DDSFormatInfo &info = dds_format_info[dds_format];
uint32_t w = width;
uint32_t h = height;
-
if (info.compressed) {
//compressed bc
- uint32_t size = MAX( info.divisor, w )/info.divisor * MAX( info.divisor, h )/info.divisor * info.block_size;
- ERR_FAIL_COND_V( size!=pitch, RES() );
- ERR_FAIL_COND_V( !(flags&DDSD_LINEARSIZE), RES() );
+ uint32_t size = MAX(info.divisor, w) / info.divisor * MAX(info.divisor, h) / info.divisor * info.block_size;
+ ERR_FAIL_COND_V(size != pitch, RES());
+ ERR_FAIL_COND_V(!(flags & DDSD_LINEARSIZE), RES());
- for(uint32_t i=1;i<mipmaps;i++) {
+ for (uint32_t i = 1; i < mipmaps; i++) {
- w=MAX(1,w>>1);
- h=MAX(1,h>>1);
- uint32_t bsize = MAX( info.divisor, w )/info.divisor * MAX( info.divisor, h )/info.divisor * info.block_size;
+ w = MAX(1, w >> 1);
+ h = MAX(1, h >> 1);
+ uint32_t bsize = MAX(info.divisor, w) / info.divisor * MAX(info.divisor, h) / info.divisor * info.block_size;
//printf("%i x %i - block: %i\n",w,h,bsize);
- size+= bsize;
+ size += bsize;
}
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();
} else if (info.palette) {
//indexed
- ERR_FAIL_COND_V( !(flags&DDSD_PITCH), RES());
- ERR_FAIL_COND_V( format_rgb_bits!=8, RES() );
+ ERR_FAIL_COND_V(!(flags & DDSD_PITCH), RES());
+ ERR_FAIL_COND_V(format_rgb_bits != 8, RES());
- uint32_t size = pitch*height;
- ERR_FAIL_COND_V( size != width*height * info.block_size, RES());
+ uint32_t size = pitch * height;
+ ERR_FAIL_COND_V(size != width * height * info.block_size, RES());
- uint8_t pallete[256*4];
- f->get_buffer(pallete,256*4);
+ uint8_t pallete[256 * 4];
+ f->get_buffer(pallete, 256 * 4);
- int colsize=3;
- for(int i=0;i<256;i++) {
+ int colsize = 3;
+ for (int i = 0; i < 256; i++) {
- if (pallete[i*4+3]<255)
- colsize=4;
+ if (pallete[i * 4 + 3] < 255)
+ colsize = 4;
}
int w = width;
int h = height;
- for(uint32_t i=1;i<mipmaps;i++) {
+ for (uint32_t i = 1; i < mipmaps; i++) {
- w=(w+1)>>1;
- h=(h+1)>>1;
- size+= w*h*info.block_size;
+ w = (w + 1) >> 1;
+ h = (h + 1) >> 1;
+ size += w * h * info.block_size;
}
- src_data.resize(size + 256*colsize );
+ src_data.resize(size + 256 * colsize);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
+ f->get_buffer(wb.ptr(), size);
- for(int i=0;i<256;i++) {
+ for (int i = 0; i < 256; i++) {
- int dst_ofs = size+i*colsize;
- int src_ofs = i*4;
- wb[dst_ofs+0]=pallete[src_ofs+2];
- wb[dst_ofs+1]=pallete[src_ofs+1];
- wb[dst_ofs+2]=pallete[src_ofs+0];
- if (colsize==4)
- wb[dst_ofs+3]=pallete[src_ofs+3];
+ int dst_ofs = size + i * colsize;
+ int src_ofs = i * 4;
+ wb[dst_ofs + 0] = pallete[src_ofs + 2];
+ wb[dst_ofs + 1] = pallete[src_ofs + 1];
+ wb[dst_ofs + 2] = pallete[src_ofs + 0];
+ if (colsize == 4)
+ wb[dst_ofs + 3] = pallete[src_ofs + 3];
}
-
- wb=PoolVector<uint8_t>::Write();
+ wb = PoolVector<uint8_t>::Write();
} else {
//uncompressed generic...
- uint32_t size = width*height*info.block_size;
-
+ uint32_t size = width * height * info.block_size;
- for(uint32_t i=1;i<mipmaps;i++) {
+ for (uint32_t i = 1; i < mipmaps; i++) {
- w=(w+1)>>1;
- h=(h+1)>>1;
- size+= w*h*info.block_size;
+ w = (w + 1) >> 1;
+ h = (h + 1) >> 1;
+ size += w * h * info.block_size;
}
- if (dds_format==DDS_BGR565)
- size=size*3/2;
- else if (dds_format==DDS_BGR5A1)
- size=size*2;
+ if (dds_format == DDS_BGR565)
+ size = size * 3 / 2;
+ else if (dds_format == DDS_BGR5A1)
+ size = size * 2;
src_data.resize(size);
PoolVector<uint8_t>::Write wb = src_data.write();
- f->get_buffer(wb.ptr(),size);
-
+ f->get_buffer(wb.ptr(), size);
- switch(dds_format) {
+ switch (dds_format) {
case DDS_BGR5A1: {
// TO RGBA
- int colcount = size/4;
+ int colcount = size / 4;
- for(int i=colcount-1;i>=0;i--) {
+ for (int i = colcount - 1; i >= 0; i--) {
- int src_ofs = i*2;
- int dst_ofs = i*4;
+ int src_ofs = i * 2;
+ int dst_ofs = i * 4;
- uint8_t a=wb[src_ofs+1]&0x80;
- uint8_t b= wb[src_ofs]&0x1F;
- uint8_t g= (wb[src_ofs]>>5) | ((wb[src_ofs+1]&0x3)<<3);
- uint8_t r= (wb[src_ofs+1]>>2)&0x1F;
- wb[dst_ofs+0]=r<<3;
- wb[dst_ofs+1]=g<<3;
- wb[dst_ofs+2]=b<<3;
- wb[dst_ofs+3]=a?255:0;
+ uint8_t a = wb[src_ofs + 1] & 0x80;
+ uint8_t b = wb[src_ofs] & 0x1F;
+ uint8_t g = (wb[src_ofs] >> 5) | ((wb[src_ofs + 1] & 0x3) << 3);
+ uint8_t r = (wb[src_ofs + 1] >> 2) & 0x1F;
+ wb[dst_ofs + 0] = r << 3;
+ wb[dst_ofs + 1] = g << 3;
+ wb[dst_ofs + 2] = b << 3;
+ wb[dst_ofs + 3] = a ? 255 : 0;
}
} break;
case DDS_BGR565: {
- int colcount = size/3;
-
- for(int i=colcount-1;i>=0;i--) {
+ int colcount = size / 3;
- int src_ofs = i*2;
- int dst_ofs = i*3;
+ for (int i = colcount - 1; i >= 0; i--) {
- uint8_t b= wb[src_ofs]&0x1F;
- uint8_t g= (wb[src_ofs]>>5) | ((wb[src_ofs+1]&0x7)<<3);
- uint8_t r= wb[src_ofs+1]>>3;
- wb[dst_ofs+0]=r<<3;
- wb[dst_ofs+1]=g<<2;
- wb[dst_ofs+2]=b<<3;//b<<3;
+ int src_ofs = i * 2;
+ int dst_ofs = i * 3;
+ uint8_t b = wb[src_ofs] & 0x1F;
+ uint8_t g = (wb[src_ofs] >> 5) | ((wb[src_ofs + 1] & 0x7) << 3);
+ uint8_t r = wb[src_ofs + 1] >> 3;
+ wb[dst_ofs + 0] = r << 3;
+ wb[dst_ofs + 1] = g << 2;
+ wb[dst_ofs + 2] = b << 3; //b<<3;
}
} break;
case DDS_BGR10A2: {
// TO RGBA
- int colcount = size/4;
-
- for(int i=colcount-1;i>=0;i--) {
-
- int ofs = i*4;
+ int colcount = size / 4;
- uint32_t w32 = uint32_t(wb[ofs+0]) | (uint32_t(wb[ofs+1])<<8) | (uint32_t(wb[ofs+2])<<16) | (uint32_t(wb[ofs+3])<<24);
+ for (int i = colcount - 1; i >= 0; i--) {
- uint8_t a= (w32&0xc0000000) >> 24;
- uint8_t r= (w32&0x3ff00000) >> 22;
- uint8_t g= (w32&0xffc00) >> 12;
- uint8_t b= (w32&0x3ff) >> 2;
+ int ofs = i * 4;
+ uint32_t w32 = uint32_t(wb[ofs + 0]) | (uint32_t(wb[ofs + 1]) << 8) | (uint32_t(wb[ofs + 2]) << 16) | (uint32_t(wb[ofs + 3]) << 24);
- wb[ofs+0]=r;
- wb[ofs+1]=g;
- wb[ofs+2]=b;
- wb[ofs+3]=a==0xc0 ? 255 : a; //0xc0 should be opaque
+ uint8_t a = (w32 & 0xc0000000) >> 24;
+ uint8_t r = (w32 & 0x3ff00000) >> 22;
+ uint8_t g = (w32 & 0xffc00) >> 12;
+ uint8_t b = (w32 & 0x3ff) >> 2;
+ wb[ofs + 0] = r;
+ wb[ofs + 1] = g;
+ wb[ofs + 2] = b;
+ wb[ofs + 3] = a == 0xc0 ? 255 : a; //0xc0 should be opaque
}
} break;
case DDS_BGRA8: {
- int colcount = size/4;
+ int colcount = size / 4;
- for(int i=0;i<colcount;i++) {
+ for (int i = 0; i < colcount; i++) {
- SWAP( wb[i*4+0],wb[i*4+2] );
+ SWAP(wb[i * 4 + 0], wb[i * 4 + 2]);
}
} break;
case DDS_BGR8: {
- int colcount = size/3;
+ int colcount = size / 3;
- for(int i=0;i<colcount;i++) {
+ for (int i = 0; i < colcount; i++) {
- SWAP( wb[i*3+0],wb[i*3+2] );
+ SWAP(wb[i * 3 + 0], wb[i * 3 + 2]);
}
} break;
case DDS_RGBA8: {
- /* do nothing either
+ /* do nothing either
int colcount = size/4;
for(int i=0;i<colcount;i++) {
@@ -446,24 +433,20 @@ RES ResourceFormatDDS::load(const String &p_path, const String& p_original_path,
} break;
default: {}
-
}
- wb=PoolVector<uint8_t>::Write();
+ wb = PoolVector<uint8_t>::Write();
}
+ Image img(width, height, mipmaps - 1, info.format, src_data);
- Image img(width,height,mipmaps-1,info.format,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;
-
}
void ResourceFormatDDS::get_recognized_extensions(List<String> *p_extensions) const {
@@ -471,14 +454,14 @@ void ResourceFormatDDS::get_recognized_extensions(List<String> *p_extensions) co
p_extensions->push_back("dds");
}
-bool ResourceFormatDDS::handles_type(const String& p_type) const {
+bool ResourceFormatDDS::handles_type(const String &p_type) const {
- return ClassDB::is_parent_class(p_type,"Texture");
+ return ClassDB::is_parent_class(p_type, "Texture");
}
String ResourceFormatDDS::get_resource_type(const String &p_path) const {
- if (p_path.get_extension().to_lower()=="dds")
+ if (p_path.get_extension().to_lower() == "dds")
return "ImageTexture";
return "";
}
diff --git a/modules/dds/texture_loader_dds.h b/modules/dds/texture_loader_dds.h
index d09af680c7..c347937cd5 100644
--- a/modules/dds/texture_loader_dds.h
+++ b/modules/dds/texture_loader_dds.h
@@ -29,15 +29,14 @@
#ifndef TEXTURE_LOADER_DDS_H
#define TEXTURE_LOADER_DDS_H
-#include "scene/resources/texture.h"
#include "io/resource_loader.h"
+#include "scene/resources/texture.h"
-class ResourceFormatDDS : public ResourceFormatLoader{
+class ResourceFormatDDS : 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 ~ResourceFormatDDS() {}