2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
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
|
|
|
|
2014-09-24 14:38:00 -07:00
|
|
|
#ifndef nsPNGDecoder_h
|
|
|
|
#define nsPNGDecoder_h
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
#include "Decoder.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-09-24 13:45:14 -07:00
|
|
|
#include "gfxTypes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "png.h"
|
|
|
|
|
2009-04-07 09:02:11 -07:00
|
|
|
#include "qcms.h"
|
2007-07-23 15:02:17 -07:00
|
|
|
|
2010-08-13 21:09:49 -07:00
|
|
|
namespace mozilla {
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-08-13 21:09:49 -07:00
|
|
|
class RasterImage;
|
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
class nsPNGDecoder : public Decoder
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2015-01-11 05:34:20 -08:00
|
|
|
explicit nsPNGDecoder(RasterImage* aImage);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsPNGDecoder();
|
|
|
|
|
2015-01-02 16:16:57 -08:00
|
|
|
virtual void InitInternal() MOZ_OVERRIDE;
|
2015-01-08 00:04:31 -08:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount) MOZ_OVERRIDE;
|
2015-01-02 16:16:57 -08:00
|
|
|
virtual Telemetry::ID SpeedHistogram() MOZ_OVERRIDE;
|
2010-08-22 19:30:46 -07:00
|
|
|
|
2015-01-10 18:47:44 -08:00
|
|
|
nsresult CreateFrame(png_uint_32 aXOffset, png_uint_32 aYOffset,
|
|
|
|
int32_t aWidth, int32_t aHeight,
|
|
|
|
gfx::SurfaceFormat aFormat);
|
2008-02-13 02:53:17 -08:00
|
|
|
void EndImageFrame();
|
|
|
|
|
2011-11-05 03:48:26 -07:00
|
|
|
// Check if PNG is valid ICO (32bpp RGBA)
|
|
|
|
// http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
|
|
|
|
bool IsValidICO() const
|
2011-08-25 13:09:01 -07:00
|
|
|
{
|
2012-07-16 16:10:18 -07:00
|
|
|
// If there are errors in the call to png_get_IHDR, the error_callback in
|
|
|
|
// nsPNGDecoder.cpp is called. In this error callback we do a longjmp, so
|
|
|
|
// we need to save the jump buffer here. Oterwise we'll end up without a
|
|
|
|
// proper callstack.
|
|
|
|
if (setjmp(png_jmpbuf(mPNG))) {
|
|
|
|
// We got here from a longjmp call indirectly from png_get_IHDR
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-05 03:48:26 -07:00
|
|
|
png_uint_32
|
|
|
|
png_width, // Unused
|
|
|
|
png_height; // Unused
|
2011-08-25 13:09:01 -07:00
|
|
|
|
2011-11-05 03:48:26 -07:00
|
|
|
int png_bit_depth,
|
|
|
|
png_color_type;
|
|
|
|
|
|
|
|
if (png_get_IHDR(mPNG, mInfo, &png_width, &png_height, &png_bit_depth,
|
2013-08-23 12:51:00 -07:00
|
|
|
&png_color_type, nullptr, nullptr, nullptr)) {
|
2011-11-05 03:48:26 -07:00
|
|
|
|
2013-01-28 09:27:35 -08:00
|
|
|
return ((png_color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
|
|
|
|
png_color_type == PNG_COLOR_TYPE_RGB) &&
|
2011-11-05 03:48:26 -07:00
|
|
|
png_bit_depth == 8);
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-08-25 13:09:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
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-20 18:50:15 -07:00
|
|
|
nsIntRect mFrameRect;
|
2014-11-14 09:59:00 -08:00
|
|
|
uint8_t* mCMSLine;
|
|
|
|
uint8_t* interlacebuf;
|
|
|
|
qcms_profile* mInProfile;
|
|
|
|
qcms_transform* mTransform;
|
2007-07-23 15:02:17 -07:00
|
|
|
|
2014-04-19 18:28:38 -07:00
|
|
|
gfx::SurfaceFormat format;
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2010-08-22 19:30:46 -07:00
|
|
|
// For size decodes
|
2013-05-04 04:42:26 -07:00
|
|
|
uint8_t mSizeBytes[8]; // Space for width and height, both 4 bytes
|
|
|
|
uint32_t mHeaderBytesRead;
|
2013-05-04 02:39:47 -07:00
|
|
|
|
|
|
|
// whether CMS or premultiplied alpha are forced off
|
|
|
|
uint32_t mCMSMode;
|
2009-09-12 15:44:18 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mChannels;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mFrameHasNoAlpha;
|
|
|
|
bool mFrameIsHidden;
|
|
|
|
bool mDisablePremultipliedAlpha;
|
2013-02-27 11:23:08 -08:00
|
|
|
|
2013-04-22 07:57:17 -07:00
|
|
|
struct AnimFrameInfo
|
|
|
|
{
|
|
|
|
AnimFrameInfo();
|
|
|
|
#ifdef PNG_APNG_SUPPORTED
|
|
|
|
AnimFrameInfo(png_structp aPNG, png_infop aInfo);
|
|
|
|
#endif
|
|
|
|
|
2015-01-07 13:07:23 -08:00
|
|
|
DisposalMethod mDispose;
|
|
|
|
BlendMethod mBlend;
|
2013-04-22 07:57:17 -07:00
|
|
|
int32_t mTimeout;
|
|
|
|
};
|
|
|
|
|
|
|
|
AnimFrameInfo mAnimInfo;
|
|
|
|
|
2013-02-27 11:23:08 -08:00
|
|
|
// The number of frames we've finished.
|
|
|
|
uint32_t mNumFrames;
|
2014-11-14 09:59:00 -08:00
|
|
|
|
|
|
|
// libpng callbacks
|
|
|
|
// We put these in the class so that they can access protected members.
|
2010-08-22 19:30:46 -07: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-25 13:09:01 -07:00
|
|
|
|
|
|
|
// This is defined in the PNG spec as an invariant. We use it to
|
|
|
|
// do manual validation without libpng.
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint8_t pngSignatureBytes[];
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-08-22 19:30:46 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-09-24 14:38:00 -07:00
|
|
|
#endif // nsPNGDecoder_h
|