michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "gfxAlphaRecovery.h" michael@0: michael@0: #include "gfxImageSurface.h" michael@0: michael@0: #define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2 michael@0: #include "mozilla/SSE.h" michael@0: michael@0: /* static */ bool michael@0: gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf, michael@0: const gfxImageSurface* whiteSurf) michael@0: { michael@0: gfxIntSize size = blackSurf->GetSize(); michael@0: michael@0: if (size != whiteSurf->GetSize() || michael@0: (blackSurf->Format() != gfxImageFormat::ARGB32 && michael@0: blackSurf->Format() != gfxImageFormat::RGB24) || michael@0: (whiteSurf->Format() != gfxImageFormat::ARGB32 && michael@0: whiteSurf->Format() != gfxImageFormat::RGB24)) michael@0: return false; michael@0: michael@0: #ifdef MOZILLA_MAY_SUPPORT_SSE2 michael@0: if (mozilla::supports_sse2() && michael@0: RecoverAlphaSSE2(blackSurf, whiteSurf)) { michael@0: return true; michael@0: } michael@0: #endif michael@0: michael@0: blackSurf->Flush(); michael@0: whiteSurf->Flush(); michael@0: michael@0: unsigned char* blackData = blackSurf->Data(); michael@0: unsigned char* whiteData = whiteSurf->Data(); michael@0: michael@0: for (int32_t i = 0; i < size.height; ++i) { michael@0: uint32_t* blackPixel = reinterpret_cast(blackData); michael@0: const uint32_t* whitePixel = reinterpret_cast(whiteData); michael@0: for (int32_t j = 0; j < size.width; ++j) { michael@0: uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]); michael@0: blackPixel[j] = recovered; michael@0: } michael@0: blackData += blackSurf->Stride(); michael@0: whiteData += whiteSurf->Stride(); michael@0: } michael@0: michael@0: blackSurf->MarkDirty(); michael@0: michael@0: return true; michael@0: }