2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
2007-03-03 00:18:34 +00:00
|
|
|
|
|
|
|
#include "gfxAlphaRecovery.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
|
2010-08-18 03:43:49 +00:00
|
|
|
#define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2
|
|
|
|
#include "mozilla/SSE.h"
|
2007-03-03 00:18:34 +00:00
|
|
|
|
2019-02-25 22:07:19 +00:00
|
|
|
/* static */
|
|
|
|
bool gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
|
|
|
|
const gfxImageSurface* whiteSurf) {
|
2015-06-01 08:26:19 +00:00
|
|
|
mozilla::gfx::IntSize size = blackSurf->GetSize();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-09 02:19:17 +00:00
|
|
|
if (size != whiteSurf->GetSize() ||
|
2016-01-08 04:57:38 +00:00
|
|
|
(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))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-08-09 02:19:17 +00:00
|
|
|
|
2010-12-05 08:38:53 +00:00
|
|
|
#ifdef MOZILLA_MAY_SUPPORT_SSE2
|
|
|
|
if (mozilla::supports_sse2() && RecoverAlphaSSE2(blackSurf, whiteSurf)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-08-18 03:43:49 +00:00
|
|
|
}
|
2010-12-05 08:38:53 +00:00
|
|
|
#endif
|
2010-08-18 03:43:49 +00:00
|
|
|
|
2010-08-09 02:22:56 +00:00
|
|
|
blackSurf->Flush();
|
|
|
|
whiteSurf->Flush();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-09 02:19:17 +00:00
|
|
|
unsigned char* blackData = blackSurf->Data();
|
|
|
|
unsigned char* whiteData = whiteSurf->Data();
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
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]);
|
2010-08-09 02:22:56 +00:00
|
|
|
blackPixel[j] = recovered;
|
2007-03-03 00:18:34 +00:00
|
|
|
}
|
2010-08-09 02:19:17 +00:00
|
|
|
blackData += blackSurf->Stride();
|
|
|
|
whiteData += whiteSurf->Stride();
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2010-08-09 02:19:17 +00:00
|
|
|
|
|
|
|
blackSurf->MarkDirty();
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-03-03 00:18:34 +00:00
|
|
|
}
|