make append_gamut_tranform() never fail

The only way it could ostensibly fail is if we get non-XYZ color
spaces, which should just not happen.  Assert that doesn't happen
and safely do nothing instead of failing.

This is one of the leaf nodes to getting SkCreateRasterPipelineBlitter
to never fail.  Next come SkColorFilter:: and SkShader::appendStages().

Change-Id: I5c7a8c63d0a9837e2e55208e1674796d86f45307
Reviewed-on: https://skia-review.googlesource.com/16002
Commit-Queue: Mike Klein <mtklein@chromium.org>
Reviewed-by: Matt Sarett <msarett@google.com>
This commit is contained in:
Mike Klein 2017-05-08 21:56:55 -04:00 committed by Skia Commit-Bot
parent 31ec144227
commit ee2d9df087
4 changed files with 19 additions and 14 deletions

View File

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

View File

@ -100,17 +100,23 @@ 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 bool append_gamut_transform(SkRasterPipeline* p, float scratch_matrix_3x4[12],
static inline void append_gamut_transform(SkRasterPipeline* p, float scratch_matrix_3x4[12],
SkColorSpace* src, SkColorSpace* dst) {
if (src == dst) { return true; }
if (!dst) { return true; } // Legacy modes intentionally ignore color gamut.
if (!src) { return true; } // A null src color space means linear gamma, dst gamut.
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.
auto toXYZ = as_CSB(src)-> toXYZD50(),
fromXYZ = as_CSB(dst)->fromXYZD50();
if (!toXYZ || !fromXYZ) { return false; } // Unsupported color space type.
if (!toXYZ || !fromXYZ) {
SkASSERT(false); // We really don't want to get here with a weird colorspace.
return;
}
if (as_CSB(src)->toXYZD50Hash() == as_CSB(dst)->toXYZD50Hash()) { return true; }
// Slightly more sophisticated version of if (src == dst)
if (as_CSB(src)->toXYZD50Hash() == as_CSB(dst)->toXYZD50Hash()) {
return;
}
SkMatrix44 m44(*fromXYZ, *toXYZ);
@ -127,12 +133,11 @@ static inline bool append_gamut_transform(SkRasterPipeline* p, float scratch_mat
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); }
return true;
}
static inline bool append_gamut_transform(SkRasterPipeline* p, SkArenaAlloc* scratch,
static inline void append_gamut_transform(SkRasterPipeline* p, SkArenaAlloc* scratch,
SkColorSpace* src, SkColorSpace* dst) {
return append_gamut_transform(p, scratch->makeArrayDefault<float>(12), src, dst);
append_gamut_transform(p, scratch->makeArrayDefault<float>(12), src, dst);
}
static inline SkColor4f to_colorspace(const SkColor4f& c, SkColorSpace* src, SkColorSpace* dst) {

View File

@ -294,8 +294,8 @@ bool SkShader::onAppendStages(SkRasterPipeline* p,
// Legacy shaders aren't aware of color spaces. We can pretty
// safely assume they're in sRGB gamut.
return append_gamut_transform(p, alloc,
SkColorSpace::MakeSRGB().get(), cs);
append_gamut_transform(p, alloc, SkColorSpace::MakeSRGB().get(), cs);
return true;
}
return false;
}

View File

@ -377,5 +377,6 @@ bool SkImageShader::onAppendStages(SkRasterPipeline* p, SkColorSpace* dst, SkAre
p->append(SkRasterPipeline::clamp_0);
p->append(SkRasterPipeline::clamp_a);
}
return append_gamut_transform(p, scratch, info.colorSpace(), dst);
append_gamut_transform(p, scratch, info.colorSpace(), dst);
return true;
}