Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "gfxAlphaRecovery.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "gfxImageSurface.h" |
michael@0 | 9 | |
michael@0 | 10 | #define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2 |
michael@0 | 11 | #include "mozilla/SSE.h" |
michael@0 | 12 | |
michael@0 | 13 | /* static */ bool |
michael@0 | 14 | gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf, |
michael@0 | 15 | const gfxImageSurface* whiteSurf) |
michael@0 | 16 | { |
michael@0 | 17 | gfxIntSize size = blackSurf->GetSize(); |
michael@0 | 18 | |
michael@0 | 19 | if (size != whiteSurf->GetSize() || |
michael@0 | 20 | (blackSurf->Format() != gfxImageFormat::ARGB32 && |
michael@0 | 21 | blackSurf->Format() != gfxImageFormat::RGB24) || |
michael@0 | 22 | (whiteSurf->Format() != gfxImageFormat::ARGB32 && |
michael@0 | 23 | whiteSurf->Format() != gfxImageFormat::RGB24)) |
michael@0 | 24 | return false; |
michael@0 | 25 | |
michael@0 | 26 | #ifdef MOZILLA_MAY_SUPPORT_SSE2 |
michael@0 | 27 | if (mozilla::supports_sse2() && |
michael@0 | 28 | RecoverAlphaSSE2(blackSurf, whiteSurf)) { |
michael@0 | 29 | return true; |
michael@0 | 30 | } |
michael@0 | 31 | #endif |
michael@0 | 32 | |
michael@0 | 33 | blackSurf->Flush(); |
michael@0 | 34 | whiteSurf->Flush(); |
michael@0 | 35 | |
michael@0 | 36 | unsigned char* blackData = blackSurf->Data(); |
michael@0 | 37 | unsigned char* whiteData = whiteSurf->Data(); |
michael@0 | 38 | |
michael@0 | 39 | for (int32_t i = 0; i < size.height; ++i) { |
michael@0 | 40 | uint32_t* blackPixel = reinterpret_cast<uint32_t*>(blackData); |
michael@0 | 41 | const uint32_t* whitePixel = reinterpret_cast<uint32_t*>(whiteData); |
michael@0 | 42 | for (int32_t j = 0; j < size.width; ++j) { |
michael@0 | 43 | uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]); |
michael@0 | 44 | blackPixel[j] = recovered; |
michael@0 | 45 | } |
michael@0 | 46 | blackData += blackSurf->Stride(); |
michael@0 | 47 | whiteData += whiteSurf->Stride(); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | blackSurf->MarkDirty(); |
michael@0 | 51 | |
michael@0 | 52 | return true; |
michael@0 | 53 | } |