summaryrefslogtreecommitdiffstats
path: root/gfx/thebes/gfxAlphaRecovery.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /gfx/thebes/gfxAlphaRecovery.cpp
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/thebes/gfxAlphaRecovery.cpp')
-rw-r--r--gfx/thebes/gfxAlphaRecovery.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/gfx/thebes/gfxAlphaRecovery.cpp b/gfx/thebes/gfxAlphaRecovery.cpp
new file mode 100644
index 0000000000..98a78ed3cb
--- /dev/null
+++ b/gfx/thebes/gfxAlphaRecovery.cpp
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 20; 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 "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;
+}