Wed, 12 Aug 2020 14:25:36 +0300
* Couple of fixes
--- a/Source/Gorgon/Containers/Image.h Sun Jul 19 11:47:10 2020 +0300 +++ b/Source/Gorgon/Containers/Image.h Wed Aug 12 14:25:36 2020 +0300 @@ -60,10 +60,10 @@ /// Duplicates this image, essentially performing the work of copy constructor basic_Image Duplicate() const { - basic_Image data; - data.Assign(this->data, size, mode); + basic_Image n; + n.Assign(data, size, mode); - return data; + return n; } /// Resizes the image to the given size and color mode. This function discards the contents @@ -310,6 +310,7 @@ mode = Graphics::ColorMode::RGBA; } + // cppcheck-suppress constParameter /// Copies data from one image to another. This operation does not perform /// blending. Additionally, color modes should be the same. However, this /// function will do clipping for overflows. Do not use negative values for @@ -342,6 +343,7 @@ return true; } + // cppcheck-suppress constParameter /// Copies data from one image to another. This operation does not perform /// blending. Additionally, color modes should be the same. However, this /// function will do clipping. Source bounds should be within the image. @@ -371,7 +373,7 @@ if(source.Top >= source.Bottom) return false; - int dw = dest.GetWidth(), dh = dest.GetHeight(); + int dw = dest.GetWidth(); int sw = source.Width(); Byte *dd = dest.RawData(); const Byte *sd = RawData(); @@ -426,8 +428,8 @@ } break; - case Graphics::ColorMode::Alpha: { - for(i=0; i<size.Area(); i++) + case Graphics::ColorMode::Alpha: + for(i=0; i<size.Area(); i++) { buffer[i*4+0] = 255; buffer[i*4+1] = 255; buffer[i*4+2] = 255; @@ -497,8 +499,8 @@ } break; - case Graphics::ColorMode::Alpha: { - for(i=0; i<size.Area(); i++) + case Graphics::ColorMode::Alpha: + for(i=0; i<size.Area(); i++) { buffer[i*4+0] = 255; buffer[i*4+1] = 255; buffer[i*4+2] = 255; @@ -616,7 +618,6 @@ int width = 0, height = 0; int bpp = 0; bool upsidedown = false; - bool bitcompress = false; bool grayscalepalette = true; int colorsused = 0; bool alpha = false; @@ -654,7 +655,7 @@ if(compress != 0 && compress != 3) return false; - bitcompress = compress != 0; + bool bitcompress = compress != 0; ReadUInt32(file); //size of bitmap @@ -805,25 +806,25 @@ for(int y = ys; y!=ye; y += yc) { int bytes = 0; for(int x=0; x<width; x++) { - uint32_t data; + uint32_t pix; if(bpp == 16) - data = ReadUInt16(file); + pix = ReadUInt16(file); else - data = ReadUInt32(file); + pix = ReadUInt32(file); if(redmask != 0 || greenmask != 0 || bluemask != 0) { - this->operator ()({x, y}, 0) = (Byte)std::round(((data&redmask)>>redshift) * redmult); - this->operator ()({x, y}, 1) = (Byte)std::round(((data&greenmask)>>greenshift) * greenmult); - this->operator ()({x, y}, 2) = (Byte)std::round(((data&bluemask)>>blueshift) * bluemult); + this->operator ()({x, y}, 0) = (Byte)std::round(((pix&redmask)>>redshift) * redmult); + this->operator ()({x, y}, 1) = (Byte)std::round(((pix&greenmask)>>greenshift) * greenmult); + this->operator ()({x, y}, 2) = (Byte)std::round(((pix&bluemask)>>blueshift) * bluemult); } if(alpha) { if(redmask != 0 || greenmask != 0 || bluemask != 0) { - this->operator ()({x, y}, 3) = (Byte)std::round(((data&alphamask)>>alphashift) * alphamult); + this->operator ()({x, y}, 3) = (Byte)std::round(((pix&alphamask)>>alphashift) * alphamult); } else { - this->operator ()({x, y}, 0) = (Byte)std::round(((data&alphamask)>>alphashift) * alphamult); + this->operator ()({x, y}, 0) = (Byte)std::round(((pix&alphamask)>>alphashift) * alphamult); } } @@ -835,7 +836,7 @@ } } } - else { + else if(bpp < 8) { Byte bitmask = (1 << bpp) - 1; bitmask = bitmask << (8-bpp); for(int y = ys; y!=ye; y += yc) { @@ -954,8 +955,8 @@ datasize = stride * size.Height; headersize = 108; - datasize = stride * size.Height; - compression = 3; + + compression = 3; bpp = 16; break;
--- a/Source/Gorgon/Graphics/Color.h Sun Jul 19 11:47:10 2020 +0300 +++ b/Source/Gorgon/Graphics/Color.h Wed Aug 12 14:25:36 2020 +0300 @@ -92,7 +92,8 @@ public: /// Data type for each channel typedef Byte ChannelType; - + + // cppcheck-suppress uninitMemberVar /// Default constructor does not perform initialization RGBA() {} @@ -133,11 +134,13 @@ /// Constructs a grayscale color from the given luminance explicit RGBA(int lum, int a) : RGBA(Byte(lum), Byte(lum), Byte(lum), Byte(a)) {} + // cppcheck-suppress noExplicitConstructor /// Conversion from integer constexpr RGBA(int color) : R((color>>0)&0xff), G((color>>8)&0xff), B((color>>16)&0xff), A((color>>24)&0xff) { static_assert(sizeof(int)>=4, "This conversion requires size of int to be at least 4 bytes"); } + // cppcheck-suppress noExplicitConstructor /// Conversion from uint32_t constexpr RGBA(uint32_t color) : R((color>>0)&0xff), G((color>>8)&0xff), B((color>>16)&0xff), A((color>>24)&0xff) { static_assert(sizeof(int)>=4, "This conversion requires size of int to be at least 4 bytes"); @@ -401,12 +404,14 @@ /// Filling constructor RGBAf(float r, float g, float b, float a=1.f) : R(r), G(g), B(b), A(a) { } + // cppcheck-suppress noExplicitConstructor /// Constructor that sets all color channels to the given value to create a grayscale color. Alpha is set to 1.0f RGBAf(float lum, float a=1.0f) : RGBAf(lum, lum, lum, a) { } /// Constructor that sets all color channels to the given value to create a grayscale color. Alpha is set to 1.0f explicit RGBAf(double lum, float a=1.0f) : RGBAf((float)lum, (float)lum, (float)lum, a) { } + // cppcheck-suppress noExplicitConstructor /// Converts a RGBA to RGBAf RGBAf(const RGBA &color) : R(color.R/255.f), G(color.G/255.f), B(color.B/255.f), A(color.A/255.f) { } @@ -416,6 +421,7 @@ /// Converts a RGBA to RGBAf RGBAf(const RGBA &color, double alpha) : R(color.R/255.f), G(color.G/255.f), B(color.B/255.f), A(float(color.A/255. * alpha)) { } + // cppcheck-suppress noExplicitConstructor /// Converts from an unsigned int RGBAf(unsigned color) : RGBAf(RGBA(color)) { }
--- a/Source/Gorgon/IO/Stream.h Sun Jul 19 11:47:10 2020 +0300 +++ b/Source/Gorgon/IO/Stream.h Wed Aug 12 14:25:36 2020 +0300 @@ -81,6 +81,8 @@ static_assert(sizeof(float) == 4, "Current implementation only supports 32bit floats"); float r; + // cppcheck-suppress invalidPointerCast + //this is ok due to requirement of standard float and double is necessary for Gorgon library stream.read(reinterpret_cast<char*>(&r), 4); return r; @@ -92,6 +94,8 @@ static_assert(sizeof(double) == 8, "Current implementation only supports 64bit floats"); float r; + // cppcheck-suppress invalidPointerCast + //this is ok due to requirement of standard float and double is necessary for Gorgon library stream.read(reinterpret_cast<char*>(&r), 4); return r; @@ -233,6 +237,8 @@ inline void WriteFloat(std::ostream &stream, float value) { static_assert(sizeof(float) == 4, "Current implementation only supports 32bit floats"); + // cppcheck-suppress invalidPointerCast + //this is ok due to requirement of standard float and double is necessary for Gorgon library stream.write(reinterpret_cast<const char*>(&value), 4); } @@ -241,6 +247,8 @@ inline void WriteDouble(std::ostream &stream, double value) { static_assert(sizeof(double) == 8, "Current implementation only supports 64bit floats"); + // cppcheck-suppress invalidPointerCast + //this is ok due to requirement of standard float and double is necessary for Gorgon library stream.write(reinterpret_cast<const char*>(&value), 4); }
--- a/Source/Gorgon/SGuid.h Sun Jul 19 11:47:10 2020 +0300 +++ b/Source/Gorgon/SGuid.h Wed Aug 12 14:25:36 2020 +0300 @@ -37,10 +37,11 @@ /// Constructor to create a new guid. Use `Gorgon::SGuid guid{Gorgon::SGuid::CreateNew}` /// to create a new guid - SGuid(const CreateNewTag&) { + explicit SGuid(const CreateNewTag&) { New(); } + // cppcheck-suppress noExplicitConstructor /// Creates a new GUID from the given data SGuid(const Byte data[8]) { if(data==nullptr) { @@ -56,6 +57,7 @@ } } + // cppcheck-suppress noExplicitConstructor /// Creates a new GUID from the given data SGuid(unsigned long long data) { Integer=data; @@ -68,7 +70,7 @@ } /// Reads a new GUID from the given stream - SGuid(std::istream &in) { + explicit SGuid(std::istream &in) { Load(in); } @@ -199,10 +201,10 @@ c=tolower(c); if(c>='0' && c<='9') { - guid.Bytes[i/2]+=(c-'0')<<(i%2 ? 4 : 0); + guid.Bytes[i/2]+=(c-'0')<<((i%2) ? 4 : 0); } else if(c>='a' && c<='f') { - guid.Bytes[i/2]+=(c-'a'+10)<<(i%2 ? 4 : 0); + guid.Bytes[i/2]+=(c-'a'+10)<<((i%2) ? 4 : 0); } else if(c=='-' || c==' ' || c=='\t') i++;