SkLumaColorFilter: Keep alpha in [0,1]

Bug: skia:
Change-Id: I2287ae75745509269e3dee2b1d31ab513580e6c3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/201221
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2019-03-14 10:11:24 -04:00 committed by Skia Commit-Bot
parent 4bf964602a
commit 8a63a4d024
4 changed files with 7 additions and 5 deletions

View File

@ -20,6 +20,8 @@
void SkLumaColorFilter::onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const {
rec.fPipeline->append(SkRasterPipeline::luminance_to_alpha);
rec.fPipeline->append(SkRasterPipeline::clamp_0);
rec.fPipeline->append(SkRasterPipeline::clamp_1);
}
sk_sp<SkColorFilter> SkLumaColorFilter::Make() {

View File

@ -23,8 +23,8 @@ public:
const GrLumaColorFilterEffect& _outer = args.fFp.cast<GrLumaColorFilterEffect>();
(void)_outer;
fragBuilder->codeAppendf(
"\nhalf luma = dot(half3(0.21260000000000001, 0.71519999999999995, 0.0722), "
"%s.xyz);\n%s = half4(0.0, 0.0, 0.0, luma);\n",
"\nhalf luma = clamp(dot(half3(0.21260000000000001, 0.71519999999999995, 0.0722), "
"%s.xyz), 0.0, 1.0);\n%s = half4(0.0, 0.0, 0.0, luma);\n",
args.fInputColor, args.fOutputColor);
}

View File

@ -12,12 +12,12 @@
float luma = SK_ITU_BT709_LUM_COEFF_R * input.fR +
SK_ITU_BT709_LUM_COEFF_G * input.fG +
SK_ITU_BT709_LUM_COEFF_B * input.fB;
return { 0, 0, 0, luma };
return { 0, 0, 0, SkTPin(luma, 0.0f, 1.0f) };
}
}
void main() {
const half3 SK_ITU_BT709_LUM_COEFF = half3(0.2126, 0.7152, 0.0722);
half luma = dot(SK_ITU_BT709_LUM_COEFF, sk_InColor.rgb);
half luma = saturate(dot(SK_ITU_BT709_LUM_COEFF, sk_InColor.rgb));
sk_OutColor = half4(0, 0, 0, luma);
}

View File

@ -20,7 +20,7 @@ public:
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
float luma = SK_ITU_BT709_LUM_COEFF_R * input.fR + SK_ITU_BT709_LUM_COEFF_G * input.fG +
SK_ITU_BT709_LUM_COEFF_B * input.fB;
return {0, 0, 0, luma};
return {0, 0, 0, SkTPin(luma, 0.0f, 1.0f)};
}
static std::unique_ptr<GrFragmentProcessor> Make() {
return std::unique_ptr<GrFragmentProcessor>(new GrLumaColorFilterEffect());