gfx/thebes/gfxAlphaRecovery.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     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 /* static */ bool
    14 gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
    15                                const gfxImageSurface* whiteSurf)
    16 {
    17     gfxIntSize size = blackSurf->GetSize();
    19     if (size != whiteSurf->GetSize() ||
    20         (blackSurf->Format() != gfxImageFormat::ARGB32 &&
    21          blackSurf->Format() != gfxImageFormat::RGB24) ||
    22         (whiteSurf->Format() != gfxImageFormat::ARGB32 &&
    23          whiteSurf->Format() != gfxImageFormat::RGB24))
    24         return false;
    26 #ifdef MOZILLA_MAY_SUPPORT_SSE2
    27     if (mozilla::supports_sse2() &&
    28         RecoverAlphaSSE2(blackSurf, whiteSurf)) {
    29         return true;
    30     }
    31 #endif
    33     blackSurf->Flush();
    34     whiteSurf->Flush();
    36     unsigned char* blackData = blackSurf->Data();
    37     unsigned char* whiteData = whiteSurf->Data();
    39     for (int32_t i = 0; i < size.height; ++i) {
    40         uint32_t* blackPixel = reinterpret_cast<uint32_t*>(blackData);
    41         const uint32_t* whitePixel = reinterpret_cast<uint32_t*>(whiteData);
    42         for (int32_t j = 0; j < size.width; ++j) {
    43             uint32_t recovered = RecoverPixel(blackPixel[j], whitePixel[j]);
    44             blackPixel[j] = recovered;
    45         }
    46         blackData += blackSurf->Stride();
    47         whiteData += whiteSurf->Stride();
    48     }
    50     blackSurf->MarkDirty();
    52     return true;
    53 }

mercurial