Beispiel #1
0
// 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
}
Beispiel #2
0
// 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
}