static SkColor4f xferColor(const SkColor4f& src, const SkColor4f& dst, SkBlendMode mode) { switch (mode) { case SkBlendMode::kSrc: return src; case SkBlendMode::kDst: return dst; default: { SkPMColor4f pmS = src.premul(); SkPMColor4f pmD = dst.premul(); return SkBlendMode_Apply(mode, pmS, pmD).unpremul(); } } }
bool SkPixmap::erase(const SkColor4f& origColor, const SkIRect* subset) const { SkPixmap pm; if (subset) { if (!this->extractSubset(&pm, *subset)) { return false; } } else { pm = *this; } const SkColor4f color = origColor.pin(); if (kRGBA_F16_SkColorType != pm.colorType()) { Sk4f c4 = Sk4f::Load(color.vec()); SkColor c; (c4 * Sk4f(255) + Sk4f(0.5f)).store(&c); return pm.erase(c); } const uint64_t half4 = color.premul().toF16(); for (int y = 0; y < pm.height(); ++y) { sk_memset64(pm.writable_addr64(0, y), half4, pm.width()); } return true; }
SkColor4f SkColorFilter::filterColor4f(const SkColor4f& c, SkColorSpace* colorSpace) const { SkPMColor4f dst, src = c.premul(); // determined experimentally, seems to cover compose+colormatrix constexpr size_t kEnoughForCommonFilters = 512; SkSTArenaAlloc<kEnoughForCommonFilters> alloc; SkRasterPipeline pipeline(&alloc); pipeline.append_constant_color(&alloc, src.vec()); SkPaint dummyPaint; SkStageRec rec = { &pipeline, &alloc, kRGBA_F32_SkColorType, colorSpace, dummyPaint, nullptr, SkMatrix::I() }; this->onAppendStages(rec, c.fA == 1); SkRasterPipeline_MemoryCtx dstPtr = { &dst, 0 }; pipeline.append(SkRasterPipeline::store_f32, &dstPtr); pipeline.run(0,0, 1,1); return dst.unpremul(); }
SkColor4f SkColorFilter::filterColor4f(const SkColor4f& c) const { SkPM4f dst, src = c.premul(); this->filterSpan4f(&src, 1, &dst); return dst.unpremul(); }