void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const { for (int i = 0; i < count; ++i) { SkPMColor c = src[i]; /* * While LuminanceToAlpha is defined to operate on un-premultiplied * inputs, due to the final alpha scaling it can be computed based on * premultipled components: * * LumA = (k1 * r / a + k2 * g / a + k3 * b / a) * a * LumA = (k1 * r + k2 * g + k3 * b) */ unsigned luma = SkComputeLuminance(SkGetPackedR32(c), SkGetPackedG32(c), SkGetPackedB32(c)); dst[i] = SkPackARGB32(luma, 0, 0, 0); } }
SkColor GrTextContext::ComputeCanonicalColor(const SkPaint& paint, bool lcd) { SkColor canonicalColor = SkPaintPriv::ComputeLuminanceColor(paint); if (lcd) { // This is the correct computation, but there are tons of cases where LCD can be overridden. // For now we just regenerate if any run in a textblob has LCD. // TODO figure out where all of these overrides are and see if we can incorporate that logic // at a higher level *OR* use sRGB SkASSERT(false); //canonicalColor = SkMaskGamma::CanonicalColor(canonicalColor); } else { // A8, though can have mixed BMP text but it shouldn't matter because BMP text won't have // gamma corrected masks anyways, nor color U8CPU lum = SkComputeLuminance(SkColorGetR(canonicalColor), SkColorGetG(canonicalColor), SkColorGetB(canonicalColor)); // reduce to our finite number of bits canonicalColor = SkMaskGamma::CanonicalColor(SkColorSetRGB(lum, lum, lum)); } return canonicalColor; }
bool SkPixmap::erase(SkColor color, const SkIRect& inArea) const { if (nullptr == fPixels) { return false; } SkIRect area; if (!area.intersect(this->bounds(), inArea)) { return false; } U8CPU a = SkColorGetA(color); U8CPU r = SkColorGetR(color); U8CPU g = SkColorGetG(color); U8CPU b = SkColorGetB(color); int height = area.height(); const int width = area.width(); const int rowBytes = this->rowBytes(); switch (this->colorType()) { case kGray_8_SkColorType: { if (255 != a) { r = SkMulDiv255Round(r, a); g = SkMulDiv255Round(g, a); b = SkMulDiv255Round(b, a); } int gray = SkComputeLuminance(r, g, b); uint8_t* p = this->writable_addr8(area.fLeft, area.fTop); while (--height >= 0) { memset(p, gray, width); p += rowBytes; } break; } case kAlpha_8_SkColorType: { uint8_t* p = this->writable_addr8(area.fLeft, area.fTop); while (--height >= 0) { memset(p, a, width); p += rowBytes; } break; } case kARGB_4444_SkColorType: case kRGB_565_SkColorType: { uint16_t* p = this->writable_addr16(area.fLeft, area.fTop); uint16_t v; // make rgb premultiplied if (255 != a) { r = SkMulDiv255Round(r, a); g = SkMulDiv255Round(g, a); b = SkMulDiv255Round(b, a); } if (kARGB_4444_SkColorType == this->colorType()) { v = pack_8888_to_4444(a, r, g, b); } else { v = SkPackRGB16(r >> (8 - SK_R16_BITS), g >> (8 - SK_G16_BITS), b >> (8 - SK_B16_BITS)); } while (--height >= 0) { sk_memset16(p, v, width); p = (uint16_t*)((char*)p + rowBytes); } break; } case kBGRA_8888_SkColorType: case kRGBA_8888_SkColorType: { uint32_t* p = this->writable_addr32(area.fLeft, area.fTop); if (255 != a && kPremul_SkAlphaType == this->alphaType()) { r = SkMulDiv255Round(r, a); g = SkMulDiv255Round(g, a); b = SkMulDiv255Round(b, a); } uint32_t v = kRGBA_8888_SkColorType == this->colorType() ? SkPackARGB_as_RGBA(a, r, g, b) : SkPackARGB_as_BGRA(a, r, g, b); while (--height >= 0) { sk_memset32(p, v, width); p = (uint32_t*)((char*)p + rowBytes); } break; } default: return false; // no change, so don't call notifyPixelsChanged() } return true; }
static inline SkPMColor luma_proc(const SkPMColor a, const SkPMColor b) { unsigned luma = SkComputeLuminance(SkGetPackedR32(b), SkGetPackedG32(b), SkGetPackedB32(b)); return SkAlphaMulQ(a, SkAlpha255To256(luma)); }