clamp to premul in dither

Dither can bump color values above alpha (duh), or below
zero (duh), so clamp back to premul after dithering.

BUG=skia:6644,skia:6643

Change-Id: Ida107e866380e06130af0d01467117bca929ba44
Reviewed-on: https://skia-review.googlesource.com/17070
Reviewed-by: Herb Derby <herb@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-05-16 12:03:15 -04:00 committed by Skia Commit-Bot
parent 0eb4ecb885
commit 7e68bc93ff
5 changed files with 3474 additions and 3351 deletions

29
gm/bug6643.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkGradientShader.h"
#include "SkPictureRecorder.h"
#include "gm.h"
DEF_SIMPLE_GM(bug6643, canvas, 200, 200) {
SkColor colors[] = { SK_ColorTRANSPARENT, SK_ColorGREEN, SK_ColorTRANSPARENT };
SkPaint p;
p.setAntiAlias(true);
p.setShader(SkGradientShader::MakeSweep(100, 100, colors, nullptr, SK_ARRAY_COUNT(colors),
SkGradientShader::kInterpolateColorsInPremul_Flag,
nullptr));
SkPictureRecorder recorder;
recorder.beginRecording(200, 200)->drawPaint(p);
p.setShader(SkShader::MakePictureShader(recorder.finishRecordingAsPicture(),
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
nullptr, nullptr));
canvas->drawColor(SK_ColorWHITE);
canvas->drawPaint(p);
}

View File

@ -49,6 +49,7 @@ gm_sources = [
"$_gm/blurs.cpp",
"$_gm/bmpfilterqualityrepeat.cpp",
"$_gm/bug5252.cpp",
"$_gm/bug6643.cpp",
"$_gm/bug530095.cpp",
"$_gm/bug615686.cpp",
"$_gm/cgm.c",

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -320,6 +320,10 @@ STAGE(dither) {
r += c->rate*dither;
g += c->rate*dither;
b += c->rate*dither;
r = max(0, min(r, a));
g = max(0, min(g, a));
b = max(0, min(b, a));
}
// load 4 floats from memory, and splat them into r,g,b,a