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
|
|
|
|
|
|
|
#ifndef nsPNGDecoder_h__
|
|
|
|
#define nsPNGDecoder_h__
|
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
#include "Decoder.h"
|
2001-01-23 01:01:03 +03:00
|
|
|
|
2012-12-18 20:37:15 +04:00
|
|
|
#include "imgDecoderObserver.h"
|
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
|
|
|
#include "gfxASurface.h"
|
2001-01-26 15:05:55 +03:00
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "png.h"
|
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.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:
|
2012-12-18 20:37:15 +04:00
|
|
|
nsPNGDecoder(RasterImage &aImage, imgDecoderObserver* aObserver);
|
2001-01-23 01:01:03 +03:00
|
|
|
virtual ~nsPNGDecoder();
|
|
|
|
|
2010-09-12 19:22:30 +04:00
|
|
|
virtual void InitInternal();
|
2012-08-22 19:56:38 +04:00
|
|
|
virtual void WriteInternal(const char* aBuffer, uint32_t aCount);
|
2011-09-23 00:25:56 +04:00
|
|
|
virtual Telemetry::ID SpeedHistogram();
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2009-12-04 05:41:00 +03:00
|
|
|
void CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t width, int32_t height,
|
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
|
|
|
gfxASurface::gfxImageFormat format);
|
2007-03-21 02:56:50 +03:00
|
|
|
void SetAnimFrameInfo();
|
2009-12-04 05:41:00 +03:00
|
|
|
|
2008-02-13 13:53:17 +03:00
|
|
|
void EndImageFrame();
|
|
|
|
|
2011-11-05 14:48:26 +04: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-26 00:09:01 +04:00
|
|
|
{
|
2012-07-17 03:10:18 +04: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 14:48:26 +04:00
|
|
|
png_uint_32
|
|
|
|
png_width, // Unused
|
|
|
|
png_height; // Unused
|
2011-08-26 00:09:01 +04:00
|
|
|
|
2011-11-05 14:48:26 +04:00
|
|
|
int png_bit_depth,
|
|
|
|
png_color_type;
|
|
|
|
|
|
|
|
if (png_get_IHDR(mPNG, mInfo, &png_width, &png_height, &png_bit_depth,
|
|
|
|
&png_color_type, NULL, NULL, NULL)) {
|
|
|
|
|
|
|
|
return (png_color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
|
|
|
|
png_bit_depth == 8);
|
|
|
|
} else {
|
|
|
|
return false;
|
2011-08-26 00:09:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *mCMSLine;
|
|
|
|
uint8_t *interlacebuf;
|
|
|
|
uint8_t *mImageData;
|
2009-04-07 20:02:11 +04:00
|
|
|
qcms_profile *mInProfile;
|
|
|
|
qcms_transform *mTransform;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
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
|
|
|
gfxASurface::gfxImageFormat format;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
// For size decodes
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *mHeaderBuf;
|
|
|
|
uint32_t mHeaderBytesRead;
|
2009-09-13 02:44:18 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mChannels;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFrameHasNoAlpha;
|
|
|
|
bool mFrameIsHidden;
|
2010-08-23 06:30:46 +04:00
|
|
|
|
2011-01-13 04:45:13 +03:00
|
|
|
// whether CMS or premultiplied alpha are forced off
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCMSMode;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDisablePremultipliedAlpha;
|
2011-01-13 04:45:13 +03:00
|
|
|
|
2010-08-23 06:30:46 +04:00
|
|
|
/*
|
|
|
|
* libpng callbacks
|
|
|
|
*
|
|
|
|
* We put these in the class so that they can access protected members.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
2001-01-23 01:01:03 +03:00
|
|
|
#endif // nsPNGDecoder_h__
|