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
This commit is contained in:
Rémi Verschelde
2017-03-05 16:44:50 +01:00
parent 45438e9918
commit 5dbf1809c6
1318 changed files with 140051 additions and 166004 deletions

View File

@@ -29,59 +29,59 @@
#include "image_loader_webp.h"
#include "io/marshalls.h"
#include "print_string.h"
#include "os/os.h"
#include "print_string.h"
#include <stdlib.h>
#include <webp/decode.h>
#include <webp/encode.h>
static PoolVector<uint8_t> _webp_lossy_pack(const Image& p_image,float p_quality) {
static PoolVector<uint8_t> _webp_lossy_pack(const Image &p_image, float p_quality) {
ERR_FAIL_COND_V(p_image.empty(),PoolVector<uint8_t>());
ERR_FAIL_COND_V(p_image.empty(), PoolVector<uint8_t>());
Image img=p_image;
Image img = p_image;
if (img.detect_alpha())
img.convert(Image::FORMAT_RGBA8);
else
img.convert(Image::FORMAT_RGB8);
Size2 s(img.get_width(),img.get_height());
Size2 s(img.get_width(), img.get_height());
PoolVector<uint8_t> data = img.get_data();
PoolVector<uint8_t>::Read r = data.read();
uint8_t *dst_buff=NULL;
size_t dst_size=0;
if (img.get_format()==Image::FORMAT_RGB8) {
uint8_t *dst_buff = NULL;
size_t dst_size = 0;
if (img.get_format() == Image::FORMAT_RGB8) {
dst_size = WebPEncodeRGB(r.ptr(),s.width,s.height,3*s.width,CLAMP(p_quality*100.0,0,100.0),&dst_buff);
dst_size = WebPEncodeRGB(r.ptr(), s.width, s.height, 3 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff);
} else {
dst_size = WebPEncodeRGBA(r.ptr(),s.width,s.height,4*s.width,CLAMP(p_quality*100.0,0,100.0),&dst_buff);
dst_size = WebPEncodeRGBA(r.ptr(), s.width, s.height, 4 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff);
}
ERR_FAIL_COND_V(dst_size==0,PoolVector<uint8_t>());
ERR_FAIL_COND_V(dst_size == 0, PoolVector<uint8_t>());
PoolVector<uint8_t> dst;
dst.resize(4+dst_size);
dst.resize(4 + dst_size);
PoolVector<uint8_t>::Write w = dst.write();
w[0]='W';
w[1]='E';
w[2]='B';
w[3]='P';
copymem(&w[4],dst_buff,dst_size);
w[0] = 'W';
w[1] = 'E';
w[2] = 'B';
w[3] = 'P';
copymem(&w[4], dst_buff, dst_size);
free(dst_buff);
w=PoolVector<uint8_t>::Write();
w = PoolVector<uint8_t>::Write();
return dst;
}
static Image _webp_lossy_unpack(const PoolVector<uint8_t>& p_buffer) {
static Image _webp_lossy_unpack(const PoolVector<uint8_t> &p_buffer) {
int size = p_buffer.size()-4;
ERR_FAIL_COND_V(size<=0,Image());
int size = p_buffer.size() - 4;
ERR_FAIL_COND_V(size <= 0, Image());
PoolVector<uint8_t>::Read r = p_buffer.read();
ERR_FAIL_COND_V(r[0]!='W' || r[1]!='E' || r[2]!='B' || r[3]!='P',Image());
ERR_FAIL_COND_V(r[0] != 'W' || r[1] != 'E' || r[2] != 'B' || r[3] != 'P', Image());
WebPBitstreamFeatures features;
if (WebPGetFeatures(&r[4],size,&features)!=VP8_STATUS_OK) {
if (WebPGetFeatures(&r[4], size, &features) != VP8_STATUS_OK) {
ERR_EXPLAIN("Error unpacking WEBP image:");
ERR_FAIL_V(Image());
}
@@ -91,31 +91,27 @@ static Image _webp_lossy_unpack(const PoolVector<uint8_t>& p_buffer) {
//print_line("alpha: "+itos(features.has_alpha));
PoolVector<uint8_t> dst_image;
int datasize = features.width*features.height*(features.has_alpha?4:3);
int datasize = features.width * features.height * (features.has_alpha ? 4 : 3);
dst_image.resize(datasize);
PoolVector<uint8_t>::Write dst_w = dst_image.write();
bool errdec=false;
if (features.has_alpha) {
errdec = WebPDecodeRGBAInto(&r[4],size,dst_w.ptr(),datasize,4*features.width)==NULL;
bool errdec = false;
if (features.has_alpha) {
errdec = WebPDecodeRGBAInto(&r[4], size, dst_w.ptr(), datasize, 4 * features.width) == NULL;
} else {
errdec = WebPDecodeRGBInto(&r[4],size,dst_w.ptr(),datasize,3*features.width)==NULL;
errdec = WebPDecodeRGBInto(&r[4], size, dst_w.ptr(), datasize, 3 * features.width) == NULL;
}
//ERR_EXPLAIN("Error decoding webp! - "+p_file);
ERR_FAIL_COND_V(errdec,Image());
ERR_FAIL_COND_V(errdec, Image());
dst_w = PoolVector<uint8_t>::Write();
return Image(features.width,features.height,0,features.has_alpha?Image::FORMAT_RGBA8:Image::FORMAT_RGB8,dst_image);
return Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image);
}
Error ImageLoaderWEBP::load_image(Image *p_image,FileAccess *f) {
Error ImageLoaderWEBP::load_image(Image *p_image, FileAccess *f) {
uint32_t size = f->get_len();
PoolVector<uint8_t> src_image;
@@ -124,60 +120,53 @@ Error ImageLoaderWEBP::load_image(Image *p_image,FileAccess *f) {
WebPBitstreamFeatures features;
PoolVector<uint8_t>::Write src_w = src_image.write();
f->get_buffer(src_w.ptr(),size);
f->get_buffer(src_w.ptr(), size);
ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_EOF);
if (WebPGetFeatures(src_w.ptr(),size,&features)!=VP8_STATUS_OK) {
if (WebPGetFeatures(src_w.ptr(), size, &features) != VP8_STATUS_OK) {
f->close();
//ERR_EXPLAIN("Error decoding WEBP image: "+p_file);
ERR_FAIL_V(ERR_FILE_CORRUPT);
}
print_line("width: "+itos(features.width));
print_line("height: "+itos(features.height));
print_line("alpha: "+itos(features.has_alpha));
print_line("width: " + itos(features.width));
print_line("height: " + itos(features.height));
print_line("alpha: " + itos(features.has_alpha));
src_w = PoolVector<uint8_t>::Write();
PoolVector<uint8_t> dst_image;
int datasize = features.width*features.height*(features.has_alpha?4:3);
int datasize = features.width * features.height * (features.has_alpha ? 4 : 3);
dst_image.resize(datasize);
PoolVector<uint8_t>::Read src_r = src_image.read();
PoolVector<uint8_t>::Write dst_w = dst_image.write();
bool errdec=false;
if (features.has_alpha) {
errdec = WebPDecodeRGBAInto(src_r.ptr(),size,dst_w.ptr(),datasize,4*features.width)==NULL;
bool errdec = false;
if (features.has_alpha) {
errdec = WebPDecodeRGBAInto(src_r.ptr(), size, dst_w.ptr(), datasize, 4 * features.width) == NULL;
} else {
errdec = WebPDecodeRGBInto(src_r.ptr(),size,dst_w.ptr(),datasize,3*features.width)==NULL;
errdec = WebPDecodeRGBInto(src_r.ptr(), size, dst_w.ptr(), datasize, 3 * features.width) == NULL;
}
//ERR_EXPLAIN("Error decoding webp! - "+p_file);
ERR_FAIL_COND_V(errdec,ERR_FILE_CORRUPT);
ERR_FAIL_COND_V(errdec, ERR_FILE_CORRUPT);
src_r = PoolVector<uint8_t>::Read();
dst_w = PoolVector<uint8_t>::Write();
*p_image = Image(features.width,features.height,0,features.has_alpha?Image::FORMAT_RGBA8:Image::FORMAT_RGB8,dst_image);
*p_image = Image(features.width, features.height, 0, features.has_alpha ? Image::FORMAT_RGBA8 : Image::FORMAT_RGB8, dst_image);
return OK;
}
void ImageLoaderWEBP::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("webp");
}
ImageLoaderWEBP::ImageLoaderWEBP() {
Image::lossy_packer=_webp_lossy_pack;
Image::lossy_unpacker=_webp_lossy_unpack;
Image::lossy_packer = _webp_lossy_pack;
Image::lossy_unpacker = _webp_lossy_unpack;
}