2007-03-22 10:30:00 -07:00
|
|
|
/* vim:set tw=80 expandtab softtabstop=4 ts=4 sw=4: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
/* I got the format description from http://www.daubnet.com/formats/BMP.html */
|
|
|
|
|
|
|
|
/* This is a Cross-Platform BMP Decoder, which should work everywhere, including
|
|
|
|
* Big-Endian machines like the PowerPC. */
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-04-03 14:57:22 -07:00
|
|
|
#include "ImageLogging.h"
|
2013-09-05 15:55:13 -07:00
|
|
|
#include "mozilla/Endian.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsBMPDecoder.h"
|
|
|
|
|
|
|
|
#include "nsIInputStream.h"
|
2010-08-13 21:09:49 -07:00
|
|
|
#include "RasterImage.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-13 21:09:49 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef PR_LOGGING
|
2012-10-29 16:32:10 -07:00
|
|
|
static PRLogModuleInfo *
|
|
|
|
GetBMPLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sBMPLog;
|
|
|
|
if (!sBMPLog)
|
|
|
|
sBMPLog = PR_NewLogModule("BMPDecoder");
|
|
|
|
return sBMPLog;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2007-07-17 14:08:46 -07:00
|
|
|
// Convert from row (1..height) to absolute line (0..height-1)
|
|
|
|
#define LINE(row) ((mBIH.height < 0) ? (-mBIH.height - (row)) : ((row) - 1))
|
|
|
|
#define PIXEL_OFFSET(row, col) (LINE(row) * mBIH.width + col)
|
|
|
|
|
2013-01-18 13:47:18 -08:00
|
|
|
nsBMPDecoder::nsBMPDecoder(RasterImage &aImage)
|
|
|
|
: Decoder(aImage)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mColors = nullptr;
|
|
|
|
mRow = nullptr;
|
2011-09-27 09:24:03 -07:00
|
|
|
mCurPos = mPos = mNumColors = mRowBytes = 0;
|
|
|
|
mOldLine = mCurLine = 1; // Otherwise decoder will never start
|
|
|
|
mState = eRLEStateInitial;
|
|
|
|
mStateData = 0;
|
2012-07-17 07:20:14 -07:00
|
|
|
mLOH = WIN_V3_HEADER_LENGTH;
|
2011-10-17 07:59:28 -07:00
|
|
|
mUseAlphaData = mHaveAlphaData = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsBMPDecoder::~nsBMPDecoder()
|
|
|
|
{
|
2009-09-12 15:44:18 -07:00
|
|
|
delete[] mColors;
|
2011-08-25 13:09:01 -07:00
|
|
|
if (mRow) {
|
|
|
|
moz_free(mRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sets whether or not the BMP will use alpha data
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsBMPDecoder::SetUseAlphaData(bool useAlphaData)
|
2011-08-25 13:09:01 -07:00
|
|
|
{
|
|
|
|
mUseAlphaData = useAlphaData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the bits per pixel from the internal BIH header
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2011-08-25 13:09:01 -07:00
|
|
|
nsBMPDecoder::GetBitsPerPixel() const
|
|
|
|
{
|
|
|
|
return mBIH.bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the width from the internal BIH header
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2011-08-25 13:09:01 -07:00
|
|
|
nsBMPDecoder::GetWidth() const
|
|
|
|
{
|
|
|
|
return mBIH.width;
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:20:57 -07:00
|
|
|
// Obtains the abs-value of the height from the internal BIH header
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2011-08-25 13:09:01 -07:00
|
|
|
nsBMPDecoder::GetHeight() const
|
|
|
|
{
|
2012-07-23 13:20:57 -07:00
|
|
|
return abs(mBIH.height);
|
2011-08-25 13:09:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the internal output image buffer
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t*
|
2011-08-25 13:09:01 -07:00
|
|
|
nsBMPDecoder::GetImageData()
|
|
|
|
{
|
2013-01-28 09:26:36 -08:00
|
|
|
return reinterpret_cast<uint32_t*>(mImageData);
|
2011-08-25 13:09:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtains the size of the compressed image resource
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2011-08-25 13:09:01 -07:00
|
|
|
nsBMPDecoder::GetCompressedImageSize() const
|
|
|
|
{
|
|
|
|
// For everything except BI_RGB the header field must be defined
|
|
|
|
if (mBIH.compression != BI_RGB) {
|
|
|
|
return mBIH.image_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mBIH.image_size isn't always filled for BI_RGB so calculate it manually
|
|
|
|
// The pixel array size is calculated based on extra 4 byte boundary padding
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t rowSize = (mBIH.bpp * mBIH.width + 7) / 8; // + 7 to round up
|
2011-08-25 13:09:01 -07:00
|
|
|
// Pad to DWORD Boundary
|
|
|
|
if (rowSize % 4) {
|
|
|
|
rowSize += (4 - (rowSize % 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The height should be the absolute value of what the height is in the BIH.
|
|
|
|
// If positive the bitmap is stored bottom to top, otherwise top to bottom
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t pixelArraySize = rowSize * GetHeight();
|
2011-08-25 13:09:01 -07:00
|
|
|
return pixelArraySize;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-09 08:24:23 -07:00
|
|
|
// Obtains whether or not a BMP file had alpha data in its 4th byte
|
|
|
|
// for 32BPP bitmaps. Only use after the bitmap has been processed.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-09-09 08:24:23 -07:00
|
|
|
nsBMPDecoder::HasAlphaData() const
|
|
|
|
{
|
|
|
|
return mHaveAlphaData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-12 08:22:30 -07:00
|
|
|
void
|
2010-08-22 19:30:46 -07:00
|
|
|
nsBMPDecoder::FinishInternal()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-12 08:22:31 -07:00
|
|
|
// We shouldn't be called in error cases
|
2010-09-12 08:22:31 -07:00
|
|
|
NS_ABORT_IF_FALSE(!HasError(), "Can't call FinishInternal on error!");
|
2010-09-12 08:22:31 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
// We should never make multiple frames
|
|
|
|
NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple BMP frames?");
|
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// Send notifications if appropriate
|
2013-02-27 11:23:08 -08:00
|
|
|
if (!IsSizeDecode() && HasSize()) {
|
2011-08-25 13:09:01 -07:00
|
|
|
|
|
|
|
// Invalidate
|
2012-07-23 13:20:57 -07:00
|
|
|
nsIntRect r(0, 0, mBIH.width, GetHeight());
|
2011-08-25 13:09:01 -07:00
|
|
|
PostInvalidation(r);
|
|
|
|
|
2013-02-01 17:06:30 -08:00
|
|
|
if (mUseAlphaData) {
|
2013-06-17 13:49:04 -07:00
|
|
|
PostFrameStop(FrameBlender::kFrameHasAlpha);
|
2013-02-01 17:06:30 -08:00
|
|
|
} else {
|
2013-06-17 13:49:04 -07:00
|
|
|
PostFrameStop(FrameBlender::kFrameOpaque);
|
2013-02-01 17:06:30 -08:00
|
|
|
}
|
2010-09-12 08:22:30 -07:00
|
|
|
PostDecodeDone();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------
|
|
|
|
// Actual Data Processing
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static void calcBitmask(uint32_t aMask, uint8_t& aBegin, uint8_t& aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// find the rightmost 1
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t pos;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool started = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
aBegin = aLength = 0;
|
|
|
|
for (pos = 0; pos <= 31; pos++) {
|
|
|
|
if (!started && (aMask & (1 << pos))) {
|
|
|
|
aBegin = pos;
|
2011-10-17 07:59:28 -07:00
|
|
|
started = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (started && !(aMask & (1 << pos))) {
|
|
|
|
aLength = pos - aBegin;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD nsBMPDecoder::CalcBitShift()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t begin, length;
|
2007-03-22 10:30:00 -07:00
|
|
|
// red
|
|
|
|
calcBitmask(mBitFields.red, begin, length);
|
|
|
|
mBitFields.redRightShift = begin;
|
|
|
|
mBitFields.redLeftShift = 8 - length;
|
|
|
|
// green
|
|
|
|
calcBitmask(mBitFields.green, begin, length);
|
|
|
|
mBitFields.greenRightShift = begin;
|
|
|
|
mBitFields.greenLeftShift = 8 - length;
|
|
|
|
// blue
|
|
|
|
calcBitmask(mBitFields.blue, begin, length);
|
|
|
|
mBitFields.blueRightShift = begin;
|
|
|
|
mBitFields.blueLeftShift = 8 - length;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-12 08:22:30 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsBMPDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-12 08:22:31 -07:00
|
|
|
NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
|
2009-10-15 19:54:44 -07:00
|
|
|
|
|
|
|
// aCount=0 means EOF, mCurLine=0 means we're past end of image
|
|
|
|
if (!aCount || !mCurLine)
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-08-25 13:09:01 -07:00
|
|
|
if (mPos < BFH_INTERNAL_LENGTH) { /* In BITMAPFILEHEADER */
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t toCopy = BFH_INTERNAL_LENGTH - mPos;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (toCopy > aCount)
|
|
|
|
toCopy = aCount;
|
|
|
|
memcpy(mRawBuf + mPos, aBuffer, toCopy);
|
|
|
|
mPos += toCopy;
|
|
|
|
aCount -= toCopy;
|
|
|
|
aBuffer += toCopy;
|
|
|
|
}
|
2011-08-25 13:09:01 -07:00
|
|
|
if (mPos == BFH_INTERNAL_LENGTH) {
|
2007-03-22 10:30:00 -07:00
|
|
|
ProcessFileHeader();
|
2009-10-15 19:54:44 -07:00
|
|
|
if (mBFH.signature[0] != 'B' || mBFH.signature[1] != 'M') {
|
2010-09-12 08:22:27 -07:00
|
|
|
PostDataError();
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2009-10-15 19:54:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mBFH.bihsize == OS2_BIH_LENGTH)
|
|
|
|
mLOH = OS2_HEADER_LENGTH;
|
|
|
|
}
|
2011-08-25 13:09:01 -07:00
|
|
|
if (mPos >= BFH_INTERNAL_LENGTH && mPos < mLOH) { /* In BITMAPINFOHEADER */
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t toCopy = mLOH - mPos;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (toCopy > aCount)
|
|
|
|
toCopy = aCount;
|
2011-08-25 13:09:01 -07:00
|
|
|
memcpy(mRawBuf + (mPos - BFH_INTERNAL_LENGTH), aBuffer, toCopy);
|
2007-03-22 10:30:00 -07:00
|
|
|
mPos += toCopy;
|
|
|
|
aCount -= toCopy;
|
|
|
|
aBuffer += toCopy;
|
|
|
|
}
|
2011-08-25 13:09:01 -07:00
|
|
|
|
2013-02-27 11:23:08 -08:00
|
|
|
// HasSize is called to ensure that if at this point mPos == mLOH but
|
2011-08-25 13:09:01 -07:00
|
|
|
// we have no data left to process, the next time WriteInternal is called
|
|
|
|
// we won't enter this condition again.
|
2013-02-27 11:23:08 -08:00
|
|
|
if (mPos == mLOH && !HasSize()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
ProcessInfoHeader();
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetBMPLog(), PR_LOG_DEBUG, ("BMP is %lix%lix%lu. compression=%lu\n",
|
2011-08-25 13:09:01 -07:00
|
|
|
mBIH.width, mBIH.height, mBIH.bpp, mBIH.compression));
|
2007-03-22 10:30:00 -07:00
|
|
|
// Verify we support this bit depth
|
|
|
|
if (mBIH.bpp != 1 && mBIH.bpp != 4 && mBIH.bpp != 8 &&
|
2009-10-15 19:54:44 -07:00
|
|
|
mBIH.bpp != 16 && mBIH.bpp != 24 && mBIH.bpp != 32) {
|
2010-09-12 08:22:27 -07:00
|
|
|
PostDataError();
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2009-10-15 19:54:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-12 15:44:18 -07:00
|
|
|
// BMPs with negative width are invalid
|
|
|
|
// Reject extremely wide images to keep the math sane
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t k64KWidth = 0x0000FFFF;
|
2009-10-15 19:54:44 -07:00
|
|
|
if (mBIH.width < 0 || mBIH.width > k64KWidth) {
|
2010-09-12 08:22:27 -07:00
|
|
|
PostDataError();
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2009-10-15 19:54:44 -07:00
|
|
|
}
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2013-07-30 17:49:41 -07:00
|
|
|
if (mBIH.height == INT_MIN) {
|
|
|
|
PostDataError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t real_height = GetHeight();
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
// Post our size to the superclass
|
|
|
|
PostSize(mBIH.width, real_height);
|
2011-05-11 02:46:59 -07:00
|
|
|
if (HasError()) {
|
2012-05-19 12:32:37 -07:00
|
|
|
// Setting the size led to an error.
|
2011-05-11 02:46:59 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
// We have the size. If we're doing a size decode, we got what
|
2009-09-12 15:44:18 -07:00
|
|
|
// we came for.
|
2010-08-22 19:30:46 -07:00
|
|
|
if (IsSizeDecode())
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2009-09-12 15:44:18 -07:00
|
|
|
|
|
|
|
// We're doing a real decode.
|
|
|
|
mOldLine = mCurLine = real_height;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mBIH.bpp <= 8) {
|
|
|
|
mNumColors = 1 << mBIH.bpp;
|
|
|
|
if (mBIH.colors && mBIH.colors < mNumColors)
|
|
|
|
mNumColors = mBIH.colors;
|
|
|
|
|
2007-12-13 13:49:05 -08:00
|
|
|
// Always allocate 256 even though mNumColors might be smaller
|
|
|
|
mColors = new colorTable[256];
|
|
|
|
memset(mColors, 0, 256 * sizeof(colorTable));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (mBIH.compression != BI_BITFIELDS && mBIH.bpp == 16) {
|
|
|
|
// Use default 5-5-5 format
|
|
|
|
mBitFields.red = 0x7C00;
|
|
|
|
mBitFields.green = 0x03E0;
|
|
|
|
mBitFields.blue = 0x001F;
|
|
|
|
CalcBitShift();
|
|
|
|
}
|
2007-07-17 14:08:46 -07:00
|
|
|
|
2011-08-25 13:09:01 -07:00
|
|
|
// Make sure we have a valid value for our supported compression modes
|
|
|
|
// before adding the frame
|
|
|
|
if (mBIH.compression != BI_RGB && mBIH.compression != BI_RLE8 &&
|
|
|
|
mBIH.compression != BI_RLE4 && mBIH.compression != BI_BITFIELDS) {
|
|
|
|
PostDataError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have RLE4 or RLE8 or BI_ALPHABITFIELDS, then ensure we
|
|
|
|
// have valid BPP values before adding the frame
|
|
|
|
if (mBIH.compression == BI_RLE8 && mBIH.bpp != 8) {
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
|
2011-08-25 13:09:01 -07:00
|
|
|
("BMP RLE8 compression only supports 8 bits per pixel\n"));
|
|
|
|
PostDataError();
|
|
|
|
return;
|
|
|
|
}
|
2011-08-31 12:11:04 -07:00
|
|
|
if (mBIH.compression == BI_RLE4 && mBIH.bpp != 4 && mBIH.bpp != 1) {
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
|
2011-08-25 13:09:01 -07:00
|
|
|
("BMP RLE4 compression only supports 4 bits per pixel\n"));
|
|
|
|
PostDataError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mBIH.compression == BI_ALPHABITFIELDS &&
|
|
|
|
mBIH.bpp != 16 && mBIH.bpp != 32) {
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetBMPLog(), PR_LOG_DEBUG,
|
2011-08-25 13:09:01 -07:00
|
|
|
("BMP ALPHABITFIELDS only supports 16 or 32 bits per pixel\n"));
|
|
|
|
PostDataError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-01 17:06:30 -08:00
|
|
|
if (mBIH.compression != BI_RLE8 && mBIH.compression != BI_RLE4 &&
|
|
|
|
mBIH.compression != BI_ALPHABITFIELDS) {
|
2007-07-17 14:08:46 -07:00
|
|
|
// mRow is not used for RLE encoded images
|
2012-08-22 08:56:38 -07:00
|
|
|
mRow = (uint8_t*)moz_malloc((mBIH.width * mBIH.bpp) / 8 + 4);
|
2011-08-25 13:09:01 -07:00
|
|
|
// + 4 because the line is padded to a 4 bit boundary, but I don't want
|
2007-07-17 14:08:46 -07:00
|
|
|
// to make exact calculations here, that's unnecessary.
|
|
|
|
// Also, it compensates rounding error.
|
|
|
|
if (!mRow) {
|
2013-02-01 17:06:30 -08:00
|
|
|
PostDataError();
|
|
|
|
return;
|
2011-08-25 13:09:01 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-02-01 17:06:30 -08:00
|
|
|
if (!mImageData) {
|
2010-09-12 08:22:27 -07:00
|
|
|
PostDecoderError(NS_ERROR_FAILURE);
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2009-10-15 19:54:44 -07:00
|
|
|
}
|
2007-07-17 14:08:46 -07:00
|
|
|
|
2011-08-25 13:09:01 -07:00
|
|
|
// Prepare for transparency
|
2007-07-17 14:08:46 -07:00
|
|
|
if ((mBIH.compression == BI_RLE8) || (mBIH.compression == BI_RLE4)) {
|
|
|
|
// Clear the image, as the RLE may jump over areas
|
2013-02-01 17:06:30 -08:00
|
|
|
memset(mImageData, 0, mImageDataLength);
|
2007-07-17 14:08:46 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-16 07:14:40 -08:00
|
|
|
|
|
|
|
if (mColors && mPos >= mLOH) {
|
|
|
|
// OS/2 Bitmaps have no padding byte
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t bytesPerColor = (mBFH.bihsize == OS2_BIH_LENGTH) ? 3 : 4;
|
2011-11-16 07:14:40 -08:00
|
|
|
if (mPos < (mLOH + mNumColors * bytesPerColor)) {
|
|
|
|
// Number of bytes already received
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t colorBytes = mPos - mLOH;
|
2011-11-16 07:14:40 -08:00
|
|
|
// Color which is currently received
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t colorNum = colorBytes / bytesPerColor;
|
|
|
|
uint8_t at = colorBytes % bytesPerColor;
|
2011-11-16 07:14:40 -08:00
|
|
|
while (aCount && (mPos < (mLOH + mNumColors * bytesPerColor))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (at) {
|
|
|
|
case 0:
|
|
|
|
mColors[colorNum].blue = *aBuffer;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mColors[colorNum].green = *aBuffer;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
mColors[colorNum].red = *aBuffer;
|
2011-11-27 12:18:17 -08:00
|
|
|
// If there is no padding byte, increment the color index
|
|
|
|
// since we're done with the current color.
|
|
|
|
if (bytesPerColor == 3)
|
|
|
|
colorNum++;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case 3:
|
2011-11-27 12:18:17 -08:00
|
|
|
// This is a padding byte only in Windows BMPs. Increment
|
|
|
|
// the color index since we're done with the current color.
|
|
|
|
colorNum++;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
mPos++; aBuffer++; aCount--;
|
2011-11-16 07:14:40 -08:00
|
|
|
at = (at + 1) % bytesPerColor;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-11-16 07:14:40 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-07-17 07:20:14 -07:00
|
|
|
else if (aCount && mBIH.compression == BI_BITFIELDS && mPos < (WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// If compression is used, this is a windows bitmap, hence we can
|
|
|
|
// use WIN_HEADER_LENGTH instead of mLOH
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t toCopy = (WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH) - mPos;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (toCopy > aCount)
|
|
|
|
toCopy = aCount;
|
2012-07-17 07:20:14 -07:00
|
|
|
memcpy(mRawBuf + (mPos - WIN_V3_HEADER_LENGTH), aBuffer, toCopy);
|
2007-03-22 10:30:00 -07:00
|
|
|
mPos += toCopy;
|
|
|
|
aBuffer += toCopy;
|
|
|
|
aCount -= toCopy;
|
|
|
|
}
|
2012-07-17 07:20:14 -07:00
|
|
|
if (mPos == WIN_V3_HEADER_LENGTH + BITFIELD_LENGTH &&
|
2012-01-23 15:28:58 -08:00
|
|
|
mBIH.compression == BI_BITFIELDS) {
|
2013-09-05 15:55:13 -07:00
|
|
|
mBitFields.red = LittleEndian::readUint32(reinterpret_cast<uint32_t*>(mRawBuf));
|
|
|
|
mBitFields.green = LittleEndian::readUint32(reinterpret_cast<uint32_t*>(mRawBuf + 4));
|
|
|
|
mBitFields.blue = LittleEndian::readUint32(reinterpret_cast<uint32_t*>(mRawBuf + 8));
|
2007-03-22 10:30:00 -07:00
|
|
|
CalcBitShift();
|
|
|
|
}
|
|
|
|
while (aCount && (mPos < mBFH.dataoffset)) { // Skip whatever is between header and data
|
|
|
|
mPos++; aBuffer++; aCount--;
|
|
|
|
}
|
|
|
|
if (aCount && ++mPos >= mBFH.dataoffset) {
|
|
|
|
// Need to increment mPos, else we might get to mPos==mLOH again
|
|
|
|
// From now on, mPos is irrelevant
|
|
|
|
if (!mBIH.compression || mBIH.compression == BI_BITFIELDS) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t rowSize = (mBIH.bpp * mBIH.width + 7) / 8; // + 7 to round up
|
2011-08-25 13:09:01 -07:00
|
|
|
if (rowSize % 4) {
|
2007-03-22 10:30:00 -07:00
|
|
|
rowSize += (4 - (rowSize % 4)); // Pad to DWORD Boundary
|
2011-08-25 13:09:01 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t toCopy;
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
toCopy = rowSize - mRowBytes;
|
|
|
|
if (toCopy) {
|
|
|
|
if (toCopy > aCount)
|
|
|
|
toCopy = aCount;
|
|
|
|
memcpy(mRow + mRowBytes, aBuffer, toCopy);
|
|
|
|
aCount -= toCopy;
|
|
|
|
aBuffer += toCopy;
|
|
|
|
mRowBytes += toCopy;
|
|
|
|
}
|
2007-07-17 14:08:46 -07:00
|
|
|
if (rowSize == mRowBytes) {
|
|
|
|
// Collected a whole row into mRow, process it
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t* p = mRow;
|
2013-01-28 09:26:36 -08:00
|
|
|
uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) + PIXEL_OFFSET(mCurLine, 0);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t lpos = mBIH.width;
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (mBIH.bpp) {
|
|
|
|
case 1:
|
|
|
|
while (lpos > 0) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t bit;
|
|
|
|
uint8_t idx;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (bit = 7; bit >= 0 && lpos > 0; bit--) {
|
|
|
|
idx = (*p >> bit) & 1;
|
|
|
|
SetPixel(d, idx, mColors);
|
|
|
|
--lpos;
|
|
|
|
}
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
while (lpos > 0) {
|
|
|
|
Set4BitPixel(d, *p, lpos, mColors);
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
while (lpos > 0) {
|
|
|
|
SetPixel(d, *p, mColors);
|
|
|
|
--lpos;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
while (lpos > 0) {
|
2013-09-05 15:55:13 -07:00
|
|
|
uint16_t val = LittleEndian::readUint16(reinterpret_cast<uint16_t*>(p));
|
2007-03-22 10:30:00 -07:00
|
|
|
SetPixel(d,
|
|
|
|
(val & mBitFields.red) >> mBitFields.redRightShift << mBitFields.redLeftShift,
|
|
|
|
(val & mBitFields.green) >> mBitFields.greenRightShift << mBitFields.greenLeftShift,
|
|
|
|
(val & mBitFields.blue) >> mBitFields.blueRightShift << mBitFields.blueLeftShift);
|
|
|
|
--lpos;
|
|
|
|
p+=2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
while (lpos > 0) {
|
|
|
|
SetPixel(d, p[2], p[1], p[0]);
|
|
|
|
p += 2;
|
|
|
|
--lpos;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
break;
|
2011-08-25 13:09:01 -07:00
|
|
|
case 32:
|
|
|
|
while (lpos > 0) {
|
|
|
|
if (mUseAlphaData) {
|
2011-09-09 08:24:23 -07:00
|
|
|
if (!mHaveAlphaData && p[3]) {
|
|
|
|
// Non-zero alpha byte detected! Clear previous
|
|
|
|
// pixels that we have already processed.
|
|
|
|
// This works because we know that if we
|
|
|
|
// are reaching here then the alpha data in byte
|
|
|
|
// 4 has been right all along. And we know it
|
|
|
|
// has been set to 0 the whole time, so that
|
|
|
|
// means that everything is transparent so far.
|
2013-01-28 09:26:36 -08:00
|
|
|
uint32_t* start = reinterpret_cast<uint32_t*>(mImageData) + GetWidth() * (mCurLine - 1);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t heightDifference = GetHeight() - mCurLine + 1;
|
|
|
|
uint32_t pixelCount = GetWidth() * heightDifference;
|
2012-07-23 13:20:57 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
memset(start, 0, pixelCount * sizeof(uint32_t));
|
2012-07-23 13:20:57 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mHaveAlphaData = true;
|
2011-09-09 08:24:23 -07:00
|
|
|
}
|
|
|
|
SetPixel(d, p[2], p[1], p[0], mHaveAlphaData ? p[3] : 0xFF);
|
|
|
|
} else {
|
2011-08-25 13:09:01 -07:00
|
|
|
SetPixel(d, p[2], p[1], p[0]);
|
|
|
|
}
|
|
|
|
p += 4;
|
|
|
|
--lpos;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unsupported color depth, but earlier check didn't catch it");
|
|
|
|
}
|
2007-07-17 14:08:46 -07:00
|
|
|
mCurLine --;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCurLine == 0) { // Finished last line
|
2011-08-25 13:09:01 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
mRowBytes = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
} while (aCount > 0);
|
2011-08-25 13:09:01 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if ((mBIH.compression == BI_RLE8) || (mBIH.compression == BI_RLE4)) {
|
2011-08-25 13:09:01 -07:00
|
|
|
if (((mBIH.compression == BI_RLE8) && (mBIH.bpp != 8)) ||
|
|
|
|
((mBIH.compression == BI_RLE4) && (mBIH.bpp != 4) && (mBIH.bpp != 1))) {
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetBMPLog(), PR_LOG_DEBUG, ("BMP RLE8/RLE4 compression only supports 8/4 bits per pixel\n"));
|
2011-08-25 13:09:01 -07:00
|
|
|
PostDataError();
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
while (aCount > 0) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t byte;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch(mState) {
|
|
|
|
case eRLEStateInitial:
|
2012-08-22 08:56:38 -07:00
|
|
|
mStateData = (uint8_t)*aBuffer++;
|
2007-03-22 10:30:00 -07:00
|
|
|
aCount--;
|
|
|
|
|
|
|
|
mState = eRLEStateNeedSecondEscapeByte;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case eRLEStateNeedSecondEscapeByte:
|
|
|
|
byte = *aBuffer++;
|
|
|
|
aCount--;
|
|
|
|
if (mStateData != RLE_ESCAPE) { // encoded mode
|
|
|
|
// Encoded mode consists of two bytes:
|
|
|
|
// the first byte (mStateData) specifies the
|
|
|
|
// number of consecutive pixels to be drawn
|
|
|
|
// using the color index contained in
|
|
|
|
// the second byte
|
|
|
|
// Work around bitmaps that specify too many pixels
|
2007-07-17 14:08:46 -07:00
|
|
|
mState = eRLEStateInitial;
|
2013-01-15 04:22:03 -08:00
|
|
|
uint32_t pixelsNeeded = std::min<uint32_t>(mBIH.width - mCurPos, mStateData);
|
2007-07-17 14:08:46 -07:00
|
|
|
if (pixelsNeeded) {
|
2013-01-28 09:26:36 -08:00
|
|
|
uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) + PIXEL_OFFSET(mCurLine, mCurPos);
|
2007-07-17 14:08:46 -07:00
|
|
|
mCurPos += pixelsNeeded;
|
|
|
|
if (mBIH.compression == BI_RLE8) {
|
|
|
|
do {
|
|
|
|
SetPixel(d, byte, mColors);
|
|
|
|
pixelsNeeded --;
|
|
|
|
} while (pixelsNeeded);
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
Set4BitPixel(d, byte, pixelsNeeded, mColors);
|
|
|
|
} while (pixelsNeeded);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(byte) {
|
|
|
|
case RLE_ESCAPE_EOL:
|
2007-07-17 14:08:46 -07:00
|
|
|
// End of Line: Go to next row
|
|
|
|
mCurLine --;
|
|
|
|
mCurPos = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
mState = eRLEStateInitial;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RLE_ESCAPE_EOF: // EndOfFile
|
2007-07-17 14:08:46 -07:00
|
|
|
mCurPos = mCurLine = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RLE_ESCAPE_DELTA:
|
|
|
|
mState = eRLEStateNeedXDelta;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default : // absolute mode
|
|
|
|
// Save the number of pixels to read
|
|
|
|
mStateData = byte;
|
2012-08-22 08:56:38 -07:00
|
|
|
if (mCurPos + mStateData > (uint32_t)mBIH.width) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// We can work around bitmaps that specify one
|
|
|
|
// pixel too many, but only if their width is odd.
|
|
|
|
mStateData -= mBIH.width & 1;
|
2012-08-22 08:56:38 -07:00
|
|
|
if (mCurPos + mStateData > (uint32_t)mBIH.width) {
|
2010-09-12 08:22:27 -07:00
|
|
|
PostDataError();
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2009-10-15 19:54:44 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// See if we will need to skip a byte
|
|
|
|
// to word align the pixel data
|
|
|
|
// mStateData is a number of pixels
|
|
|
|
// so allow for the RLE compression type
|
|
|
|
// Pixels RLE8=1 RLE4=2
|
|
|
|
// 1 Pad Pad
|
|
|
|
// 2 No Pad
|
|
|
|
// 3 Pad No
|
|
|
|
// 4 No No
|
|
|
|
if (((mStateData - 1) & mBIH.compression) != 0)
|
|
|
|
mState = eRLEStateAbsoluteMode;
|
|
|
|
else
|
|
|
|
mState = eRLEStateAbsoluteModePadded;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eRLEStateNeedXDelta:
|
|
|
|
// Handle the XDelta and proceed to get Y Delta
|
|
|
|
byte = *aBuffer++;
|
|
|
|
aCount--;
|
2007-07-17 14:08:46 -07:00
|
|
|
mCurPos += byte;
|
|
|
|
if (mCurPos > mBIH.width)
|
|
|
|
mCurPos = mBIH.width;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mState = eRLEStateNeedYDelta;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case eRLEStateNeedYDelta:
|
|
|
|
// Get the Y Delta and then "handle" the move
|
|
|
|
byte = *aBuffer++;
|
|
|
|
aCount--;
|
|
|
|
mState = eRLEStateInitial;
|
2013-01-15 04:22:03 -08:00
|
|
|
mCurLine -= std::min<int32_t>(byte, mCurLine);
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eRLEStateAbsoluteMode: // Absolute Mode
|
|
|
|
case eRLEStateAbsoluteModePadded:
|
2007-07-17 14:08:46 -07:00
|
|
|
if (mStateData) {
|
|
|
|
// In absolute mode, the second byte (mStateData)
|
|
|
|
// represents the number of pixels
|
|
|
|
// that follow, each of which contains
|
|
|
|
// the color index of a single pixel.
|
2013-01-28 09:26:36 -08:00
|
|
|
uint32_t* d = reinterpret_cast<uint32_t*>(mImageData) + PIXEL_OFFSET(mCurLine, mCurPos);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t* oldPos = d;
|
2007-07-17 14:08:46 -07:00
|
|
|
if (mBIH.compression == BI_RLE8) {
|
|
|
|
while (aCount > 0 && mStateData > 0) {
|
|
|
|
byte = *aBuffer++;
|
|
|
|
aCount--;
|
|
|
|
SetPixel(d, byte, mColors);
|
|
|
|
mStateData--;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (aCount > 0 && mStateData > 0) {
|
|
|
|
byte = *aBuffer++;
|
|
|
|
aCount--;
|
|
|
|
Set4BitPixel(d, byte, mStateData, mColors);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-17 14:08:46 -07:00
|
|
|
mCurPos += d - oldPos;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mStateData == 0) {
|
|
|
|
// In absolute mode, each run must
|
|
|
|
// be aligned on a word boundary
|
|
|
|
|
|
|
|
if (mState == eRLEStateAbsoluteMode) { // Word Aligned
|
|
|
|
mState = eRLEStateInitial;
|
|
|
|
} else if (aCount > 0) { // Not word Aligned
|
|
|
|
// "next" byte is just a padding byte
|
|
|
|
// so "move" past it and we can continue
|
|
|
|
aBuffer++;
|
|
|
|
aCount--;
|
|
|
|
mState = eRLEStateInitial;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// else state is still eRLEStateAbsoluteMode
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default :
|
2010-09-12 08:22:27 -07:00
|
|
|
NS_ABORT_IF_FALSE(0, "BMP RLE decompression: unknown state!");
|
|
|
|
PostDecoderError(NS_ERROR_UNEXPECTED);
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Because of the use of the continue statement
|
|
|
|
// we only get here for eol, eof or y delta
|
|
|
|
if (mCurLine == 0) { // Finished last line
|
2007-07-17 14:08:46 -07:00
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-25 13:09:01 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t rows = mOldLine - mCurLine;
|
2007-07-17 14:08:46 -07:00
|
|
|
if (rows) {
|
2010-08-24 14:12:04 -07:00
|
|
|
|
|
|
|
// Invalidate
|
2007-11-09 04:47:50 -08:00
|
|
|
nsIntRect r(0, mBIH.height < 0 ? -mBIH.height - mOldLine : mCurLine,
|
|
|
|
mBIH.width, rows);
|
2010-08-24 14:12:04 -07:00
|
|
|
PostInvalidation(r);
|
2007-07-17 14:08:46 -07:00
|
|
|
|
|
|
|
mOldLine = mCurLine;
|
|
|
|
}
|
|
|
|
|
2010-09-12 08:22:30 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBMPDecoder::ProcessFileHeader()
|
|
|
|
{
|
|
|
|
memset(&mBFH, 0, sizeof(mBFH));
|
|
|
|
memcpy(&mBFH.signature, mRawBuf, sizeof(mBFH.signature));
|
|
|
|
memcpy(&mBFH.filesize, mRawBuf + 2, sizeof(mBFH.filesize));
|
|
|
|
memcpy(&mBFH.reserved, mRawBuf + 6, sizeof(mBFH.reserved));
|
|
|
|
memcpy(&mBFH.dataoffset, mRawBuf + 10, sizeof(mBFH.dataoffset));
|
|
|
|
memcpy(&mBFH.bihsize, mRawBuf + 14, sizeof(mBFH.bihsize));
|
|
|
|
|
|
|
|
// Now correct the endianness of the header
|
2013-09-05 15:55:13 -07:00
|
|
|
mBFH.filesize = LittleEndian::readUint32(&mBFH.filesize);
|
|
|
|
mBFH.dataoffset = LittleEndian::readUint32(&mBFH.dataoffset);
|
|
|
|
mBFH.bihsize = LittleEndian::readUint32(&mBFH.bihsize);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsBMPDecoder::ProcessInfoHeader()
|
|
|
|
{
|
|
|
|
memset(&mBIH, 0, sizeof(mBIH));
|
|
|
|
if (mBFH.bihsize == 12) { // OS/2 Bitmap
|
|
|
|
memcpy(&mBIH.width, mRawBuf, 2);
|
|
|
|
memcpy(&mBIH.height, mRawBuf + 2, 2);
|
|
|
|
memcpy(&mBIH.planes, mRawBuf + 4, sizeof(mBIH.planes));
|
|
|
|
memcpy(&mBIH.bpp, mRawBuf + 6, sizeof(mBIH.bpp));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy(&mBIH.width, mRawBuf, sizeof(mBIH.width));
|
|
|
|
memcpy(&mBIH.height, mRawBuf + 4, sizeof(mBIH.height));
|
|
|
|
memcpy(&mBIH.planes, mRawBuf + 8, sizeof(mBIH.planes));
|
|
|
|
memcpy(&mBIH.bpp, mRawBuf + 10, sizeof(mBIH.bpp));
|
|
|
|
memcpy(&mBIH.compression, mRawBuf + 12, sizeof(mBIH.compression));
|
|
|
|
memcpy(&mBIH.image_size, mRawBuf + 16, sizeof(mBIH.image_size));
|
|
|
|
memcpy(&mBIH.xppm, mRawBuf + 20, sizeof(mBIH.xppm));
|
|
|
|
memcpy(&mBIH.yppm, mRawBuf + 24, sizeof(mBIH.yppm));
|
|
|
|
memcpy(&mBIH.colors, mRawBuf + 28, sizeof(mBIH.colors));
|
|
|
|
memcpy(&mBIH.important_colors, mRawBuf + 32, sizeof(mBIH.important_colors));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Convert endianness
|
2013-09-05 15:55:13 -07:00
|
|
|
mBIH.width = LittleEndian::readUint32(&mBIH.width);
|
|
|
|
mBIH.height = LittleEndian::readUint32(&mBIH.height);
|
|
|
|
mBIH.planes = LittleEndian::readUint16(&mBIH.planes);
|
|
|
|
mBIH.bpp = LittleEndian::readUint16(&mBIH.bpp);
|
|
|
|
|
|
|
|
mBIH.compression = LittleEndian::readUint32(&mBIH.compression);
|
|
|
|
mBIH.image_size = LittleEndian::readUint32(&mBIH.image_size);
|
|
|
|
mBIH.xppm = LittleEndian::readUint32(&mBIH.xppm);
|
|
|
|
mBIH.yppm = LittleEndian::readUint32(&mBIH.yppm);
|
|
|
|
mBIH.colors = LittleEndian::readUint32(&mBIH.colors);
|
|
|
|
mBIH.important_colors = LittleEndian::readUint32(&mBIH.important_colors);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-22 19:30:46 -07:00
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-22 19:30:46 -07:00
|
|
|
} // namespace mozilla
|