summaryrefslogtreecommitdiffstats
path: root/gfx/thebes/gfxAlphaRecovery.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /gfx/thebes/gfxAlphaRecovery.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/thebes/gfxAlphaRecovery.cpp')
-rw-r--r--gfx/thebes/gfxAlphaRecovery.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/gfx/thebes/gfxAlphaRecovery.cpp b/gfx/thebes/gfxAlphaRecovery.cpp
new file mode 100644
index 000000000..810fbeffa
--- /dev/null
+++ b/gfx/thebes/gfxAlphaRecovery.cpp
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * 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 "gfxAlphaRecovery.h"
+
+#include "gfxImageSurface.h"
+
+#define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2
+#include "mozilla/SSE.h"
+
+/* static */ bool
+gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
+ const gfxImageSurface* whiteSurf)
+{
+ mozilla::gfx::IntSize size = blackSurf->GetSize();
+
+ if (size != whiteSurf->GetSize() ||
+ (blackSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
+ blackSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) ||
+ (whiteSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
+ whiteSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32))
+ return false;
+
+#ifdef MOZILLA_MAY_SUPPORT_SSE2
+ if (mozilla::supports_sse2() &&
+ RecoverAlphaSSE2(blackSurf, whiteSurf)) {
+ return true;
+ }
+#endif
+
+ blackSurf->Flush();
+ whiteSurf->Flush();
+
+ unsigned char* blackData = blackSurf->Data();
+ unsigned char* whiteData = whiteSurf->Data();
+
+ for (int32_t i = 0; i < size.height; ++i) {
+ uint32_t* blackPixel = reinterpret_cast<uint32_t*>(blackData);
+ const uint32_t* whitePixel = reinterpret_cast<uint32_t*>(whiteData);
+ for (int32_t j = 0; j < size.width; ++j) {
+ uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]);
+ blackPixel[j] = recovered;
+ }
+ blackData += blackSurf->Stride();
+ whiteData += whiteSurf->Stride();
+ }
+
+ blackSurf->MarkDirty();
+
+ return true;
+}