2015-07-11 05:26:15 +03:00
|
|
|
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
|
2012-05-21 15:12:37 +04: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/. */
|
2001-11-03 10:10:51 +03:00
|
|
|
|
|
|
|
/* This is a Cross-Platform ICO Decoder, which should work everywhere, including
|
|
|
|
* Big-Endian machines like the PowerPC. */
|
|
|
|
|
2005-05-27 02:43:36 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-09-06 02:55:13 +04:00
|
|
|
#include "mozilla/Endian.h"
|
2014-11-27 00:22:10 +03:00
|
|
|
#include "mozilla/Move.h"
|
2001-11-03 10:10:51 +03:00
|
|
|
#include "nsICODecoder.h"
|
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
#include "RasterImage.h"
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2015-09-19 23:34:14 +03:00
|
|
|
using namespace mozilla::gfx;
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
namespace mozilla {
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Constants.
|
|
|
|
static const uint32_t ICOHEADERSIZE = 6;
|
|
|
|
static const uint32_t BITMAPINFOSIZE = 40;
|
2001-11-03 10:10:51 +03:00
|
|
|
|
2001-11-03 12:50:31 +03:00
|
|
|
// ----------------------------------------
|
|
|
|
// Actual Data Processing
|
|
|
|
// ----------------------------------------
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2014-11-14 20:59:00 +03:00
|
|
|
nsICODecoder::CalcAlphaRowSize()
|
2002-09-27 14:22:53 +04:00
|
|
|
{
|
2007-07-18 01:08:46 +04:00
|
|
|
// Calculate rowsize in DWORD's and then return in # of bytes
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rowSize = (GetRealWidth() + 31) / 32; // + 31 to round up
|
2011-08-26 00:09:01 +04:00
|
|
|
return rowSize * 4; // Return rowSize in bytes
|
2002-09-27 14:22:53 +04:00
|
|
|
}
|
|
|
|
|
2011-08-26 00:09:01 +04:00
|
|
|
// Obtains the number of colors from the bits per pixel
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t
|
2014-11-14 20:59:00 +03:00
|
|
|
nsICODecoder::GetNumColors()
|
2011-08-26 00:09:01 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t numColors = 0;
|
2011-08-26 00:09:01 +04:00
|
|
|
if (mBPP <= 8) {
|
|
|
|
switch (mBPP) {
|
|
|
|
case 1:
|
|
|
|
numColors = 2;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
numColors = 16;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
numColors = 256;
|
|
|
|
break;
|
|
|
|
default:
|
2012-08-22 19:56:38 +04:00
|
|
|
numColors = (uint16_t)-1;
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return numColors;
|
|
|
|
}
|
|
|
|
|
2015-01-16 02:11:35 +03:00
|
|
|
nsICODecoder::nsICODecoder(RasterImage* aImage)
|
2015-09-19 09:12:30 +03:00
|
|
|
: Decoder(aImage)
|
|
|
|
, mLexer(Transition::To(ICOState::HEADER, ICOHEADERSIZE))
|
2015-09-19 23:34:14 +03:00
|
|
|
, mBiggestResourceColorDepth(0)
|
2015-09-19 09:12:30 +03:00
|
|
|
, mBestResourceDelta(INT_MIN)
|
|
|
|
, mBestResourceColorDepth(0)
|
|
|
|
, mNumIcons(0)
|
|
|
|
, mCurrIcon(0)
|
|
|
|
, mBPP(0)
|
|
|
|
, mMaskRowSize(0)
|
|
|
|
, mCurrMaskLine(0)
|
2015-09-22 05:52:31 +03:00
|
|
|
, mIsCursor(false)
|
|
|
|
, mHasMaskAlpha(false)
|
2015-09-19 09:12:30 +03:00
|
|
|
{ }
|
2015-09-18 20:54:40 +03:00
|
|
|
|
2010-09-12 19:22:30 +04:00
|
|
|
void
|
2010-08-23 06:30:46 +04:00
|
|
|
nsICODecoder::FinishInternal()
|
2001-11-03 10:10:51 +03:00
|
|
|
{
|
2010-09-12 19:22:31 +04:00
|
|
|
// We shouldn't be called in error cases
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!HasError(), "Shouldn't call FinishInternal after error!");
|
2010-09-12 19:22:31 +04:00
|
|
|
|
2015-07-11 05:26:15 +03:00
|
|
|
GetFinalStateFromContainedDecoder();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsICODecoder::FinishWithErrorInternal()
|
|
|
|
{
|
|
|
|
GetFinalStateFromContainedDecoder();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsICODecoder::GetFinalStateFromContainedDecoder()
|
|
|
|
{
|
|
|
|
if (!mContainedDecoder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Finish the internally used decoder.
|
|
|
|
mContainedDecoder->CompleteDecode();
|
|
|
|
|
2015-07-11 05:26:15 +03:00
|
|
|
mDecodeDone = mContainedDecoder->GetDecodeDone();
|
|
|
|
mDataError = mDataError || mContainedDecoder->HasDataError();
|
|
|
|
mFailCode = NS_SUCCEEDED(mFailCode) ? mContainedDecoder->GetDecoderError()
|
|
|
|
: mFailCode;
|
|
|
|
mDecodeAborted = mContainedDecoder->WasAborted();
|
|
|
|
mProgress |= mContainedDecoder->TakeProgress();
|
|
|
|
mInvalidRect.UnionRect(mInvalidRect, mContainedDecoder->TakeInvalidRect());
|
|
|
|
mCurrentFrame = mContainedDecoder->GetCurrentFrameRef();
|
2015-09-19 09:12:30 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(HasError() || !mCurrentFrame || mCurrentFrame->IsImageComplete());
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns a buffer filled with the bitmap file header in little endian:
|
|
|
|
// Signature 2 bytes 'BM'
|
2014-11-14 20:59:00 +03:00
|
|
|
// FileSize 4 bytes File size in bytes
|
|
|
|
// reserved 4 bytes unused (=0)
|
|
|
|
// DataOffset 4 bytes File offset to Raster Data
|
2011-10-17 18:59:28 +04:00
|
|
|
// Returns true if successful
|
2014-11-14 20:59:00 +03:00
|
|
|
bool
|
|
|
|
nsICODecoder::FillBitmapFileHeaderBuffer(int8_t* bfh)
|
2011-08-26 00:09:01 +04:00
|
|
|
{
|
|
|
|
memset(bfh, 0, 14);
|
|
|
|
bfh[0] = 'B';
|
|
|
|
bfh[1] = 'M';
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t dataOffset = 0;
|
|
|
|
int32_t fileSize = 0;
|
2015-07-23 01:49:49 +03:00
|
|
|
dataOffset = BMPFILEHEADER::LENGTH + BITMAPINFOSIZE;
|
2011-08-26 00:09:01 +04:00
|
|
|
|
|
|
|
// The color table is present only if BPP is <= 8
|
|
|
|
if (mDirEntry.mBitCount <= 8) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t numColors = GetNumColors();
|
|
|
|
if (numColors == (uint16_t)-1) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
dataOffset += 4 * numColors;
|
2011-09-22 17:43:13 +04:00
|
|
|
fileSize = dataOffset + GetRealWidth() * GetRealHeight();
|
2011-08-26 00:09:01 +04:00
|
|
|
} else {
|
2014-11-14 20:59:00 +03:00
|
|
|
fileSize = dataOffset + (mDirEntry.mBitCount * GetRealWidth() *
|
2011-09-22 17:43:13 +04:00
|
|
|
GetRealHeight()) / 8;
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapToLittleEndianInPlace(&fileSize, 1);
|
2011-08-26 00:09:01 +04:00
|
|
|
memcpy(bfh + 2, &fileSize, sizeof(fileSize));
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapToLittleEndianInPlace(&dataOffset, 1);
|
2011-08-26 00:09:01 +04:00
|
|
|
memcpy(bfh + 10, &dataOffset, sizeof(dataOffset));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// A BMP inside of an ICO has *2 height because of the AND mask
|
|
|
|
// that follows the actual bitmap. The BMP shouldn't know about
|
|
|
|
// this difference though.
|
2011-11-04 17:56:17 +04:00
|
|
|
bool
|
2014-11-14 20:59:00 +03:00
|
|
|
nsICODecoder::FixBitmapHeight(int8_t* bih)
|
2011-08-26 00:09:01 +04:00
|
|
|
{
|
2011-11-04 17:56:17 +04:00
|
|
|
// Get the height from the BMP file information header
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t height;
|
2011-11-04 17:56:17 +04:00
|
|
|
memcpy(&height, bih + 8, sizeof(height));
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapFromLittleEndianInPlace(&height, 1);
|
2012-07-21 21:57:35 +04:00
|
|
|
// BMPs can be stored inverted by having a negative height
|
|
|
|
height = abs(height);
|
2011-11-04 17:56:17 +04:00
|
|
|
|
|
|
|
// The bitmap height is by definition * 2 what it should be to account for
|
|
|
|
// the 'AND mask'. It is * 2 even if the `AND mask` is not present.
|
|
|
|
height /= 2;
|
|
|
|
|
|
|
|
if (height > 256) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
// We should always trust the height from the bitmap itself instead of
|
2011-11-04 17:56:17 +04:00
|
|
|
// the ICO height. So fix the ICO height.
|
|
|
|
if (height == 256) {
|
|
|
|
mDirEntry.mHeight = 0;
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
mDirEntry.mHeight = (int8_t)height;
|
2011-11-04 17:56:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fix the BMP height in the BIH so that the BMP decoder can work properly
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapToLittleEndianInPlace(&height, 1);
|
2011-08-26 00:09:01 +04:00
|
|
|
memcpy(bih + 8, &height, sizeof(height));
|
2011-11-04 17:56:17 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We should always trust the contained resource for the width
|
|
|
|
// information over our own information.
|
|
|
|
bool
|
2014-11-14 20:59:00 +03:00
|
|
|
nsICODecoder::FixBitmapWidth(int8_t* bih)
|
2011-11-04 17:56:17 +04:00
|
|
|
{
|
|
|
|
// Get the width from the BMP file information header
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t width;
|
2011-11-04 17:56:17 +04:00
|
|
|
memcpy(&width, bih + 4, sizeof(width));
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapFromLittleEndianInPlace(&width, 1);
|
2011-11-04 17:56:17 +04:00
|
|
|
if (width > 256) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
// We should always trust the width from the bitmap itself instead of
|
2011-11-04 17:56:17 +04:00
|
|
|
// the ICO width.
|
|
|
|
if (width == 256) {
|
|
|
|
mDirEntry.mWidth = 0;
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
mDirEntry.mWidth = (int8_t)width;
|
2011-11-04 17:56:17 +04:00
|
|
|
}
|
|
|
|
return true;
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The BMP information header's bits per pixel should be trusted
|
2015-09-19 09:12:30 +03:00
|
|
|
// more than what we have. Usually the ICO's BPP is set to 0.
|
2014-11-14 20:59:00 +03:00
|
|
|
int32_t
|
2015-09-19 09:12:30 +03:00
|
|
|
nsICODecoder::ReadBPP(const char* aBIH)
|
2011-08-26 00:09:01 +04:00
|
|
|
{
|
2015-09-19 09:12:30 +03:00
|
|
|
const int8_t* bih = reinterpret_cast<const int8_t*>(aBIH);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t bitsPerPixel;
|
2011-08-26 00:09:01 +04:00
|
|
|
memcpy(&bitsPerPixel, bih + 14, sizeof(bitsPerPixel));
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapFromLittleEndianInPlace(&bitsPerPixel, 1);
|
2011-08-26 00:09:01 +04:00
|
|
|
return bitsPerPixel;
|
|
|
|
}
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2014-11-14 20:59:00 +03:00
|
|
|
int32_t
|
2015-09-19 09:12:30 +03:00
|
|
|
nsICODecoder::ReadBIHSize(const char* aBIH)
|
2011-08-30 09:12:59 +04:00
|
|
|
{
|
2015-09-19 09:12:30 +03:00
|
|
|
const int8_t* bih = reinterpret_cast<const int8_t*>(aBIH);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t headerSize;
|
2011-08-30 09:12:59 +04:00
|
|
|
memcpy(&headerSize, bih, sizeof(headerSize));
|
2013-09-06 02:55:13 +04:00
|
|
|
NativeEndian::swapFromLittleEndianInPlace(&headerSize, 1);
|
2011-08-30 09:12:59 +04:00
|
|
|
return headerSize;
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::ReadHeader(const char* aData)
|
2015-09-18 20:54:27 +03:00
|
|
|
{
|
2015-09-19 09:12:30 +03:00
|
|
|
// If the third byte is 1, this is an icon. If 2, a cursor.
|
|
|
|
if ((aData[2] != 1) && (aData[2] != 2)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
2015-09-19 09:12:30 +03:00
|
|
|
mIsCursor = (aData[2] == 2);
|
2011-08-26 00:09:01 +04:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// The fifth and sixth bytes specify the number of resources in the file.
|
|
|
|
mNumIcons =
|
|
|
|
LittleEndian::readUint16(reinterpret_cast<const uint16_t*>(aData + 4));
|
2015-09-18 23:01:25 +03:00
|
|
|
if (mNumIcons == 0) {
|
2015-09-19 09:12:30 +03:00
|
|
|
return Transition::Terminate(ICOState::SUCCESS); // Nothing to do.
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
|
2015-09-19 23:34:14 +03:00
|
|
|
// Downscale-during-decode can end up decoding different resources in the ICO
|
|
|
|
// file depending on the target size. Since the resources are not necessarily
|
|
|
|
// scaled versions of the same image, some may be transparent and some may not
|
|
|
|
// be. We could be precise about transparency if we decoded the metadata of
|
|
|
|
// every resource, but for now we don't and it's safest to assume that
|
|
|
|
// transparency could be present.
|
|
|
|
PostHasTransparency();
|
2011-08-26 00:09:01 +04:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
return Transition::To(ICOState::DIR_ENTRY, ICODIRENTRYSIZE);
|
|
|
|
}
|
2005-01-12 23:16:07 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
size_t
|
|
|
|
nsICODecoder::FirstResourceOffset() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mNumIcons > 0,
|
|
|
|
"Calling FirstResourceOffset before processing header");
|
2005-01-12 23:16:07 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// The first resource starts right after the directory, which starts right
|
|
|
|
// after the ICO header.
|
|
|
|
return ICOHEADERSIZE + mNumIcons * ICODIRENTRYSIZE;
|
|
|
|
}
|
2011-08-26 00:09:01 +04:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::ReadDirEntry(const char* aData)
|
|
|
|
{
|
|
|
|
mCurrIcon++;
|
|
|
|
|
|
|
|
// Read the directory entry.
|
|
|
|
IconDirEntry e;
|
|
|
|
memset(&e, 0, sizeof(e));
|
|
|
|
memcpy(&e.mWidth, aData, sizeof(e.mWidth));
|
|
|
|
memcpy(&e.mHeight, aData + 1, sizeof(e.mHeight));
|
|
|
|
memcpy(&e.mColorCount, aData + 2, sizeof(e.mColorCount));
|
|
|
|
memcpy(&e.mReserved, aData + 3, sizeof(e.mReserved));
|
|
|
|
memcpy(&e.mPlanes, aData + 4, sizeof(e.mPlanes));
|
|
|
|
e.mPlanes = LittleEndian::readUint16(&e.mPlanes);
|
|
|
|
memcpy(&e.mBitCount, aData + 6, sizeof(e.mBitCount));
|
|
|
|
e.mBitCount = LittleEndian::readUint16(&e.mBitCount);
|
|
|
|
memcpy(&e.mBytesInRes, aData + 8, sizeof(e.mBytesInRes));
|
|
|
|
e.mBytesInRes = LittleEndian::readUint32(&e.mBytesInRes);
|
|
|
|
memcpy(&e.mImageOffset, aData + 12, sizeof(e.mImageOffset));
|
|
|
|
e.mImageOffset = LittleEndian::readUint32(&e.mImageOffset);
|
|
|
|
|
2015-09-19 23:34:14 +03:00
|
|
|
// Determine if this is the biggest resource we've seen so far. We always use
|
|
|
|
// the biggest resource for the intrinsic size, and if we're not downscaling,
|
|
|
|
// we select it as the best resource as well.
|
|
|
|
IntSize entrySize(GetRealWidth(e), GetRealHeight(e));
|
|
|
|
if (e.mBitCount >= mBiggestResourceColorDepth &&
|
|
|
|
entrySize.width * entrySize.height >=
|
|
|
|
mBiggestResourceSize.width * mBiggestResourceSize.height) {
|
|
|
|
mBiggestResourceSize = entrySize;
|
|
|
|
mBiggestResourceColorDepth = e.mBitCount;
|
|
|
|
mBiggestResourceHotSpot = IntSize(e.mXHotspot, e.mYHotspot);
|
|
|
|
|
|
|
|
if (!mDownscaler) {
|
|
|
|
mDirEntry = e;
|
2015-09-18 23:01:25 +03:00
|
|
|
}
|
2015-09-19 23:34:14 +03:00
|
|
|
}
|
2009-10-16 06:54:44 +04:00
|
|
|
|
2015-09-19 23:34:14 +03:00
|
|
|
if (mDownscaler) {
|
|
|
|
// Calculate the delta between this resource's size and the desired size, so
|
|
|
|
// we can see if it is better than our current-best option. In the case of
|
|
|
|
// several equally-good resources, we use the last one. "Better" in this
|
|
|
|
// case is determined by |delta|, a measure of the difference in size
|
|
|
|
// between the entry we've found and the downscaler's target size. We will
|
|
|
|
// choose the smallest resource that is >= the target size (i.e. we assume
|
|
|
|
// it's better to downscale a larger icon than to upscale a smaller one).
|
|
|
|
IntSize desiredSize = mDownscaler->TargetSize();
|
|
|
|
int32_t delta = entrySize.width - desiredSize.width +
|
|
|
|
entrySize.height - desiredSize.height;
|
|
|
|
if (e.mBitCount >= mBestResourceColorDepth &&
|
|
|
|
((mBestResourceDelta < 0 && delta >= mBestResourceDelta) ||
|
|
|
|
(delta >= 0 && delta <= mBestResourceDelta))) {
|
|
|
|
mBestResourceDelta = delta;
|
|
|
|
mBestResourceColorDepth = e.mBitCount;
|
|
|
|
mDirEntry = e;
|
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
}
|
2007-07-18 01:08:46 +04:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
if (mCurrIcon == mNumIcons) {
|
2015-09-19 23:34:14 +03:00
|
|
|
// Ensure the resource we selected has an offset past the ICO headers.
|
|
|
|
if (mDirEntry.mImageOffset < FirstResourceOffset()) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a cursor, set the hotspot. We use the hotspot from the biggest
|
|
|
|
// resource since we also use that resource for the intrinsic size.
|
|
|
|
if (mIsCursor) {
|
|
|
|
mImageMetadata.SetHotspot(mBiggestResourceHotSpot.width,
|
|
|
|
mBiggestResourceHotSpot.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We always report the biggest resource's size as the intrinsic size; this
|
|
|
|
// is necessary for downscale-during-decode to work since we won't even
|
|
|
|
// attempt to *upscale* while decoding.
|
|
|
|
PostSize(mBiggestResourceSize.width, mBiggestResourceSize.height);
|
2015-09-19 23:34:06 +03:00
|
|
|
if (IsMetadataDecode()) {
|
|
|
|
return Transition::Terminate(ICOState::SUCCESS);
|
|
|
|
}
|
|
|
|
|
2015-09-19 23:34:14 +03:00
|
|
|
// If the resource we selected matches the downscaler's target size
|
|
|
|
// perfectly, we don't need to do any downscaling.
|
|
|
|
if (mDownscaler && GetRealSize() == mDownscaler->TargetSize()) {
|
|
|
|
mDownscaler.reset();
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
size_t offsetToResource = mDirEntry.mImageOffset - FirstResourceOffset();
|
|
|
|
return Transition::ToUnbuffered(ICOState::FOUND_RESOURCE,
|
|
|
|
ICOState::SKIP_TO_RESOURCE,
|
|
|
|
offsetToResource);
|
2015-09-18 20:54:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
return Transition::To(ICOState::DIR_ENTRY, ICODIRENTRYSIZE);
|
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::SniffResource(const char* aData)
|
|
|
|
{
|
|
|
|
// We use the first PNGSIGNATURESIZE bytes to determine whether this resource
|
|
|
|
// is a PNG or a BMP.
|
|
|
|
bool isPNG = !memcmp(aData, nsPNGDecoder::pngSignatureBytes,
|
|
|
|
PNGSIGNATURESIZE);
|
|
|
|
if (isPNG) {
|
|
|
|
// Create a PNG decoder which will do the rest of the work for us.
|
|
|
|
mContainedDecoder = new nsPNGDecoder(mImage);
|
|
|
|
mContainedDecoder->SetMetadataDecode(IsMetadataDecode());
|
|
|
|
mContainedDecoder->SetDecoderFlags(GetDecoderFlags());
|
|
|
|
mContainedDecoder->SetSurfaceFlags(GetSurfaceFlags());
|
2015-09-19 23:34:14 +03:00
|
|
|
if (mDownscaler) {
|
|
|
|
mContainedDecoder->SetTargetSize(mDownscaler->TargetSize());
|
|
|
|
}
|
2015-09-19 09:12:30 +03:00
|
|
|
mContainedDecoder->Init();
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
if (!WriteToContainedDecoder(aData, PNGSIGNATURESIZE)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
2015-09-18 23:01:25 +03:00
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
if (mDirEntry.mBytesInRes <= PNGSIGNATURESIZE) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
2015-09-18 23:01:25 +03:00
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Read in the rest of the PNG unbuffered.
|
|
|
|
size_t toRead = mDirEntry.mBytesInRes - PNGSIGNATURESIZE;
|
|
|
|
return Transition::ToUnbuffered(ICOState::FINISHED_RESOURCE,
|
|
|
|
ICOState::READ_PNG,
|
|
|
|
toRead);
|
|
|
|
} else {
|
|
|
|
// Create a BMP decoder which will do most of the work for us; the exception
|
|
|
|
// is the AND mask, which isn't present in standalone BMPs.
|
2015-09-18 23:01:25 +03:00
|
|
|
nsBMPDecoder* bmpDecoder = new nsBMPDecoder(mImage);
|
|
|
|
mContainedDecoder = bmpDecoder;
|
|
|
|
bmpDecoder->SetUseAlphaData(true);
|
|
|
|
mContainedDecoder->SetMetadataDecode(IsMetadataDecode());
|
|
|
|
mContainedDecoder->SetDecoderFlags(GetDecoderFlags());
|
|
|
|
mContainedDecoder->SetSurfaceFlags(GetSurfaceFlags());
|
2015-09-19 23:34:14 +03:00
|
|
|
if (mDownscaler) {
|
|
|
|
mContainedDecoder->SetTargetSize(mDownscaler->TargetSize());
|
|
|
|
}
|
2015-09-18 23:01:25 +03:00
|
|
|
mContainedDecoder->Init();
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Make sure we have a sane size for the bitmap information header.
|
|
|
|
int32_t bihSize = ReadBIHSize(aData);
|
|
|
|
if (bihSize != static_cast<int32_t>(BITMAPINFOSIZE)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
2015-09-18 23:01:25 +03:00
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Buffer the first part of the bitmap information header.
|
|
|
|
memcpy(mBIHraw, aData, PNGSIGNATURESIZE);
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Read in the rest of the bitmap information header.
|
|
|
|
return Transition::To(ICOState::READ_BIH,
|
|
|
|
BITMAPINFOSIZE - PNGSIGNATURESIZE);
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 20:59:00 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::ReadPNG(const char* aData, uint32_t aLen)
|
|
|
|
{
|
|
|
|
if (!WriteToContainedDecoder(aData, aLen)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Raymond Chen says that 32bpp only are valid PNG ICOs
|
|
|
|
// http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
|
2015-09-19 23:34:14 +03:00
|
|
|
if (!static_cast<nsPNGDecoder*>(mContainedDecoder.get())->IsValidICO()) {
|
2015-09-19 09:12:30 +03:00
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
return Transition::ContinueUnbuffered(ICOState::READ_PNG);
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::ReadBIH(const char* aData)
|
|
|
|
{
|
|
|
|
// Buffer the rest of the bitmap information header.
|
|
|
|
memcpy(mBIHraw + PNGSIGNATURESIZE, aData, BITMAPINFOSIZE - PNGSIGNATURESIZE);
|
|
|
|
|
|
|
|
// Extracting the BPP from the BIH header; it should be trusted over the one
|
|
|
|
// we have from the ICO header.
|
|
|
|
mBPP = ReadBPP(mBIHraw);
|
|
|
|
|
|
|
|
// The ICO format when containing a BMP does not include the 14 byte
|
|
|
|
// bitmap file header. To use the code of the BMP decoder we need to
|
|
|
|
// generate this header ourselves and feed it to the BMP decoder.
|
|
|
|
int8_t bfhBuffer[BMPFILEHEADERSIZE];
|
|
|
|
if (!FillBitmapFileHeaderBuffer(bfhBuffer)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
2015-09-18 20:54:32 +03:00
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
if (!WriteToContainedDecoder(reinterpret_cast<const char*>(bfhBuffer),
|
|
|
|
sizeof(bfhBuffer))) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// Fix the ICO height from the BIH. It needs to be halved so our BMP decoder
|
|
|
|
// will understand, because the BMP decoder doesn't expect the alpha mask that
|
|
|
|
// follows the BMP data in an ICO.
|
|
|
|
if (!FixBitmapHeight(reinterpret_cast<int8_t*>(mBIHraw))) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fix the ICO width from the BIH.
|
|
|
|
if (!FixBitmapWidth(reinterpret_cast<int8_t*>(mBIHraw))) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write out the BMP's bitmap info header.
|
|
|
|
if (!WriteToContainedDecoder(mBIHraw, sizeof(mBIHraw))) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sometimes the ICO BPP header field is not filled out so we should trust the
|
|
|
|
// contained resource over our own information.
|
|
|
|
// XXX(seth): Is this ever different than the value we obtained from
|
|
|
|
// ReadBPP() above?
|
|
|
|
nsRefPtr<nsBMPDecoder> bmpDecoder =
|
|
|
|
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
|
|
|
|
mBPP = bmpDecoder->GetBitsPerPixel();
|
|
|
|
|
|
|
|
// Check to make sure we have valid color settings.
|
|
|
|
uint16_t numColors = GetNumColors();
|
|
|
|
if (numColors == uint16_t(-1)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have an AND mask on this BMP? If so, we need to read it after we read
|
|
|
|
// the BMP data itself.
|
|
|
|
uint32_t bmpDataLength = bmpDecoder->GetCompressedImageSize() + 4 * numColors;
|
|
|
|
bool hasANDMask = (BITMAPINFOSIZE + bmpDataLength) < mDirEntry.mBytesInRes;
|
|
|
|
ICOState afterBMPState = hasANDMask ? ICOState::PREPARE_FOR_MASK
|
|
|
|
: ICOState::FINISHED_RESOURCE;
|
|
|
|
|
|
|
|
// Read in the rest of the BMP unbuffered.
|
|
|
|
return Transition::ToUnbuffered(afterBMPState,
|
|
|
|
ICOState::READ_BMP,
|
|
|
|
bmpDataLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::ReadBMP(const char* aData, uint32_t aLen)
|
|
|
|
{
|
|
|
|
if (!WriteToContainedDecoder(aData, aLen)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Transition::ContinueUnbuffered(ICOState::READ_BMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::PrepareForMask()
|
|
|
|
{
|
|
|
|
nsRefPtr<nsBMPDecoder> bmpDecoder =
|
|
|
|
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
|
|
|
|
|
|
|
|
uint16_t numColors = GetNumColors();
|
|
|
|
MOZ_ASSERT(numColors != uint16_t(-1));
|
|
|
|
|
|
|
|
// Determine the length of the AND mask.
|
|
|
|
uint32_t bmpLengthWithHeader =
|
|
|
|
BITMAPINFOSIZE + bmpDecoder->GetCompressedImageSize() + 4 * numColors;
|
|
|
|
MOZ_ASSERT(bmpLengthWithHeader < mDirEntry.mBytesInRes);
|
|
|
|
uint32_t maskLength = mDirEntry.mBytesInRes - bmpLengthWithHeader;
|
|
|
|
|
|
|
|
// If we have a 32-bpp BMP with alpha data, we ignore the AND mask. We can
|
|
|
|
// also obviously ignore it if the image has zero width or zero height.
|
|
|
|
if ((bmpDecoder->GetBitsPerPixel() == 32 && bmpDecoder->HasAlphaData()) ||
|
|
|
|
GetRealWidth() == 0 || GetRealHeight() == 0) {
|
|
|
|
return Transition::ToUnbuffered(ICOState::FINISHED_RESOURCE,
|
|
|
|
ICOState::SKIP_MASK,
|
|
|
|
maskLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute the row size for the mask.
|
|
|
|
mMaskRowSize = ((GetRealWidth() + 31) / 32) * 4; // + 31 to round up
|
|
|
|
|
|
|
|
// If the expected size of the AND mask is larger than its actual size, then
|
|
|
|
// we must have a truncated (and therefore corrupt) AND mask.
|
|
|
|
uint32_t expectedLength = mMaskRowSize * GetRealHeight();
|
|
|
|
if (maskLength < expectedLength) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-09-22 05:52:31 +03:00
|
|
|
// If we're downscaling, the mask is the wrong size for the surface we've
|
|
|
|
// produced, so we need to downscale the mask into a temporary buffer and then
|
|
|
|
// combine the mask's alpha values with the color values from the image.
|
|
|
|
if (mDownscaler) {
|
|
|
|
MOZ_ASSERT(bmpDecoder->GetImageDataLength() ==
|
|
|
|
mDownscaler->TargetSize().width *
|
|
|
|
mDownscaler->TargetSize().height *
|
|
|
|
sizeof(uint32_t));
|
|
|
|
mMaskBuffer = MakeUnique<uint8_t[]>(bmpDecoder->GetImageDataLength());
|
2015-09-26 11:36:19 +03:00
|
|
|
nsresult rv = mDownscaler->BeginFrame(GetRealSize(), Nothing(),
|
2015-09-22 05:52:31 +03:00
|
|
|
mMaskBuffer.get(),
|
|
|
|
/* aHasAlpha = */ true,
|
|
|
|
/* aFlipVertically = */ true);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
mCurrMaskLine = GetRealHeight();
|
|
|
|
return Transition::To(ICOState::READ_MASK_ROW, mMaskRowSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::ReadMaskRow(const char* aData)
|
|
|
|
{
|
|
|
|
mCurrMaskLine--;
|
|
|
|
|
2015-09-22 05:52:31 +03:00
|
|
|
uint8_t sawTransparency = 0;
|
2015-09-19 09:12:30 +03:00
|
|
|
|
2015-09-22 05:52:31 +03:00
|
|
|
// Get the mask row we're reading.
|
|
|
|
const uint8_t* mask = reinterpret_cast<const uint8_t*>(aData);
|
|
|
|
const uint8_t* maskRowEnd = mask + mMaskRowSize;
|
|
|
|
|
|
|
|
// Get the corresponding row of the mask buffer (if we're downscaling) or the
|
|
|
|
// decoded image data (if we're not).
|
|
|
|
uint32_t* decoded = nullptr;
|
|
|
|
if (mDownscaler) {
|
|
|
|
// Initialize the row to all white and fully opaque.
|
|
|
|
memset(mDownscaler->RowBuffer(), 0xFF, GetRealWidth() * sizeof(uint32_t));
|
|
|
|
|
|
|
|
decoded = reinterpret_cast<uint32_t*>(mDownscaler->RowBuffer());
|
|
|
|
} else {
|
|
|
|
nsRefPtr<nsBMPDecoder> bmpDecoder =
|
|
|
|
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
|
|
|
|
uint32_t* imageData = bmpDecoder->GetImageData();
|
|
|
|
if (!imageData) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
decoded = imageData + mCurrMaskLine * GetRealWidth();
|
2015-09-19 09:12:30 +03:00
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
|
2015-09-22 05:52:31 +03:00
|
|
|
MOZ_ASSERT(decoded);
|
2015-09-19 09:12:30 +03:00
|
|
|
uint32_t* decodedRowEnd = decoded + GetRealWidth();
|
|
|
|
|
|
|
|
// Iterate simultaneously through the AND mask and the image data.
|
|
|
|
while (mask < maskRowEnd) {
|
|
|
|
uint8_t idx = *mask++;
|
|
|
|
sawTransparency |= idx;
|
|
|
|
for (uint8_t bit = 0x80; bit && decoded < decodedRowEnd; bit >>= 1) {
|
|
|
|
// Clear pixel completely for transparency.
|
|
|
|
if (idx & bit) {
|
|
|
|
*decoded = 0;
|
2015-09-18 23:01:25 +03:00
|
|
|
}
|
2015-09-19 09:12:30 +03:00
|
|
|
decoded++;
|
2015-09-18 23:01:25 +03:00
|
|
|
}
|
2015-09-18 20:54:27 +03:00
|
|
|
}
|
2015-09-19 09:12:30 +03:00
|
|
|
|
2015-09-22 05:52:31 +03:00
|
|
|
if (mDownscaler) {
|
|
|
|
mDownscaler->CommitRow();
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
// If any bits are set in sawTransparency, then we know at least one pixel was
|
|
|
|
// transparent.
|
|
|
|
if (sawTransparency) {
|
2015-09-22 05:52:31 +03:00
|
|
|
mHasMaskAlpha = true;
|
2015-09-19 09:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mCurrMaskLine == 0) {
|
2015-09-22 05:52:31 +03:00
|
|
|
return Transition::To(ICOState::FINISH_MASK, 0);
|
2015-09-19 09:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return Transition::To(ICOState::READ_MASK_ROW, mMaskRowSize);
|
|
|
|
}
|
|
|
|
|
2015-09-22 05:52:31 +03:00
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::FinishMask()
|
|
|
|
{
|
|
|
|
// If we're downscaling, we now have the appropriate alpha values in
|
|
|
|
// mMaskBuffer. We just need to transfer them to the image.
|
|
|
|
if (mDownscaler) {
|
|
|
|
// Retrieve the image data.
|
|
|
|
nsRefPtr<nsBMPDecoder> bmpDecoder =
|
|
|
|
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
|
|
|
|
uint8_t* imageData = reinterpret_cast<uint8_t*>(bmpDecoder->GetImageData());
|
|
|
|
if (!imageData) {
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate through the alpha values, copying from mask to image.
|
|
|
|
MOZ_ASSERT(mMaskBuffer);
|
|
|
|
MOZ_ASSERT(bmpDecoder->GetImageDataLength() > 0);
|
|
|
|
for (size_t i = 3 ; i < bmpDecoder->GetImageDataLength() ; i += 4) {
|
|
|
|
imageData[i] = mMaskBuffer[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the mask contained any transparent pixels, record that fact.
|
|
|
|
if (mHasMaskAlpha) {
|
|
|
|
PostHasTransparency();
|
|
|
|
|
|
|
|
nsRefPtr<nsBMPDecoder> bmpDecoder =
|
|
|
|
static_cast<nsBMPDecoder*>(mContainedDecoder.get());
|
|
|
|
bmpDecoder->SetHasAlphaData();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Transition::To(ICOState::FINISHED_RESOURCE, 0);
|
|
|
|
}
|
|
|
|
|
2015-09-19 23:34:06 +03:00
|
|
|
LexerTransition<ICOState>
|
|
|
|
nsICODecoder::FinishResource()
|
|
|
|
{
|
|
|
|
// Make sure the actual size of the resource matches the size in the directory
|
|
|
|
// entry. If not, we consider the image corrupt.
|
|
|
|
if (mContainedDecoder->HasSize() &&
|
2015-09-19 23:34:14 +03:00
|
|
|
mContainedDecoder->GetSize() != GetRealSize()) {
|
2015-09-19 23:34:06 +03:00
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Transition::Terminate(ICOState::SUCCESS);
|
|
|
|
}
|
|
|
|
|
2015-09-19 09:12:30 +03:00
|
|
|
void
|
|
|
|
nsICODecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!HasError(), "Shouldn't call WriteInternal after error!");
|
|
|
|
MOZ_ASSERT(aBuffer);
|
|
|
|
MOZ_ASSERT(aCount > 0);
|
|
|
|
|
|
|
|
Maybe<ICOState> terminalState =
|
|
|
|
mLexer.Lex(aBuffer, aCount,
|
|
|
|
[=](ICOState aState, const char* aData, size_t aLength) {
|
|
|
|
switch (aState) {
|
|
|
|
case ICOState::HEADER:
|
|
|
|
return ReadHeader(aData);
|
|
|
|
case ICOState::DIR_ENTRY:
|
|
|
|
return ReadDirEntry(aData);
|
|
|
|
case ICOState::SKIP_TO_RESOURCE:
|
|
|
|
return Transition::ContinueUnbuffered(ICOState::SKIP_TO_RESOURCE);
|
|
|
|
case ICOState::FOUND_RESOURCE:
|
|
|
|
return Transition::To(ICOState::SNIFF_RESOURCE, PNGSIGNATURESIZE);
|
|
|
|
case ICOState::SNIFF_RESOURCE:
|
|
|
|
return SniffResource(aData);
|
|
|
|
case ICOState::READ_PNG:
|
|
|
|
return ReadPNG(aData, aLength);
|
|
|
|
case ICOState::READ_BIH:
|
|
|
|
return ReadBIH(aData);
|
|
|
|
case ICOState::READ_BMP:
|
|
|
|
return ReadBMP(aData, aLength);
|
|
|
|
case ICOState::PREPARE_FOR_MASK:
|
|
|
|
return PrepareForMask();
|
|
|
|
case ICOState::READ_MASK_ROW:
|
|
|
|
return ReadMaskRow(aData);
|
2015-09-22 05:52:31 +03:00
|
|
|
case ICOState::FINISH_MASK:
|
|
|
|
return FinishMask();
|
2015-09-19 09:12:30 +03:00
|
|
|
case ICOState::SKIP_MASK:
|
|
|
|
return Transition::ContinueUnbuffered(ICOState::SKIP_MASK);
|
|
|
|
case ICOState::FINISHED_RESOURCE:
|
2015-09-19 23:34:06 +03:00
|
|
|
return FinishResource();
|
2015-09-19 09:12:30 +03:00
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unknown ICOState");
|
|
|
|
return Transition::Terminate(ICOState::FAILURE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!terminalState) {
|
|
|
|
return; // Need more data.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*terminalState == ICOState::FAILURE) {
|
|
|
|
PostDataError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(*terminalState == ICOState::SUCCESS);
|
2012-05-08 16:38:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2015-01-08 11:04:31 +03:00
|
|
|
nsICODecoder::WriteToContainedDecoder(const char* aBuffer, uint32_t aCount)
|
2012-05-08 16:38:43 +04:00
|
|
|
{
|
2015-01-08 11:04:31 +03:00
|
|
|
mContainedDecoder->Write(aBuffer, aCount);
|
2014-11-18 12:48:49 +03:00
|
|
|
mProgress |= mContainedDecoder->TakeProgress();
|
2015-03-25 11:00:00 +03:00
|
|
|
mInvalidRect.UnionRect(mInvalidRect, mContainedDecoder->TakeInvalidRect());
|
2012-05-08 16:38:43 +04:00
|
|
|
if (mContainedDecoder->HasDataError()) {
|
2015-09-19 09:12:30 +03:00
|
|
|
PostDataError();
|
2012-05-08 16:38:43 +04:00
|
|
|
}
|
|
|
|
if (mContainedDecoder->HasDecoderError()) {
|
|
|
|
PostDecoderError(mContainedDecoder->GetDecoderError());
|
|
|
|
}
|
|
|
|
return !HasError();
|
2001-11-03 10:10:51 +03:00
|
|
|
}
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-23 06:30:46 +04:00
|
|
|
} // namespace mozilla
|