mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 20:47:44 +00:00
e368dc9c85
This patch was generated by a script. Here's the source of the script for future reference: function convert() { echo "Converting $1 to $2..." find . ! -wholename "*nsprpub*" \ ! -wholename "*security/nss*" \ ! -wholename "*/.hg*" \ ! -wholename "obj-ff-dbg*" \ ! -name nsXPCOMCID.h \ ! -name prtypes.h \ -type f \ \( -iname "*.cpp" \ -o -iname "*.h" \ -o -iname "*.c" \ -o -iname "*.cc" \ -o -iname "*.idl" \ -o -iname "*.ipdl" \ -o -iname "*.ipdlh" \ -o -iname "*.mm" \) | \ xargs -n 1 sed -i -e "s/\b$1\b/$2/g" } convert PRInt8 int8_t convert PRUint8 uint8_t convert PRInt16 int16_t convert PRUint16 uint16_t convert PRInt32 int32_t convert PRUint32 uint32_t convert PRInt64 int64_t convert PRUint64 uint64_t convert PRIntn int convert PRUintn unsigned convert PRSize size_t convert PROffset32 int32_t convert PROffset64 int64_t convert PRPtrdiff ptrdiff_t convert PRFloat64 double
93 lines
3.2 KiB
C++
93 lines
3.2 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,
|
|
Analysis* analysis)
|
|
{
|
|
gfxIntSize size = blackSurf->GetSize();
|
|
|
|
if (size != whiteSurf->GetSize() ||
|
|
(blackSurf->Format() != gfxASurface::ImageFormatARGB32 &&
|
|
blackSurf->Format() != gfxASurface::ImageFormatRGB24) ||
|
|
(whiteSurf->Format() != gfxASurface::ImageFormatARGB32 &&
|
|
whiteSurf->Format() != gfxASurface::ImageFormatRGB24))
|
|
return false;
|
|
|
|
#ifdef MOZILLA_MAY_SUPPORT_SSE2
|
|
if (!analysis && mozilla::supports_sse2() &&
|
|
RecoverAlphaSSE2(blackSurf, whiteSurf)) {
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
blackSurf->Flush();
|
|
whiteSurf->Flush();
|
|
|
|
unsigned char* blackData = blackSurf->Data();
|
|
unsigned char* whiteData = whiteSurf->Data();
|
|
|
|
/* Get the alpha value of 'first' */
|
|
uint32_t first;
|
|
if (size.width == 0 || size.height == 0) {
|
|
first = 0;
|
|
} else {
|
|
if (!blackData || !whiteData)
|
|
return false;
|
|
|
|
first = RecoverPixel(*reinterpret_cast<uint32_t*>(blackData),
|
|
*reinterpret_cast<uint32_t*>(whiteData));
|
|
}
|
|
|
|
uint32_t deltas = 0;
|
|
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;
|
|
deltas |= (first ^ recovered);
|
|
}
|
|
blackData += blackSurf->Stride();
|
|
whiteData += whiteSurf->Stride();
|
|
}
|
|
|
|
blackSurf->MarkDirty();
|
|
|
|
if (analysis) {
|
|
analysis->uniformAlpha = (deltas >> 24) == 0;
|
|
analysis->uniformColor = false;
|
|
if (analysis->uniformAlpha) {
|
|
double d_first_alpha = first >> 24;
|
|
analysis->alpha = d_first_alpha/255.0;
|
|
/* we only set uniformColor when the alpha is already uniform.
|
|
it's only useful in that case ... and if the alpha was nonuniform
|
|
then computing whether the color is uniform would require unpremultiplying
|
|
every pixel */
|
|
analysis->uniformColor = deltas == 0;
|
|
if (analysis->uniformColor) {
|
|
if (d_first_alpha == 0.0) {
|
|
/* can't unpremultiply, this is OK */
|
|
analysis->r = analysis->g = analysis->b = 0.0;
|
|
} else {
|
|
analysis->r = (first & 0xFF)/d_first_alpha;
|
|
analysis->g = ((first >> 8) & 0xFF)/d_first_alpha;
|
|
analysis->b = ((first >> 16) & 0xFF)/d_first_alpha;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|