]> git.tdb.fi Git - libs/gui.git/blobdiff - source/graphics/bmploader.cpp
Use default member initializers and defaulted default constructors
[libs/gui.git] / source / graphics / bmploader.cpp
index d88e2aa6435f36f3c908bf3c274a9799a5b2339e..b85cce16b1d28392e1b4ad72c2b9724204405c2c 100644 (file)
@@ -1,5 +1,5 @@
-#include <msp/core/inttypes.h>
 #include "bmploader.h"
+#include <cstdint>
 
 using namespace std;
 
@@ -15,7 +15,7 @@ void read_full(Msp::IO::Base &io, char *buffer, unsigned size)
 template<typename T>
 T decode(const char *data)
 {
-       const Msp::UInt8 *udata = reinterpret_cast<const Msp::UInt8 *>(data);
+       const uint8_t *udata = reinterpret_cast<const uint8_t *>(data);
        T result = 0;
        for(unsigned i=0; i<sizeof(T); ++i)
                result |= udata[i]<<(i*8);
@@ -29,8 +29,7 @@ namespace Graphics {
 
 BmpLoader::BmpLoader(IO::Base &i, unsigned sb):
        io(i),
-       sig_bytes(sb),
-       invert_row_order(false)
+       sig_bytes(sb)
 {
        // Image data location is stored at offset 10 and can't be skipped
        if(sig_bytes>10)
@@ -53,25 +52,25 @@ void BmpLoader::load_headers_(Image::Data &data)
        if(!sig_bytes && (bm_header[0]!='B' || bm_header[1]!='M'))
                throw bad_image_data("bitmap header mismatch");
 
-       unsigned data_offset = decode<UInt32>(bm_header+10);
+       unsigned data_offset = decode<uint32_t>(bm_header+10);
 
        char dib_header[124];
        read_full(io, dib_header, 12);
-       unsigned dib_length = min<unsigned>(decode<UInt32>(dib_header), sizeof(dib_header));
+       unsigned dib_length = min<unsigned>(decode<uint32_t>(dib_header), sizeof(dib_header));
        if(dib_length<40)
                throw bad_image_data("DIB header too short (very old bmp file?)");
 
        read_full(io, dib_header+12, dib_length-12);
 
-       data.width = decode<UInt32>(dib_header+4);
-       Int32 height = decode<UInt32>(dib_header+8);
+       data.width = decode<uint32_t>(dib_header+4);
+       int32_t height = decode<uint32_t>(dib_header+8);
        data.height = abs(height);
 
-       unsigned color_planes = decode<UInt16>(dib_header+12);
+       unsigned color_planes = decode<uint16_t>(dib_header+12);
        if(color_planes!=1)
                throw bad_image_data("color_planes!=1");
-       unsigned bits_per_pixel = decode<UInt16>(dib_header+14);
-       unsigned compression = decode<UInt32>(dib_header+16);
+       unsigned bits_per_pixel = decode<uint16_t>(dib_header+14);
+       unsigned compression = decode<uint32_t>(dib_header+16);
        if(compression)
                throw unsupported_image_format("compression not supported");
 
@@ -98,7 +97,6 @@ void BmpLoader::load_headers_(Image::Data &data)
 
 void BmpLoader::load_pixels_(Image::Data &data)
 {
-       data.pixels = new char[data.stride*data.height];
        if(invert_row_order)
        {
                for(unsigned y=0; y<data.height; ++y)