Make SkPixmap::getColor support kUnpremul pixels
Bug: skia:6319 Change-Id: Id5ad27b4e85516dfdad0c127655e6272bc0a39ac Reviewed-on: https://skia-review.googlesource.com/19089 Commit-Queue: Matt Sarett <msarett@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
39afa1226f
commit
9466bf5694
@ -257,6 +257,13 @@ SkColor SkPixmap::getColor(int x, int y) const {
|
|||||||
SkASSERT(this->addr());
|
SkASSERT(this->addr());
|
||||||
SkASSERT((unsigned)x < (unsigned)this->width());
|
SkASSERT((unsigned)x < (unsigned)this->width());
|
||||||
SkASSERT((unsigned)y < (unsigned)this->height());
|
SkASSERT((unsigned)y < (unsigned)this->height());
|
||||||
|
|
||||||
|
const bool needsUnpremul = (kPremul_SkAlphaType == fInfo.alphaType());
|
||||||
|
auto toColor = [needsUnpremul](uint32_t maybePremulColor) {
|
||||||
|
return needsUnpremul ? SkUnPreMultiply::PMColorToColor(maybePremulColor)
|
||||||
|
: SkSwizzle_BGRA_to_PMColor(maybePremulColor);
|
||||||
|
};
|
||||||
|
|
||||||
switch (this->colorType()) {
|
switch (this->colorType()) {
|
||||||
case kGray_8_SkColorType: {
|
case kGray_8_SkColorType: {
|
||||||
uint8_t value = *this->addr8(x, y);
|
uint8_t value = *this->addr8(x, y);
|
||||||
@ -267,8 +274,8 @@ SkColor SkPixmap::getColor(int x, int y) const {
|
|||||||
}
|
}
|
||||||
case kIndex_8_SkColorType: {
|
case kIndex_8_SkColorType: {
|
||||||
SkASSERT(this->ctable());
|
SkASSERT(this->ctable());
|
||||||
SkPMColor pmColor = (*this->ctable())[*this->addr8(x, y)];
|
SkPMColor c = (*this->ctable())[*this->addr8(x, y)];
|
||||||
return SkUnPreMultiply::PMColorToColor(pmColor);
|
return toColor(c);
|
||||||
}
|
}
|
||||||
case kRGB_565_SkColorType: {
|
case kRGB_565_SkColorType: {
|
||||||
return SkPixel16ToColor(*this->addr16(x, y));
|
return SkPixel16ToColor(*this->addr16(x, y));
|
||||||
@ -276,23 +283,23 @@ SkColor SkPixmap::getColor(int x, int y) const {
|
|||||||
case kARGB_4444_SkColorType: {
|
case kARGB_4444_SkColorType: {
|
||||||
uint16_t value = *this->addr16(x, y);
|
uint16_t value = *this->addr16(x, y);
|
||||||
SkPMColor c = SkPixel4444ToPixel32(value);
|
SkPMColor c = SkPixel4444ToPixel32(value);
|
||||||
return SkUnPreMultiply::PMColorToColor(c);
|
return toColor(c);
|
||||||
}
|
}
|
||||||
case kBGRA_8888_SkColorType: {
|
case kBGRA_8888_SkColorType: {
|
||||||
uint32_t value = *this->addr32(x, y);
|
uint32_t value = *this->addr32(x, y);
|
||||||
SkPMColor c = SkSwizzle_BGRA_to_PMColor(value);
|
SkPMColor c = SkSwizzle_BGRA_to_PMColor(value);
|
||||||
return SkUnPreMultiply::PMColorToColor(c);
|
return toColor(c);
|
||||||
}
|
}
|
||||||
case kRGBA_8888_SkColorType: {
|
case kRGBA_8888_SkColorType: {
|
||||||
uint32_t value = *this->addr32(x, y);
|
uint32_t value = *this->addr32(x, y);
|
||||||
SkPMColor c = SkSwizzle_RGBA_to_PMColor(value);
|
SkPMColor c = SkSwizzle_RGBA_to_PMColor(value);
|
||||||
return SkUnPreMultiply::PMColorToColor(c);
|
return toColor(c);
|
||||||
}
|
}
|
||||||
case kRGBA_F16_SkColorType: {
|
case kRGBA_F16_SkColorType: {
|
||||||
const uint64_t* addr =
|
const uint64_t* addr =
|
||||||
(const uint64_t*)fPixels + y * (fRowBytes >> 3) + x;
|
(const uint64_t*)fPixels + y * (fRowBytes >> 3) + x;
|
||||||
Sk4f p4 = SkHalfToFloat_finite_ftz(*addr);
|
Sk4f p4 = SkHalfToFloat_finite_ftz(*addr);
|
||||||
if (p4[3]) {
|
if (p4[3] && needsUnpremul) {
|
||||||
float inva = 1 / p4[3];
|
float inva = 1 / p4[3];
|
||||||
p4 = p4 * Sk4f(inva, inva, inva, 1);
|
p4 = p4 * Sk4f(inva, inva, inva, 1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user