From 5dbf1809c6e3e905b94b8764e99491e608122261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 5 Mar 2017 16:44:50 +0100 Subject: 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 --- modules/jpg/image_loader_jpegd.cpp | 54 ++++++++++++++------------------------ modules/jpg/image_loader_jpegd.h | 8 ++---- modules/jpg/register_types.cpp | 4 +-- 3 files changed, 24 insertions(+), 42 deletions(-) (limited to 'modules/jpg') diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index 1152d42e1b..ca928c4fe6 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -28,16 +28,15 @@ /*************************************************************************/ #include "image_loader_jpegd.h" -#include "print_string.h" #include "os/os.h" +#include "print_string.h" #include #include +Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p_buffer_len) { -Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_buffer_len) { - - jpgd::jpeg_decoder_mem_stream mem_stream(p_buffer,p_buffer_len); + jpgd::jpeg_decoder_mem_stream mem_stream(p_buffer, p_buffer_len); jpgd::jpeg_decoder decoder(&mem_stream); @@ -48,8 +47,8 @@ Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_ const int image_width = decoder.get_width(); const int image_height = decoder.get_height(); int comps = decoder.get_num_components(); - if (comps==3) - comps=4; //weird + if (comps == 3) + comps = 4; //weird if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS) return ERR_FILE_CORRUPT; @@ -62,42 +61,34 @@ Error jpeg_load_image_from_buffer(Image *p_image,const uint8_t* p_buffer, int p_ PoolVector::Write dw = data.write(); - jpgd::uint8 *pImage_data = (jpgd::uint8*)dw.ptr(); + jpgd::uint8 *pImage_data = (jpgd::uint8 *)dw.ptr(); - for (int y = 0; y < image_height; y++) - { - const jpgd::uint8* pScan_line; + for (int y = 0; y < image_height; y++) { + const jpgd::uint8 *pScan_line; jpgd::uint scan_line_len; - if (decoder.decode((const void**)&pScan_line, &scan_line_len) != jpgd::JPGD_SUCCESS) - { + if (decoder.decode((const void **)&pScan_line, &scan_line_len) != jpgd::JPGD_SUCCESS) { return ERR_FILE_CORRUPT; } jpgd::uint8 *pDst = pImage_data + y * dst_bpl; memcpy(pDst, pScan_line, dst_bpl); - - } - //all good Image::Format fmt; - if (comps==1) - fmt=Image::FORMAT_L8; + if (comps == 1) + fmt = Image::FORMAT_L8; else - fmt=Image::FORMAT_RGBA8; + fmt = Image::FORMAT_RGBA8; dw = PoolVector::Write(); - p_image->create(image_width,image_height,0,fmt,data); + p_image->create(image_width, image_height, 0, fmt, data); return OK; - } - -Error ImageLoaderJPG::load_image(Image *p_image,FileAccess *f) { - +Error ImageLoaderJPG::load_image(Image *p_image, FileAccess *f) { PoolVector src_image; int src_image_len = f->get_len(); @@ -106,30 +97,27 @@ Error ImageLoaderJPG::load_image(Image *p_image,FileAccess *f) { PoolVector::Write w = src_image.write(); - f->get_buffer(&w[0],src_image_len); + f->get_buffer(&w[0], src_image_len); f->close(); - - Error err = jpeg_load_image_from_buffer(p_image,w.ptr(),src_image_len); + Error err = jpeg_load_image_from_buffer(p_image, w.ptr(), src_image_len); w = PoolVector::Write(); return err; - } void ImageLoaderJPG::get_recognized_extensions(List *p_extensions) const { - + p_extensions->push_back("jpg"); p_extensions->push_back("jpeg"); } - -static Image _jpegd_mem_loader_func(const uint8_t* p_png,int p_size) { +static Image _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { Image img; - Error err = jpeg_load_image_from_buffer(&img,p_png,p_size); + Error err = jpeg_load_image_from_buffer(&img, p_png, p_size); if (err) ERR_PRINT("Couldn't initialize ImageLoaderJPG with the given resource."); @@ -138,7 +126,5 @@ static Image _jpegd_mem_loader_func(const uint8_t* p_png,int p_size) { ImageLoaderJPG::ImageLoaderJPG() { - Image::_jpg_mem_loader_func=_jpegd_mem_loader_func; + Image::_jpg_mem_loader_func = _jpegd_mem_loader_func; } - - diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index aeb219aa5d..0803cfba1e 100644 --- a/modules/jpg/image_loader_jpegd.h +++ b/modules/jpg/image_loader_jpegd.h @@ -36,14 +36,10 @@ */ class ImageLoaderJPG : public ImageFormatLoader { - public: - - virtual Error load_image(Image *p_image,FileAccess *f); - virtual void get_recognized_extensions(List *p_extensions) const; + virtual Error load_image(Image *p_image, FileAccess *f); + virtual void get_recognized_extensions(List *p_extensions) const; ImageLoaderJPG(); }; - - #endif diff --git a/modules/jpg/register_types.cpp b/modules/jpg/register_types.cpp index bcd467f5fc..ce0330643a 100644 --- a/modules/jpg/register_types.cpp +++ b/modules/jpg/register_types.cpp @@ -34,11 +34,11 @@ static ImageLoaderJPG *image_loader_jpg = NULL; void register_jpg_types() { - image_loader_jpg = memnew( ImageLoaderJPG ); + image_loader_jpg = memnew(ImageLoaderJPG); ImageLoader::add_image_format_loader(image_loader_jpg); } void unregister_jpg_types() { - memdelete( image_loader_jpg ); + memdelete(image_loader_jpg); } -- cgit v1.2.3