gfx/thebes/gfxAlphaRecovery.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxAlphaRecovery.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "gfxAlphaRecovery.h"
    1.10 +
    1.11 +#include "gfxImageSurface.h"
    1.12 +
    1.13 +#define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2
    1.14 +#include "mozilla/SSE.h"
    1.15 +
    1.16 +/* static */ bool
    1.17 +gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
    1.18 +                               const gfxImageSurface* whiteSurf)
    1.19 +{
    1.20 +    gfxIntSize size = blackSurf->GetSize();
    1.21 +
    1.22 +    if (size != whiteSurf->GetSize() ||
    1.23 +        (blackSurf->Format() != gfxImageFormat::ARGB32 &&
    1.24 +         blackSurf->Format() != gfxImageFormat::RGB24) ||
    1.25 +        (whiteSurf->Format() != gfxImageFormat::ARGB32 &&
    1.26 +         whiteSurf->Format() != gfxImageFormat::RGB24))
    1.27 +        return false;
    1.28 +
    1.29 +#ifdef MOZILLA_MAY_SUPPORT_SSE2
    1.30 +    if (mozilla::supports_sse2() &&
    1.31 +        RecoverAlphaSSE2(blackSurf, whiteSurf)) {
    1.32 +        return true;
    1.33 +    }
    1.34 +#endif
    1.35 +
    1.36 +    blackSurf->Flush();
    1.37 +    whiteSurf->Flush();
    1.38 +
    1.39 +    unsigned char* blackData = blackSurf->Data();
    1.40 +    unsigned char* whiteData = whiteSurf->Data();
    1.41 +
    1.42 +    for (int32_t i = 0; i < size.height; ++i) {
    1.43 +        uint32_t* blackPixel = reinterpret_cast<uint32_t*>(blackData);
    1.44 +        const uint32_t* whitePixel = reinterpret_cast<uint32_t*>(whiteData);
    1.45 +        for (int32_t j = 0; j < size.width; ++j) {
    1.46 +            uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]);
    1.47 +            blackPixel[j] = recovered;
    1.48 +        }
    1.49 +        blackData += blackSurf->Stride();
    1.50 +        whiteData += whiteSurf->Stride();
    1.51 +    }
    1.52 +
    1.53 +    blackSurf->MarkDirty();
    1.54 +
    1.55 +    return true;
    1.56 +}

mercurial