2001-01-23 01:01:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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-01-23 01:01:03 +03:00
|
|
|
|
2015-04-06 02:22:00 +03:00
|
|
|
#ifndef mozilla_image_decoders_nsPNGDecoder_h
|
|
|
|
#define mozilla_image_decoders_nsPNGDecoder_h
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
#include "png.h"
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.h"
|
2016-06-27 23:38:34 +03:00
|
|
|
#include "StreamingLexer.h"
|
2016-06-25 01:20:32 +03:00
|
|
|
#include "SurfacePipe.h"
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
namespace mozilla {
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-14 08:09:49 +04:00
|
|
|
class RasterImage;
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
class nsPNGDecoder : public Decoder
|
2001-01-23 01:01:03 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~nsPNGDecoder();
|
|
|
|
|
2016-08-03 02:45:22 +03:00
|
|
|
/// @return true if this PNG is a valid ICO resource.
|
|
|
|
bool IsValidICO() const;
|
|
|
|
|
|
|
|
protected:
|
2016-07-11 10:34:50 +03:00
|
|
|
nsresult InitInternal() override;
|
2016-07-16 08:27:12 +03:00
|
|
|
LexerResult DoDecode(SourceBufferIterator& aIterator,
|
|
|
|
IResumable* aOnResume) override;
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2017-02-15 22:15:15 +03:00
|
|
|
Maybe<Telemetry::HistogramID> SpeedHistogram() const override;
|
2016-07-03 06:22:06 +03:00
|
|
|
|
2016-06-25 01:20:32 +03:00
|
|
|
private:
|
|
|
|
friend class DecoderFactory;
|
|
|
|
|
|
|
|
// Decoders should only be instantiated via DecoderFactory.
|
|
|
|
explicit nsPNGDecoder(RasterImage* aImage);
|
|
|
|
|
2016-07-19 09:51:16 +03:00
|
|
|
/// The information necessary to create a frame.
|
|
|
|
struct FrameInfo
|
|
|
|
{
|
|
|
|
gfx::IntRect mFrameRect;
|
|
|
|
bool mIsInterlaced;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult CreateFrame(const FrameInfo& aFrameInfo);
|
2008-02-13 13:53:17 +03:00
|
|
|
void EndImageFrame();
|
|
|
|
|
2016-08-18 16:55:45 +03:00
|
|
|
bool HasAlphaChannel() const
|
|
|
|
{
|
|
|
|
return mChannels == 2 || mChannels == 4;
|
|
|
|
}
|
|
|
|
|
2016-06-25 01:20:32 +03:00
|
|
|
enum class TransparencyType
|
|
|
|
{
|
|
|
|
eNone,
|
|
|
|
eAlpha,
|
|
|
|
eFrameRect
|
|
|
|
};
|
|
|
|
|
2016-08-18 16:55:45 +03:00
|
|
|
TransparencyType GetTransparencyType(const gfx::IntRect& aFrameRect);
|
2016-06-25 01:20:32 +03:00
|
|
|
void PostHasTransparencyIfNeeded(TransparencyType aTransparencyType);
|
|
|
|
|
|
|
|
void PostInvalidationIfNeeded();
|
|
|
|
|
|
|
|
void WriteRow(uint8_t* aRow);
|
2015-08-12 20:41:02 +03:00
|
|
|
|
2016-07-19 09:51:16 +03:00
|
|
|
// Convenience methods to make interacting with StreamingLexer from inside
|
|
|
|
// a libpng callback easier.
|
|
|
|
void DoTerminate(png_structp aPNGStruct, TerminalState aState);
|
|
|
|
void DoYield(png_structp aPNGStruct);
|
|
|
|
|
2016-06-27 23:38:34 +03:00
|
|
|
enum class State
|
|
|
|
{
|
|
|
|
PNG_DATA,
|
|
|
|
FINISHED_PNG_DATA
|
|
|
|
};
|
|
|
|
|
|
|
|
LexerTransition<State> ReadPNGData(const char* aData, size_t aLength);
|
|
|
|
LexerTransition<State> FinishedPNGData();
|
|
|
|
|
|
|
|
StreamingLexer<State> mLexer;
|
|
|
|
|
2016-07-19 09:51:16 +03:00
|
|
|
// The next lexer state transition. We need to store it here because we can't
|
|
|
|
// directly return arbitrary values from libpng callbacks.
|
|
|
|
LexerTransition<State> mNextTransition;
|
|
|
|
|
|
|
|
// We yield to the caller every time we finish decoding a frame. When this
|
|
|
|
// happens, we need to allocate the next frame after returning from the yield.
|
|
|
|
// |mNextFrameInfo| is used to store the information needed to allocate the
|
|
|
|
// next frame.
|
|
|
|
Maybe<FrameInfo> mNextFrameInfo;
|
|
|
|
|
|
|
|
// The length of the last chunk of data passed to ReadPNGData(). We use this
|
|
|
|
// to arrange to arrive back at the correct spot in the data after yielding.
|
|
|
|
size_t mLastChunkLength;
|
|
|
|
|
2001-02-21 01:43:56 +03:00
|
|
|
public:
|
2001-01-23 01:01:03 +03:00
|
|
|
png_structp mPNG;
|
|
|
|
png_infop mInfo;
|
Bug 753 - Remove nsIImage, gfxIImageFrame, and their implementations, and expose an equivalent api on imgIContainer. r=roc,josh,bz,longsonr,vlad,karlt,jimm,bsmedberg,mfinkle,peterw,peterv sr=vlad,roc
--HG--
rename : gfx/src/shared/gfxImageFrame.cpp => modules/libpr0n/src/imgFrame.cpp
rename : gfx/src/shared/gfxImageFrame.h => modules/libpr0n/src/imgFrame.h
2009-07-21 05:50:15 +04:00
|
|
|
nsIntRect mFrameRect;
|
2014-11-14 20:59:00 +03:00
|
|
|
uint8_t* mCMSLine;
|
|
|
|
uint8_t* interlacebuf;
|
|
|
|
qcms_profile* mInProfile;
|
|
|
|
qcms_transform* mTransform;
|
2016-08-18 16:55:45 +03:00
|
|
|
gfx::SurfaceFormat mFormat;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2013-05-04 13:39:47 +04:00
|
|
|
// whether CMS or premultiplied alpha are forced off
|
|
|
|
uint32_t mCMSMode;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mChannels;
|
2016-06-25 01:20:32 +03:00
|
|
|
uint8_t mPass;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFrameIsHidden;
|
|
|
|
bool mDisablePremultipliedAlpha;
|
2013-02-27 23:23:08 +04:00
|
|
|
|
2013-04-22 18:57:17 +04:00
|
|
|
struct AnimFrameInfo
|
|
|
|
{
|
|
|
|
AnimFrameInfo();
|
|
|
|
#ifdef PNG_APNG_SUPPORTED
|
|
|
|
AnimFrameInfo(png_structp aPNG, png_infop aInfo);
|
|
|
|
#endif
|
|
|
|
|
2015-01-08 00:07:23 +03:00
|
|
|
DisposalMethod mDispose;
|
|
|
|
BlendMethod mBlend;
|
2013-04-22 18:57:17 +04:00
|
|
|
int32_t mTimeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
AnimFrameInfo mAnimInfo;
|
|
|
|
|
2016-06-25 01:20:32 +03:00
|
|
|
SurfacePipe mPipe; /// The SurfacePipe used to write to the output surface.
|
|
|
|
|
2013-02-27 23:23:08 +04:00
|
|
|
// The number of frames we've finished.
|
|
|
|
uint32_t mNumFrames;
|
2014-11-14 20:59:00 +03:00
|
|
|
|
|
|
|
// libpng callbacks
|
|
|
|
// We put these in the class so that they can access protected members.
|
2010-08-23 06:30:46 +04:00
|
|
|
static void PNGAPI info_callback(png_structp png_ptr, png_infop info_ptr);
|
|
|
|
static void PNGAPI row_callback(png_structp png_ptr, png_bytep new_row,
|
|
|
|
png_uint_32 row_num, int pass);
|
|
|
|
#ifdef PNG_APNG_SUPPORTED
|
|
|
|
static void PNGAPI frame_info_callback(png_structp png_ptr,
|
|
|
|
png_uint_32 frame_num);
|
|
|
|
#endif
|
|
|
|
static void PNGAPI end_callback(png_structp png_ptr, png_infop info_ptr);
|
|
|
|
static void PNGAPI error_callback(png_structp png_ptr,
|
|
|
|
png_const_charp error_msg);
|
|
|
|
static void PNGAPI warning_callback(png_structp png_ptr,
|
|
|
|
png_const_charp warning_msg);
|
2011-08-26 00:09:01 +04:00
|
|
|
|
|
|
|
// This is defined in the PNG spec as an invariant. We use it to
|
|
|
|
// do manual validation without libpng.
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint8_t pngSignatureBytes[];
|
2001-01-23 01:01:03 +03:00
|
|
|
};
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-23 06:30:46 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-04-06 02:22:00 +03:00
|
|
|
#endif // mozilla_image_decoders_nsPNGDecoder_h
|