BmpLoader::BmpLoader(IO::Base &i, unsigned sb):
io(i),
- sig_bytes(sb)
+ sig_bytes(sb),
+ invert_row_order(false)
{
// Image data location is stored at offset 10 and can't be skipped
if(sig_bytes>10)
bool BmpLoader::detect(const std::string &sig)
{
- static const char bmp_sig[] = "BM";
+ static const char bmp_sig[] = { 'B', 'M' };
if(sig.size()<sizeof(bmp_sig))
return false;
return !sig.compare(0, sizeof(bmp_sig), bmp_sig, sizeof(bmp_sig));
}
-void BmpLoader::load(Image::Data &data)
+void BmpLoader::load_headers_(Image::Data &data)
{
char bm_header[14];
read_full(io, bm_header+sig_bytes, sizeof(bm_header)-sig_bytes);
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)
+{
+ data.pixels = new char[data.stride*data.height];
+ if(invert_row_order)
{
for(unsigned y=0; y<data.height; ++y)
- read_full(io, data.data+(data.height-1-y)*data.stride, data.stride);
+ read_full(io, data.pixels+(data.height-1-y)*data.stride, data.stride);
}
else
{
for(unsigned y=0; y<data.height; ++y)
- read_full(io, data.data+y*data.stride, data.stride);
+ read_full(io, data.pixels+y*data.stride, data.stride);
}
}