Pass alphaType to append_gamut_transform() to inform the clamp

BUG=skia:

Change-Id: I1a8aef36043d4091bffae95b0275fa7fa8a35c97
Reviewed-on: https://skia-review.googlesource.com/9441
Commit-Queue: Matt Sarett <msarett@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Matt Sarett 2017-05-12 08:38:02 -04:00 committed by Skia Commit-Bot
parent 6cdc22cde8
commit f391f4e07d
3 changed files with 15 additions and 9 deletions

View File

@ -320,7 +320,8 @@ static void convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, size
float matrix[12];
if (isColorAware) {
append_gamut_transform(&pipeline, matrix, srcInfo.colorSpace(), dstInfo.colorSpace());
append_gamut_transform(&pipeline, matrix, srcInfo.colorSpace(), dstInfo.colorSpace(),
premulState);
}
SkAlphaType dat = dstInfo.alphaType();

View File

@ -101,7 +101,8 @@ static inline void analyze_3x4_matrix(const float matrix[12],
// N.B. scratch_matrix_3x4 must live at least as long as p.
static inline void append_gamut_transform(SkRasterPipeline* p, float scratch_matrix_3x4[12],
SkColorSpace* src, SkColorSpace* dst) {
SkColorSpace* src, SkColorSpace* dst,
SkAlphaType alphaType) {
if (src == dst) { return; } // That was easy.
if (!dst) { return; } // Legacy modes intentionally ignore color gamut.
if (!src) { return; } // A null src color space means linear gamma, dst gamut.
@ -127,17 +128,21 @@ static inline void append_gamut_transform(SkRasterPipeline* p, float scratch_mat
*ptr++ = m44.get(0,2); *ptr++ = m44.get(1,2); *ptr++ = m44.get(2,2);
*ptr++ = m44.get(0,3); *ptr++ = m44.get(1,3); *ptr++ = m44.get(2,3);
bool needs_clamp_0, needs_clamp_a;
analyze_3x4_matrix(scratch_matrix_3x4, &needs_clamp_0, &needs_clamp_a);
bool needs_clamp_0, needs_clamp_1;
analyze_3x4_matrix(scratch_matrix_3x4, &needs_clamp_0, &needs_clamp_1);
p->append(SkRasterPipeline::matrix_3x4, scratch_matrix_3x4);
if (needs_clamp_0) { p->append(SkRasterPipeline::clamp_0); }
if (needs_clamp_a) { p->append(SkRasterPipeline::clamp_a); }
if (needs_clamp_1) {
(kPremul_SkAlphaType == alphaType) ? p->append(SkRasterPipeline::clamp_a)
: p->append(SkRasterPipeline::clamp_1);
}
}
static inline void append_gamut_transform(SkRasterPipeline* p, SkArenaAlloc* scratch,
SkColorSpace* src, SkColorSpace* dst) {
append_gamut_transform(p, scratch->makeArrayDefault<float>(12), src, dst);
SkColorSpace* src, SkColorSpace* dst,
SkAlphaType alphaType) {
append_gamut_transform(p, scratch->makeArrayDefault<float>(12), src, dst, alphaType);
}
static inline SkColor4f to_colorspace(const SkColor4f& c, SkColorSpace* src, SkColorSpace* dst) {
@ -149,7 +154,7 @@ static inline SkColor4f to_colorspace(const SkColor4f& c, SkColorSpace* src, SkC
SkRasterPipeline p;
p.append(SkRasterPipeline::constant_color, color4f_ptr);
append_gamut_transform(&p, scratch_matrix_3x4, src, dst);
append_gamut_transform(&p, scratch_matrix_3x4, src, dst, kUnpremul_SkAlphaType);
p.append(SkRasterPipeline::store_f32, &color4f_ptr);
p.run(0,1);

View File

@ -385,6 +385,6 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dstCS, SkA
p->append(SkRasterPipeline::clamp_0);
p->append(SkRasterPipeline::clamp_a);
}
append_gamut_transform(p, alloc, info.colorSpace(), dstCS);
append_gamut_transform(p, alloc, info.colorSpace(), dstCS, kPremul_SkAlphaType);
return true;
}