No bug - tagging 2af34b4c9adf8c8defd3251b569af9c38cc0a429 with FIREFOX_BETA_124_BASE...
[gecko.git] / gfx / thebes / gfxAlphaRecovery.cpp
blobde36b84b22d6a50254169aafa463eae0bee65729
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gfxAlphaRecovery.h"
8 #include "gfxImageSurface.h"
10 #define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2
11 #include "mozilla/SSE.h"
13 #include <xsimd/xsimd.hpp>
15 /* static */
16 bool gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
17 const gfxImageSurface* whiteSurf) {
18 mozilla::gfx::IntSize size = blackSurf->GetSize();
20 if (size != whiteSurf->GetSize() ||
21 (blackSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
22 blackSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32) ||
23 (whiteSurf->Format() != mozilla::gfx::SurfaceFormat::A8R8G8B8_UINT32 &&
24 whiteSurf->Format() != mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32))
25 return false;
27 #ifdef MOZILLA_MAY_SUPPORT_SSE2
28 if (mozilla::supports_sse2() &&
29 RecoverAlphaGeneric<xsimd::sse2>(blackSurf, whiteSurf)) {
30 return true;
32 #endif
33 #ifdef MOZILLA_MAY_SUPPORT_NEON
34 if (mozilla::supports_neon() &&
35 RecoverAlphaGeneric<xsimd::neon>(blackSurf, whiteSurf)) {
36 return true;
38 #endif
40 blackSurf->Flush();
41 whiteSurf->Flush();
43 unsigned char* blackData = blackSurf->Data();
44 unsigned char* whiteData = whiteSurf->Data();
46 for (int32_t i = 0; i < size.height; ++i) {
47 uint32_t* blackPixel = reinterpret_cast<uint32_t*>(blackData);
48 const uint32_t* whitePixel = reinterpret_cast<uint32_t*>(whiteData);
49 for (int32_t j = 0; j < size.width; ++j) {
50 uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]);
51 blackPixel[j] = recovered;
53 blackData += blackSurf->Stride();
54 whiteData += whiteSurf->Stride();
57 blackSurf->MarkDirty();
59 return true;