From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- gfx/thebes/gfxAlphaRecovery.cpp | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 gfx/thebes/gfxAlphaRecovery.cpp (limited to 'gfx/thebes/gfxAlphaRecovery.cpp') diff --git a/gfx/thebes/gfxAlphaRecovery.cpp b/gfx/thebes/gfxAlphaRecovery.cpp new file mode 100644 index 0000000000..de36b84b22 --- /dev/null +++ b/gfx/thebes/gfxAlphaRecovery.cpp @@ -0,0 +1,60 @@ +/* -*- 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" + +#include + +/* 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() && + RecoverAlphaGeneric(blackSurf, whiteSurf)) { + return true; + } +#endif +#ifdef MOZILLA_MAY_SUPPORT_NEON + if (mozilla::supports_neon() && + RecoverAlphaGeneric(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(blackData); + const uint32_t* whitePixel = reinterpret_cast(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; +} -- cgit v1.2.3