зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1146663 (Part 5) - Require that all image decoders support downscale-during-decode. r=tn
This commit is contained in:
Родитель
df31b64d6c
Коммит
c1229ef66c
|
@ -244,6 +244,20 @@ Decoder::CompleteDecode()
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
Decoder::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
Decoder::AllocateFrame(uint32_t aFrameNum,
|
||||
const nsIntSize& aTargetSize,
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "mozilla/RefPtr.h"
|
||||
#include "DecodePool.h"
|
||||
#include "DecoderFlags.h"
|
||||
#include "Downscaler.h"
|
||||
#include "ImageMetadata.h"
|
||||
#include "Orientation.h"
|
||||
#include "SourceBuffer.h"
|
||||
|
@ -112,19 +113,14 @@ public:
|
|||
* If this decoder supports downscale-during-decode, sets the target size that
|
||||
* this image should be decoded to.
|
||||
*
|
||||
* If this decoder *doesn't* support downscale-during-decode, returns
|
||||
* NS_ERROR_NOT_AVAILABLE. If the provided size is unacceptable, returns
|
||||
* another error.
|
||||
* If the provided size is unacceptable, an error is returned.
|
||||
*
|
||||
* Returning NS_OK from this method is a promise that the decoder will decode
|
||||
* the image to the requested target size unless it encounters an error.
|
||||
*
|
||||
* This must be called before Init() is called.
|
||||
*/
|
||||
virtual nsresult SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
nsresult SetTargetSize(const nsIntSize& aSize);
|
||||
|
||||
/**
|
||||
* Set the requested sample size for this decoder. Used to implement the
|
||||
|
@ -403,6 +399,8 @@ protected:
|
|||
imgFrame* aPreviousFrame);
|
||||
|
||||
protected:
|
||||
Maybe<Downscaler> mDownscaler;
|
||||
|
||||
uint8_t* mImageData; // Pointer to image data in either Cairo or 8bit format
|
||||
uint32_t mImageDataLength;
|
||||
uint32_t* mColormap; // Current colormap to be used in Cairo format
|
||||
|
|
|
@ -133,8 +133,6 @@ DecoderFactory::CreateDecoder(DecoderType aType,
|
|||
// Set a target size for downscale-during-decode if applicable.
|
||||
if (aTargetSize) {
|
||||
DebugOnly<nsresult> rv = decoder->SetTargetSize(*aTargetSize);
|
||||
MOZ_ASSERT(nsresult(rv) != NS_ERROR_NOT_AVAILABLE,
|
||||
"We're downscale-during-decode but decoder doesn't support it?");
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
|
||||
}
|
||||
|
||||
|
|
|
@ -64,20 +64,6 @@ nsBMPDecoder::~nsBMPDecoder()
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBMPDecoder::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Sets whether or not the BMP will use alpha data
|
||||
void
|
||||
nsBMPDecoder::SetUseAlphaData(bool useAlphaData)
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
|
||||
#include "BMPFileHeaders.h"
|
||||
#include "Decoder.h"
|
||||
#include "Downscaler.h"
|
||||
#include "gfxColor.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
|
@ -25,8 +24,6 @@ class nsBMPDecoder : public Decoder
|
|||
public:
|
||||
~nsBMPDecoder();
|
||||
|
||||
nsresult SetTargetSize(const nsIntSize& aSize) override;
|
||||
|
||||
// Specifies whether or not the BMP file will contain alpha data
|
||||
// If set to true and the BMP is 32BPP, the alpha data will be
|
||||
// retrieved from the 4th byte of image data per pixel
|
||||
|
@ -77,8 +74,6 @@ private:
|
|||
char mRawBuf[BIH_INTERNAL_LENGTH::WIN_V3]; //< If this is changed,
|
||||
// WriteInternal() MUST be updated
|
||||
|
||||
Maybe<Downscaler> mDownscaler;
|
||||
|
||||
uint32_t mLOH; //< Length of the header
|
||||
|
||||
uint32_t mNumColors; //< The number of used colors, i.e. the number of
|
||||
|
|
|
@ -99,20 +99,6 @@ nsGIFDecoder2::~nsGIFDecoder2()
|
|||
free(mGIFStruct.hold);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGIFDecoder2::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint8_t*
|
||||
nsGIFDecoder2::GetCurrentRowBuffer()
|
||||
{
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#define mozilla_image_decoders_nsGIFDecoder2_h
|
||||
|
||||
#include "Decoder.h"
|
||||
#include "Downscaler.h"
|
||||
|
||||
#include "GIF2.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -25,8 +24,6 @@ class nsGIFDecoder2 : public Decoder
|
|||
public:
|
||||
~nsGIFDecoder2();
|
||||
|
||||
nsresult SetTargetSize(const nsIntSize& aSize) override;
|
||||
|
||||
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
|
||||
virtual void FinishInternal() override;
|
||||
virtual Telemetry::ID SpeedHistogram() override;
|
||||
|
@ -73,7 +70,6 @@ private:
|
|||
bool mSawTransparency;
|
||||
|
||||
gif_struct mGIFStruct;
|
||||
Maybe<Downscaler> mDownscaler;
|
||||
Maybe<Deinterlacer> mDeinterlacer;
|
||||
};
|
||||
|
||||
|
|
|
@ -71,20 +71,6 @@ nsICODecoder::nsICODecoder(RasterImage* aImage)
|
|||
, mCurrMaskLine(0)
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
nsICODecoder::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsICODecoder::FinishInternal()
|
||||
{
|
||||
|
|
|
@ -43,8 +43,6 @@ class nsICODecoder : public Decoder
|
|||
public:
|
||||
virtual ~nsICODecoder() { }
|
||||
|
||||
nsresult SetTargetSize(const nsIntSize& aSize) override;
|
||||
|
||||
/// @return the width of the icon directory entry @aEntry.
|
||||
static uint32_t GetRealWidth(const IconDirEntry& aEntry)
|
||||
{
|
||||
|
@ -119,7 +117,6 @@ private:
|
|||
LexerTransition<ICOState> FinishResource();
|
||||
|
||||
StreamingLexer<ICOState, 32> mLexer; // The lexer.
|
||||
Maybe<Downscaler> mDownscaler; // Our downscaler, if we're downscaling.
|
||||
nsRefPtr<Decoder> mContainedDecoder; // Either a BMP or PNG decoder.
|
||||
char mBIHraw[40]; // The bitmap information header.
|
||||
IconDirEntry mDirEntry; // The dir entry for the selected resource.
|
||||
|
|
|
@ -33,20 +33,6 @@ nsIconDecoder::nsIconDecoder(RasterImage* aImage)
|
|||
nsIconDecoder::~nsIconDecoder()
|
||||
{ }
|
||||
|
||||
nsresult
|
||||
nsIconDecoder::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsIconDecoder::WriteInternal(const char* aBuffer, uint32_t aCount)
|
||||
{
|
||||
|
|
|
@ -39,8 +39,6 @@ class nsIconDecoder : public Decoder
|
|||
public:
|
||||
virtual ~nsIconDecoder();
|
||||
|
||||
virtual nsresult SetTargetSize(const nsIntSize& aSize) override;
|
||||
|
||||
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
|
||||
|
||||
private:
|
||||
|
@ -49,8 +47,6 @@ private:
|
|||
// Decoders should only be instantiated via DecoderFactory.
|
||||
explicit nsIconDecoder(RasterImage* aImage);
|
||||
|
||||
Maybe<Downscaler> mDownscaler;
|
||||
|
||||
uint32_t mExpectedDataLength;
|
||||
uint32_t mPixBytesRead;
|
||||
uint32_t mState;
|
||||
|
|
|
@ -136,20 +136,6 @@ nsJPEGDecoder::SpeedHistogram()
|
|||
return Telemetry::IMAGE_DECODE_SPEED_JPEG;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJPEGDecoder::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsJPEGDecoder::InitInternal()
|
||||
{
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "Decoder.h"
|
||||
|
||||
#include "Downscaler.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
|
@ -55,8 +54,6 @@ class nsJPEGDecoder : public Decoder
|
|||
public:
|
||||
virtual ~nsJPEGDecoder();
|
||||
|
||||
virtual nsresult SetTargetSize(const nsIntSize& aSize) override;
|
||||
|
||||
virtual void SetSampleSize(int aSampleSize) override
|
||||
{
|
||||
mSampleSize = aSampleSize;
|
||||
|
@ -73,8 +70,6 @@ protected:
|
|||
Orientation ReadOrientationFromEXIF();
|
||||
void OutputScanlines(bool* suspend);
|
||||
|
||||
Maybe<Downscaler> mDownscaler;
|
||||
|
||||
private:
|
||||
friend class DecoderFactory;
|
||||
|
||||
|
|
|
@ -141,20 +141,6 @@ nsPNGDecoder::~nsPNGDecoder()
|
|||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPNGDecoder::SetTargetSize(const nsIntSize& aSize)
|
||||
{
|
||||
// Make sure the size is reasonable.
|
||||
if (MOZ_UNLIKELY(aSize.width <= 0 || aSize.height <= 0)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// Create a downscaler that we'll filter our output through.
|
||||
mDownscaler.emplace(aSize);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsPNGDecoder::CheckForTransparency(SurfaceFormat aFormat,
|
||||
const IntRect& aFrameRect)
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#define mozilla_image_decoders_nsPNGDecoder_h
|
||||
|
||||
#include "Decoder.h"
|
||||
#include "Downscaler.h"
|
||||
|
||||
#include "gfxTypes.h"
|
||||
|
||||
|
@ -27,8 +26,6 @@ class nsPNGDecoder : public Decoder
|
|||
public:
|
||||
virtual ~nsPNGDecoder();
|
||||
|
||||
virtual nsresult SetTargetSize(const nsIntSize& aSize) override;
|
||||
|
||||
virtual void InitInternal() override;
|
||||
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) override;
|
||||
virtual Telemetry::ID SpeedHistogram() override;
|
||||
|
@ -85,7 +82,6 @@ private:
|
|||
|
||||
public:
|
||||
png_structp mPNG;
|
||||
Maybe<Downscaler> mDownscaler;
|
||||
png_infop mInfo;
|
||||
nsIntRect mFrameRect;
|
||||
uint8_t* mCMSLine;
|
||||
|
|
Загрузка…
Ссылка в новой задаче