1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
24 class nsPNGDecoder
: public Decoder
27 explicit nsPNGDecoder(RasterImage
* aImage
);
28 virtual ~nsPNGDecoder();
30 virtual void InitInternal() MOZ_OVERRIDE
;
31 virtual void WriteInternal(const char* aBuffer
, uint32_t aCount
) MOZ_OVERRIDE
;
32 virtual Telemetry::ID
SpeedHistogram() MOZ_OVERRIDE
;
34 void CreateFrame(png_uint_32 x_offset
, png_uint_32 y_offset
,
35 int32_t width
, int32_t height
,
36 gfx::SurfaceFormat format
);
39 // Check if PNG is valid ICO (32bpp RGBA)
40 // http://blogs.msdn.com/b/oldnewthing/archive/2010/10/22/10079192.aspx
41 bool IsValidICO() const
43 // If there are errors in the call to png_get_IHDR, the error_callback in
44 // nsPNGDecoder.cpp is called. In this error callback we do a longjmp, so
45 // we need to save the jump buffer here. Oterwise we'll end up without a
47 if (setjmp(png_jmpbuf(mPNG
))) {
48 // We got here from a longjmp call indirectly from png_get_IHDR
59 if (png_get_IHDR(mPNG
, mInfo
, &png_width
, &png_height
, &png_bit_depth
,
60 &png_color_type
, nullptr, nullptr, nullptr)) {
62 return ((png_color_type
== PNG_COLOR_TYPE_RGB_ALPHA
||
63 png_color_type
== PNG_COLOR_TYPE_RGB
) &&
75 uint8_t* interlacebuf
;
76 qcms_profile
* mInProfile
;
77 qcms_transform
* mTransform
;
79 gfx::SurfaceFormat format
;
82 uint8_t mSizeBytes
[8]; // Space for width and height, both 4 bytes
83 uint32_t mHeaderBytesRead
;
85 // whether CMS or premultiplied alpha are forced off
89 bool mFrameHasNoAlpha
;
91 bool mDisablePremultipliedAlpha
;
96 #ifdef PNG_APNG_SUPPORTED
97 AnimFrameInfo(png_structp aPNG
, png_infop aInfo
);
100 DisposalMethod mDispose
;
105 AnimFrameInfo mAnimInfo
;
107 // The number of frames we've finished.
111 // We put these in the class so that they can access protected members.
112 static void PNGAPI
info_callback(png_structp png_ptr
, png_infop info_ptr
);
113 static void PNGAPI
row_callback(png_structp png_ptr
, png_bytep new_row
,
114 png_uint_32 row_num
, int pass
);
115 #ifdef PNG_APNG_SUPPORTED
116 static void PNGAPI
frame_info_callback(png_structp png_ptr
,
117 png_uint_32 frame_num
);
119 static void PNGAPI
end_callback(png_structp png_ptr
, png_infop info_ptr
);
120 static void PNGAPI
error_callback(png_structp png_ptr
,
121 png_const_charp error_msg
);
122 static void PNGAPI
warning_callback(png_structp png_ptr
,
123 png_const_charp warning_msg
);
125 // This is defined in the PNG spec as an invariant. We use it to
126 // do manual validation without libpng.
127 static const uint8_t pngSignatureBytes
[];
131 } // namespace mozilla
133 #endif // nsPNGDecoder_h