ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

bmp.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "image/bmp.h"
00024 
00025 #include "common/stream.h"
00026 #include "common/substream.h"
00027 #include "common/textconsole.h"
00028 #include "graphics/pixelformat.h"
00029 #include "graphics/surface.h"
00030 #include "image/codecs/codec.h"
00031 
00032 namespace Image {
00033 
00034 BitmapDecoder::BitmapDecoder() {
00035     _surface = 0;
00036     _palette = 0;
00037     _paletteColorCount = 0;
00038     _codec = 0;
00039 }
00040 
00041 BitmapDecoder::~BitmapDecoder() {
00042     destroy();
00043 }
00044 
00045 void BitmapDecoder::destroy() {
00046     _surface = 0;
00047 
00048     delete[] _palette;
00049     _palette = 0;
00050 
00051     _paletteColorCount = 0;
00052 
00053     delete _codec;
00054     _codec = 0;
00055 }
00056 
00057 bool BitmapDecoder::loadStream(Common::SeekableReadStream &stream) {
00058     destroy();
00059 
00060     if (stream.readByte() != 'B')
00061         return false;
00062 
00063     if (stream.readByte() != 'M')
00064         return false;
00065 
00066     /* uint32 fileSize = */ stream.readUint32LE();
00067     /* uint16 res1 = */ stream.readUint16LE();
00068     /* uint16 res2 = */ stream.readUint16LE();
00069     uint32 imageOffset = stream.readUint32LE();
00070 
00071     uint32 infoSize = stream.readUint32LE();
00072     if (infoSize != 40) {
00073         warning("Only Windows v3 bitmaps are supported");
00074         return false;
00075     }
00076 
00077     uint32 width = stream.readUint32LE();
00078     int32 height = stream.readSint32LE();
00079 
00080     if (width == 0 || height == 0)
00081         return false;
00082 
00083     if (height < 0) {
00084         warning("Right-side up bitmaps not supported");
00085         return false;
00086     }
00087 
00088     /* uint16 planes = */ stream.readUint16LE();
00089     uint16 bitsPerPixel = stream.readUint16LE();
00090 
00091     if (bitsPerPixel != 8 && bitsPerPixel != 24 && bitsPerPixel != 32) {
00092         warning("%dbpp bitmaps not supported", bitsPerPixel);
00093         return false;
00094     }
00095 
00096     uint32 compression = stream.readUint32BE();
00097     uint32 imageSize = stream.readUint32LE();
00098     /* uint32 pixelsPerMeterX = */ stream.readUint32LE();
00099     /* uint32 pixelsPerMeterY = */ stream.readUint32LE();
00100     _paletteColorCount = stream.readUint32LE();
00101     /* uint32 colorsImportant = */ stream.readUint32LE();
00102 
00103     if (bitsPerPixel == 8) {
00104         if (_paletteColorCount == 0)
00105             _paletteColorCount = 256;
00106 
00107         // Read the palette
00108         _palette = new byte[_paletteColorCount * 3];
00109         for (uint16 i = 0; i < _paletteColorCount; i++) {
00110             _palette[i * 3 + 2] = stream.readByte();
00111             _palette[i * 3 + 1] = stream.readByte();
00112             _palette[i * 3 + 0] = stream.readByte();
00113             stream.readByte();
00114         }
00115     }
00116 
00117     // Create the codec (it will warn about unhandled compression)
00118     _codec = createBitmapCodec(compression, width, height, bitsPerPixel);
00119     if (!_codec)
00120         return false;
00121 
00122     // If the image size is zero, set it to the rest of the stream.
00123     if (imageSize == 0)
00124         imageSize = stream.size() - imageOffset;
00125 
00126     // Grab the frame data
00127     Common::SeekableSubReadStream subStream(&stream, imageOffset, imageOffset + imageSize);
00128 
00129     // We only support raw bitmaps for now
00130     _surface = _codec->decodeFrame(subStream);
00131 
00132     return true;
00133 }
00134 
00135 } // End of namespace Image


Generated on Sat Feb 16 2019 05:00:46 for ResidualVM by doxygen 1.7.1
curved edge   curved edge