author L10n Bumper Bot <>
Thu, 08 Nov 2018 03:00:11 -0800
changeset 501100 1cd4f2d571554c4dc89cf1be1d98683c0d14f797
parent 451441 570db0492055ac9bd86af8c13cbdb16148578ff9
child 508163 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
no bug - Bumping Fennec l10n changesets r=release a=l10n-bump DONTBUILD an -> 336e061995b9 ar -> f6834a7d7374 as -> d2c76e616a66 ast -> fcb8f3455237 az -> c4caf3b07cf2 be -> 697eb1022498 bg -> 7bf1f448f743 bn-BD -> 5f7a87adee06 bn-IN -> 49ce3195c4c2 br -> 41cf35b7c5b5 bs -> 4a14aee27904 ca -> 9373e8ce86d4 cak -> a40d767541ba cs -> 4b99defb0525 cy -> 4c948fed2584 de -> 017a7e7a267a dsb -> aadebeccf5ba el -> 2d28a78dcef5 en-CA -> 55ad9171a9f0 en-GB -> 296422b495e9 en-ZA -> c1b5d2128914 eo -> c68e87667d9f es-AR -> bff0a788c711 es-CL -> 1d3efd2532ea es-ES -> 4d1feb70b0e2 es-MX -> fceda607d0f4 et -> 58a8262a0cc7 eu -> 7cebfd46208b fa -> cbc040d58476 ff -> 46f5aec275ea fi -> 235ab13d261e fr -> 8ee417b64f99

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 * 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 */

 * Downscaler is a high-quality, streaming image downscaler based upon Skia's
 * scaling implementation.

#ifndef mozilla_image_Downscaler_h
#define mozilla_image_Downscaler_h

#include "mozilla/Maybe.h"
#include "mozilla/UniquePtr.h"
#include "gfxPoint.h"
#include "nsRect.h"
#include "mozilla/gfx/ConvolutionFilter.h"

namespace mozilla {
namespace image {

 * DownscalerInvalidRect wraps two invalidation rects: one in terms of the
 * original image size, and one in terms of the target size.
struct DownscalerInvalidRect
  nsIntRect mOriginalSizeRect;
  nsIntRect mTargetSizeRect;


 * Downscaler is a high-quality, streaming image downscaler based upon Skia's
 * scaling implementation.
 * Decoders can construct a Downscaler once they know their target size, then
 * call BeginFrame() for each frame they decode. They should write a decoded row
 * into the buffer returned by RowBuffer(), and then call CommitRow() to signal
 * that they have finished.

 * Because invalidations need to be computed in terms of the scaled version of
 * the image, Downscaler also tracks them. Decoders can call HasInvalidation()
 * and TakeInvalidRect() instead of tracking invalidations themselves.
class Downscaler
  /// Constructs a new Downscaler which to scale to size @aTargetSize.
  explicit Downscaler(const nsIntSize& aTargetSize);

  const nsIntSize& OriginalSize() const { return mOriginalSize; }
  const nsIntSize& TargetSize() const { return mTargetSize; }
  const nsIntSize FrameSize() const { return nsIntSize(mFrameRect.Width(), mFrameRect.Height()); }
  const gfxSize& Scale() const { return mScale; }

   * Begins a new frame and reinitializes the Downscaler.
   * @param aOriginalSize The original size of this frame, before scaling.
   * @param aFrameRect The region of  the original image which has data.
   *                   Every pixel outside @aFrameRect is considered blank and
   *                   has zero alpha.
   * @param aOutputBuffer The buffer to which the Downscaler should write its
   *                      output; this is the same buffer where the Decoder
   *                      would write its output when not downscaling during
   *                      decode.
   * @param aHasAlpha Whether or not this frame has an alpha channel.
   *                  Performance is a little better if it doesn't have one.
   * @param aFlipVertically If true, output rows will be written to the output
   *                        buffer in reverse order vertically, which matches
   *                        the way they are stored in some image formats.
  nsresult BeginFrame(const nsIntSize& aOriginalSize,
                      const Maybe<nsIntRect>& aFrameRect,
                      uint8_t* aOutputBuffer,
                      bool aHasAlpha,
                      bool aFlipVertically = false);

  bool IsFrameComplete() const { return mCurrentInLine >= mOriginalSize.height; }

  /// Retrieves the buffer into which the Decoder should write each row.
  uint8_t* RowBuffer()
    return mRowBuffer.get() + mFrameRect.X() * sizeof(uint32_t);

  /// Clears the current row buffer.
  void ClearRow() { ClearRestOfRow(0); }

  /// Clears the current row buffer starting at @aStartingAtCol.
  void ClearRestOfRow(uint32_t aStartingAtCol);

  /// Signals that the decoder has finished writing a row into the row buffer.
  void CommitRow();

  /// Returns true if there is a non-empty invalid rect available.
  bool HasInvalidation() const;

  /// Takes the Downscaler's current invalid rect and resets it.
  DownscalerInvalidRect TakeInvalidRect();

   * Resets the Downscaler's position in the image, for a new progressive pass
   * over the same frame. Because the same data structures can be reused, this
   * is more efficient than calling BeginFrame.
  void ResetForNextProgressivePass();

  void DownscaleInputLine();
  void ReleaseWindow();
  void SkipToRow(int32_t aRow);

  nsIntSize mOriginalSize;
  nsIntSize mTargetSize;
  nsIntRect mFrameRect;
  gfxSize mScale;

  uint8_t* mOutputBuffer;

  UniquePtr<uint8_t[]> mRowBuffer;
  UniquePtr<uint8_t*[]> mWindow;

  gfx::ConvolutionFilter mXFilter;
  gfx::ConvolutionFilter mYFilter;

  int32_t mWindowCapacity;

  int32_t mLinesInBuffer;
  int32_t mPrevInvalidatedLine;
  int32_t mCurrentOutLine;
  int32_t mCurrentInLine;

  bool mHasAlpha : 1;
  bool mFlipVertically : 1;


 * Downscaler requires Skia to work, so we provide a dummy implementation if
 * Skia is disabled that asserts if constructed.

class Downscaler
  explicit Downscaler(const nsIntSize&) : mScale(1.0, 1.0)
    MOZ_RELEASE_ASSERT(false, "Skia is not enabled");

  const nsIntSize& OriginalSize() const { return mSize; }
  const nsIntSize& TargetSize() const { return mSize; }
  const gfxSize& Scale() const { return mScale; }

  nsresult BeginFrame(const nsIntSize&, const Maybe<nsIntRect>&, uint8_t*, bool, bool = false)
    return NS_ERROR_FAILURE;

  bool IsFrameComplete() const { return false; }
  uint8_t* RowBuffer() { return nullptr; }
  void ClearRow() { }
  void ClearRestOfRow(uint32_t) { }
  void CommitRow() { }
  bool HasInvalidation() const { return false; }
  DownscalerInvalidRect TakeInvalidRect() { return DownscalerInvalidRect(); }
  void ResetForNextProgressivePass() { }
  const nsIntSize FrameSize() const { return nsIntSize(0, 0); }
  nsIntSize mSize;
  gfxSize mScale;


} // namespace image
} // namespace mozilla

#endif // mozilla_image_Downscaler_h