// CreateFrame() is used for both simple and animated images void nsPNGDecoder::CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset, int32_t width, int32_t height, gfx::SurfaceFormat format) { MOZ_ASSERT(HasSize()); if (format == gfx::SurfaceFormat::B8G8R8A8) { PostHasTransparency(); } // Our first full frame is automatically created by the image decoding // infrastructure. Just use it as long as it matches up. nsIntRect neededRect(x_offset, y_offset, width, height); nsRefPtr<imgFrame> currentFrame = GetCurrentFrame(); if (!currentFrame->GetRect().IsEqualEdges(neededRect)) { if (mNumFrames == 0) { // We need padding on the first frame, which means that we don't draw into // part of the image at all. Report that as transparency. PostHasTransparency(); } NeedNewFrame(mNumFrames, x_offset, y_offset, width, height, format); } else if (mNumFrames != 0) { NeedNewFrame(mNumFrames, x_offset, y_offset, width, height, format); } mFrameRect = neededRect; MOZ_LOG(GetPNGDecoderAccountingLog(), LogLevel::Debug, ("PNGDecoderAccounting: nsPNGDecoder::CreateFrame -- created " "image frame with %dx%d pixels in container %p", width, height, &mImage)); #ifdef PNG_APNG_SUPPORTED if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) { mAnimInfo = AnimFrameInfo(mPNG, mInfo); if (mAnimInfo.mDispose == DisposalMethod::CLEAR) { // We may have to display the background under this image during // animation playback, so we regard it as transparent. PostHasTransparency(); } } #endif }
//****************************************************************************** void nsGIFDecoder2::BeginImageFrame(uint16_t aDepth) { MOZ_ASSERT(HasSize()); gfx::SurfaceFormat format; if (mGIFStruct.is_transparent) { format = gfx::SurfaceFormat::B8G8R8A8; PostHasTransparency(); } else { format = gfx::SurfaceFormat::B8G8R8X8; } // Use correct format, RGB for first frame, PAL for following frames // and include transparency to allow for optimization of opaque images if (mGIFStruct.images_decoded) { // Image data is stored with original depth and palette NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height, format, aDepth); } else { nsRefPtr<imgFrame> currentFrame = GetCurrentFrame(); // Our first full frame is automatically created by the image decoding // infrastructure. Just use it as long as it matches up. if (!currentFrame->GetRect().IsEqualEdges(nsIntRect(mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height))) { // We need padding on the first frame, which means that we don't draw into // part of the image at all. Report that as transparency. PostHasTransparency(); // Regardless of depth of input, image is decoded into 24bit RGB NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height, format); } } mCurrentFrameIndex = mGIFStruct.images_decoded; }
//****************************************************************************** void nsGIFDecoder2::BeginImageFrame(uint16_t aDepth) { gfx::SurfaceFormat format; if (mGIFStruct.is_transparent) format = gfx::SurfaceFormat::B8G8R8A8; else format = gfx::SurfaceFormat::B8G8R8X8; MOZ_ASSERT(HasSize()); // Use correct format, RGB for first frame, PAL for following frames // and include transparency to allow for optimization of opaque images if (mGIFStruct.images_decoded) { // Image data is stored with original depth and palette NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height, format, aDepth); } // Our first full frame is automatically created by the image decoding // infrastructure. Just use it as long as it matches up. else if (!GetCurrentFrame()->GetRect().IsEqualEdges(nsIntRect(mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height))) { // Regardless of depth of input, image is decoded into 24bit RGB NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height, format); } else { // Our preallocated frame matches up, with the possible exception of alpha. if (format == gfx::SurfaceFormat::B8G8R8X8) { GetCurrentFrame()->SetHasNoAlpha(); } } mCurrentFrameIndex = mGIFStruct.images_decoded; }
//****************************************************************************** void nsGIFDecoder2::BeginImageFrame(uint16_t aDepth) { gfxASurface::gfxImageFormat format; if (mGIFStruct.is_transparent) format = gfxASurface::ImageFormatARGB32; else format = gfxASurface::ImageFormatRGB24; // Use correct format, RGB for first frame, PAL for following frames // and include transparency to allow for optimization of opaque images if (mGIFStruct.images_decoded) { // Image data is stored with original depth and palette NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height, format, aDepth); } else { // Regardless of depth of input, image is decoded into 24bit RGB NeedNewFrame(mGIFStruct.images_decoded, mGIFStruct.x_offset, mGIFStruct.y_offset, mGIFStruct.width, mGIFStruct.height, format); } mCurrentFrame = mGIFStruct.images_decoded; }
// CreateFrame() is used for both simple and animated images void nsPNGDecoder::CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset, int32_t width, int32_t height, gfx::SurfaceFormat format) { // Our first full frame is automatically created by the image decoding // infrastructure. Just use it as long as it matches up. MOZ_ASSERT(HasSize()); if (mNumFrames != 0 || !GetCurrentFrame()->GetRect().IsEqualEdges(nsIntRect(x_offset, y_offset, width, height))) { NeedNewFrame(mNumFrames, x_offset, y_offset, width, height, format); } else if (mNumFrames == 0) { // Our preallocated frame matches up, with the possible exception of alpha. if (format == gfx::SurfaceFormat::B8G8R8X8) { GetCurrentFrame()->SetHasNoAlpha(); } } mFrameRect.x = x_offset; mFrameRect.y = y_offset; mFrameRect.width = width; mFrameRect.height = height; PR_LOG(GetPNGDecoderAccountingLog(), PR_LOG_DEBUG, ("PNGDecoderAccounting: nsPNGDecoder::CreateFrame -- created " "image frame with %dx%d pixels in container %p", width, height, &mImage)); mFrameHasNoAlpha = true; #ifdef PNG_APNG_SUPPORTED if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL)) { mAnimInfo = AnimFrameInfo(mPNG, mInfo); } #endif }