X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgraphics%2Fbmploader.cpp;h=eb069a11dceea856174040ecf29427cbd36028f9;hb=3c5bbaeadb33d288c0f9e487b52904b7ed7e4319;hp=71de507d1f8b2681a76ddf3bf861a8677a4990e8;hpb=5715968065256daa4c43d5365cf5e268d75e007a;p=libs%2Fgui.git diff --git a/source/graphics/bmploader.cpp b/source/graphics/bmploader.cpp index 71de507..eb069a1 100644 --- a/source/graphics/bmploader.cpp +++ b/source/graphics/bmploader.cpp @@ -1,5 +1,5 @@ -#include #include "bmploader.h" +#include using namespace std; @@ -15,7 +15,7 @@ void read_full(Msp::IO::Base &io, char *buffer, unsigned size) template T decode(const char *data) { - const Msp::UInt8 *udata = reinterpret_cast(data); + const uint8_t *udata = reinterpret_cast(data); T result = 0; for(unsigned i=0; i(bm_header+10); + unsigned data_offset = decode(bm_header+10); char dib_header[124]; read_full(io, dib_header, 12); - unsigned dib_length = min(decode(dib_header), sizeof(dib_header)); + unsigned dib_length = min(decode(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(dib_header+4); - Int32 height = decode(dib_header+8); + data.width = decode(dib_header+4); + int32_t height = decode(dib_header+8); data.height = abs(height); - unsigned color_planes = decode(dib_header+12); + unsigned color_planes = decode(dib_header+12); if(color_planes!=1) throw bad_image_data("color_planes!=1"); - unsigned bits_per_pixel = decode(dib_header+14); - unsigned compression = decode(dib_header+16); + unsigned bits_per_pixel = decode(dib_header+14); + unsigned compression = decode(dib_header+16); if(compression) throw unsupported_image_format("compression not supported"); @@ -92,16 +92,20 @@ void BmpLoader::load(Image::Data &data) skip -= size; } - data.data = new char[data.stride*data.height]; - if(height<0) + invert_row_order = (height<0); +} + +void BmpLoader::load_pixels_(Image::Data &data) +{ + if(invert_row_order) { for(unsigned y=0; y