Bug 1208935 - Move Deinterlacer to a standalone file. r=seth
authorSteve Singer <steve@ssinger.info>
Mon, 28 Sep 2015 20:40:00 +0200
changeset 265190 b50322abc2863332513aa05e5e53ab3d8278672d
parent 265189 aa7e651a038a95c1f2eba8d869d66fb568c8b88c
child 265191 0ba93aad644ab455a6395b18a54c3bb4b121d9c1
push id29458
push userkwierso@gmail.com
push dateWed, 30 Sep 2015 20:49:32 +0000
treeherdermozilla-central@f2f8cb92dce4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseth
bugs1208935
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1208935 - Move Deinterlacer to a standalone file. r=seth
image/Deinterlacer.cpp
image/Deinterlacer.h
image/Downscaler.cpp
image/Downscaler.h
image/decoders/nsGIFDecoder2.h
image/moz.build
new file mode 100644
--- /dev/null
+++ b/image/Deinterlacer.cpp
@@ -0,0 +1,45 @@
+/* -*- 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 http://mozilla.org/MPL/2.0/. */
+
+
+#include "Downscaler.h"
+
+namespace mozilla {
+namespace image {
+
+Deinterlacer::Deinterlacer(const nsIntSize& aImageSize)
+  : mImageSize(aImageSize)
+  , mBuffer(MakeUnique<uint8_t[]>(mImageSize.width *
+                                  mImageSize.height *
+                                  sizeof(uint32_t)))
+{ }
+
+uint32_t
+Deinterlacer::RowSize() const
+{
+  return mImageSize.width * sizeof(uint32_t);
+}
+
+uint8_t*
+Deinterlacer::RowBuffer(uint32_t aRow)
+{
+  uint32_t offset = aRow * RowSize();
+  MOZ_ASSERT(offset < mImageSize.width * mImageSize.height * sizeof(uint32_t),
+             "Row is outside of image");
+  return mBuffer.get() + offset;
+}
+
+void
+Deinterlacer::PropagatePassToDownscaler(Downscaler& aDownscaler)
+{
+  for (int32_t row = 0 ; row < mImageSize.height ; ++row) {
+    memcpy(aDownscaler.RowBuffer(), RowBuffer(row), RowSize());
+    aDownscaler.CommitRow();
+  }
+}
+
+} // namespace image
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/image/Deinterlacer.h
@@ -0,0 +1,50 @@
+/* -*- 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 http://mozilla.org/MPL/2.0/. */
+
+
+/**
+ * Deinterlacer is a utility class to allow Downscaler to work with interlaced
+ * images.
+
+ * Since Downscaler needs to receive rows in top-to-bottom or
+ * bottom-to-top order, it can't natively handle interlaced images, in which the
+ * rows arrive in an interleaved order. Deinterlacer solves this problem by
+ * acting as an intermediate buffer that records decoded rows. Unlike
+ * Downscaler, it allows the rows to be written in arbitrary order. After each
+ * pass, calling PropagatePassToDownscaler() will downscale every buffered row
+ * in a single operation. The rows remain in the buffer, so rows that were
+ * written in one pass will be included in subsequent passes.
+ */
+
+
+#ifndef mozilla_image_Deinterlacer_h
+#define mozilla_image_Deinterlacer_h
+
+#include "Downscaler.h"
+
+namespace mozilla {
+namespace image {
+
+class Deinterlacer
+{
+public:
+  explicit Deinterlacer(const nsIntSize& aImageSize);
+
+  uint8_t* RowBuffer(uint32_t aRow);
+  void PropagatePassToDownscaler(Downscaler& aDownscaler);
+
+private:
+  uint32_t RowSize() const;
+
+  nsIntSize mImageSize;
+  UniquePtr<uint8_t[]> mBuffer;
+};
+
+
+} // namespace image
+} // namespace mozilla
+
+#endif // mozilla_image_Deinterlacer_h
--- a/image/Downscaler.cpp
+++ b/image/Downscaler.cpp
@@ -309,41 +309,12 @@ Downscaler::DownscaleInputLine()
   // Shift the buffer. We're just moving pointers here, so this is cheap.
   mLinesInBuffer -= diff;
   mLinesInBuffer = max(mLinesInBuffer, 0);
   for (int32_t i = 0; i < mLinesInBuffer; ++i) {
     swap(mWindow[i], mWindow[filterLength - mLinesInBuffer + i]);
   }
 }
 
-Deinterlacer::Deinterlacer(const nsIntSize& aImageSize)
-  : mImageSize(aImageSize)
-  , mBuffer(MakeUnique<uint8_t[]>(mImageSize.width *
-                                  mImageSize.height *
-                                  sizeof(uint32_t)))
-{ }
 
-uint32_t
-Deinterlacer::RowSize() const
-{
-  return mImageSize.width * sizeof(uint32_t);
-}
-
-uint8_t*
-Deinterlacer::RowBuffer(uint32_t aRow)
-{
-  uint32_t offset = aRow * RowSize();
-  MOZ_ASSERT(offset < mImageSize.width * mImageSize.height * sizeof(uint32_t),
-             "Row is outside of image");
-  return mBuffer.get() + offset;
-}
-
-void
-Deinterlacer::PropagatePassToDownscaler(Downscaler& aDownscaler)
-{
-  for (int32_t row = 0 ; row < mImageSize.height ; ++row) {
-    memcpy(aDownscaler.RowBuffer(), RowBuffer(row), RowSize());
-    aDownscaler.CommitRow();
-  }
-}
 
 } // namespace image
 } // namespace mozilla
--- a/image/Downscaler.h
+++ b/image/Downscaler.h
@@ -157,49 +157,23 @@ public:
   const gfxSize& Scale() const { return gfxSize(1.0, 1.0); }
 
   nsresult BeginFrame(const nsIntSize&, uint8_t*, bool, bool = false)
   {
     return NS_ERROR_FAILURE;
   }
 
   uint8_t* RowBuffer() { return nullptr; }
-  void ClearRow(uint32_t = 0);
+  void ClearRow(uint32_t = 0) { }
   void CommitRow() { }
   bool HasInvalidation() const { return false; }
   DownscalerInvalidRect TakeInvalidRect() { return DownscalerInvalidRect(); }
   void ResetForNextProgressivePass() { }
 };
 
 #endif // MOZ_ENABLE_SKIA
 
-/**
- * Deinterlacer is a utility class to allow Downscaler to work with interlaced
- * images.
 
- * Since Downscaler needs to receive rows in top-to-bottom or
- * bottom-to-top order, it can't natively handle interlaced images, in which the
- * rows arrive in an interleaved order. Deinterlacer solves this problem by
- * acting as an intermediate buffer that records decoded rows. Unlike
- * Downscaler, it allows the rows to be written in arbitrary order. After each
- * pass, calling PropagatePassToDownscaler() will downscale every buffered row
- * in a single operation. The rows remain in the buffer, so rows that were
- * written in one pass will be included in subsequent passes.
- */
-class Deinterlacer
-{
-public:
-  explicit Deinterlacer(const nsIntSize& aImageSize);
-
-  uint8_t* RowBuffer(uint32_t aRow);
-  void PropagatePassToDownscaler(Downscaler& aDownscaler);
-
-private:
-  uint32_t RowSize() const;
-
-  nsIntSize mImageSize;
-  UniquePtr<uint8_t[]> mBuffer;
-};
 
 } // namespace image
 } // namespace mozilla
 
 #endif // mozilla_image_Downscaler_h
--- a/image/decoders/nsGIFDecoder2.h
+++ b/image/decoders/nsGIFDecoder2.h
@@ -3,17 +3,17 @@
  * 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/. */
 
 #ifndef mozilla_image_decoders_nsGIFDecoder2_h
 #define mozilla_image_decoders_nsGIFDecoder2_h
 
 #include "Decoder.h"
-
+#include "Deinterlacer.h"
 #include "GIF2.h"
 #include "nsCOMPtr.h"
 
 namespace mozilla {
 namespace image {
 class RasterImage;
 
 //////////////////////////////////////////////////////////////////////
--- a/image/moz.build
+++ b/image/moz.build
@@ -49,16 +49,17 @@ EXPORTS += [
     'SurfaceFlags.h',
 ]
 
 UNIFIED_SOURCES += [
     'ClippedImage.cpp',
     'DecodePool.cpp',
     'Decoder.cpp',
     'DecoderFactory.cpp',
+    'Deinterlacer.cpp',
     'DynamicImage.cpp',
     'FrameAnimator.cpp',
     'FrozenImage.cpp',
     'Image.cpp',
     'ImageCacheKey.cpp',
     'ImageFactory.cpp',
     'ImageOps.cpp',
     'ImageWrapper.cpp',