2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07: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-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "gfxAlphaRecovery.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
|
2010-08-17 20:43:49 -07:00
|
|
|
#define MOZILLA_SSE_INCLUDE_HEADER_FOR_SSE2
|
|
|
|
#include "mozilla/SSE.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* static */ bool
|
2010-08-08 19:19:17 -07:00
|
|
|
gfxAlphaRecovery::RecoverAlpha(gfxImageSurface* blackSurf,
|
2013-10-25 14:25:40 -07:00
|
|
|
const gfxImageSurface* whiteSurf)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-08 19:19:17 -07:00
|
|
|
gfxIntSize size = blackSurf->GetSize();
|
|
|
|
|
|
|
|
if (size != whiteSurf->GetSize() ||
|
2013-09-24 13:45:13 -07:00
|
|
|
(blackSurf->Format() != gfxImageFormatARGB32 &&
|
|
|
|
blackSurf->Format() != gfxImageFormatRGB24) ||
|
|
|
|
(whiteSurf->Format() != gfxImageFormatARGB32 &&
|
|
|
|
whiteSurf->Format() != gfxImageFormatRGB24))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-08-08 19:19:17 -07:00
|
|
|
|
2010-12-05 00:38:53 -08:00
|
|
|
#ifdef MOZILLA_MAY_SUPPORT_SSE2
|
2013-10-25 14:25:40 -07:00
|
|
|
if (mozilla::supports_sse2() &&
|
2010-12-05 00:38:53 -08:00
|
|
|
RecoverAlphaSSE2(blackSurf, whiteSurf)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-08-17 20:43:49 -07:00
|
|
|
}
|
2010-12-05 00:38:53 -08:00
|
|
|
#endif
|
2010-08-17 20:43:49 -07:00
|
|
|
|
2010-08-08 19:22:56 -07:00
|
|
|
blackSurf->Flush();
|
|
|
|
whiteSurf->Flush();
|
|
|
|
|
2010-08-08 19:19:17 -07:00
|
|
|
unsigned char* blackData = blackSurf->Data();
|
|
|
|
unsigned char* whiteData = whiteSurf->Data();
|
|
|
|
|
2012-08-22 08:56:38 -07: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-08 19:22:56 -07:00
|
|
|
blackPixel[j] = recovered;
|
2010-08-08 19:19:17 -07:00
|
|
|
}
|
|
|
|
blackData += blackSurf->Stride();
|
|
|
|
whiteData += whiteSurf->Stride();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-08 19:19:17 -07:00
|
|
|
|
|
|
|
blackSurf->MarkDirty();
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|