gecko-dev/gfx/thebes/gfxAlphaRecovery.cpp
Nicholas Nethercote 88696a303a Bug 1209812 (part 6) - Convert all gfxImageFormat values to SurfaceFormat equivalents. r=jrmuizel.
This patch:

- Makes the following substitutions (plus necessary namespace qualifiers:

    gfxImageFormat::ARGB32      --> SurfaceFormat::A8R8G8B8_UINT32
    gfxImageFormat::RGB24       --> SurfaceFormat::X8R8G8B8_UINT32
    gfxImageFormat::A8          --> SurfaceFormat::A8
    gfxImageFormat::RGB16_565   --> SurfaceFormat::R5G6B5_UINT16
    gfxImageFormat::Unknown     --> SurfaceFormat::UNKNOWN

- Changes gfxImageFormat to be a typedef to gfx::SurfaceFormat. This will be
  removed soon.

- Removes gfxCairoFormatToImageFormat() and gfxImageFormatToCairoFormat() and
  replace calls to them with CairoFormatToGfxFormat() and
  GfxFormatToCairoFormat().

- Removes ParamTraits<gfxImageFormat>.

- Add namespace qualifiers to SurfaceFormat instances where necessary.

--HG--
extra : rebase_source : f56e92b1593957a9e4e00171100bc7605816e696
2016-01-07 20:57:38 -08:00

54 lines
1.8 KiB
C++

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