diff options
author | Brian Osman <brianosman@google.com> | 2018-07-12 14:44:27 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-12 20:54:14 +0000 |
commit | b62f50cf763279fa0d0aa2f80624de02c7a1c2fb (patch) | |
tree | a4aba5466ff7e3136bd97c35718a678354b430ea /src/core | |
parent | 5bc4fc8f3f26e9e14cccee4d200309e4b500b8d3 (diff) |
Replace nearly all kRespect with kIgnore
- Encoders and decoders always assume kIgnore.
- They are less opinionated about F16 and color space,
we just trust the color space that's passed in, and
put that directly in the image (no sRGB encoding).
- SkBitmap and SkPixmap read/write pixels functions were
defaulting to kResepct, those are now always kIgnore.
- Many other bits of plumbing are simplified, and I
added a default of kIgnore to SkImage::makeColorSpace,
so we can phase out that argument entirely.
- Still need to add defaults to other public APIs that
take SkTransferFunctionBehavior.
- This makes gold think that we've dramatically changed
the contents of all F16 images, but that's because
it doesn't understand the (now linear) color space
that's embedded. Once we triage them all once, they
will work fine (and they'll look perfect in the browser).
Bug: skia:
Change-Id: I62fa090f96cae1b67d181ce14bd91f34ff2ed747
Reviewed-on: https://skia-review.googlesource.com/140570
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkBitmap.cpp | 9 | ||||
-rw-r--r-- | src/core/SkColorSpaceXform.cpp | 23 | ||||
-rw-r--r-- | src/core/SkColorSpaceXformPriv.h | 8 | ||||
-rw-r--r-- | src/core/SkColorSpaceXformer.cpp | 6 | ||||
-rw-r--r-- | src/core/SkConvertPixels.cpp | 42 | ||||
-rw-r--r-- | src/core/SkConvertPixels.h | 3 | ||||
-rw-r--r-- | src/core/SkPixmap.cpp | 5 |
7 files changed, 31 insertions, 65 deletions
diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 4ef7abf95c..6d936f9436 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -494,8 +494,7 @@ bool SkBitmap::readPixels(const SkPixmap& dst, int srcX, int srcY) const { return this->readPixels(dst.info(), dst.writable_addr(), dst.rowBytes(), srcX, srcY); } -bool SkBitmap::writePixels(const SkPixmap& src, int dstX, int dstY, - SkTransferFunctionBehavior behavior) { +bool SkBitmap::writePixels(const SkPixmap& src, int dstX, int dstY, SkTransferFunctionBehavior) { if (!SkImageInfoValidConversion(this->info(), src.info())) { return false; } @@ -507,8 +506,7 @@ bool SkBitmap::writePixels(const SkPixmap& src, int dstX, int dstY, void* dstPixels = this->getAddr(rec.fX, rec.fY); const SkImageInfo dstInfo = this->info().makeWH(rec.fInfo.width(), rec.fInfo.height()); - SkConvertPixels(dstInfo, dstPixels, this->rowBytes(), rec.fInfo, rec.fPixels, rec.fRowBytes, - behavior); + SkConvertPixels(dstInfo, dstPixels, this->rowBytes(), rec.fInfo, rec.fPixels, rec.fRowBytes); this->notifyPixelsChanged(); return true; } @@ -528,8 +526,7 @@ static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int return false; } SkConvertPixels(SkImageInfo::MakeA8(pmap.width(), pmap.height()), alpha, alphaRowBytes, - pmap.info(), pmap.addr(), pmap.rowBytes(), - SkTransferFunctionBehavior::kRespect); + pmap.info(), pmap.addr(), pmap.rowBytes()); return true; } diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp index 213e5b501e..5418c588fd 100644 --- a/src/core/SkColorSpaceXform.cpp +++ b/src/core/SkColorSpaceXform.cpp @@ -12,7 +12,7 @@ #include "../../third_party/skcms/skcms.h" std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* src, SkColorSpace* dst) { - return SkMakeColorSpaceXform(src, dst, SkTransferFunctionBehavior::kRespect); + return SkMakeColorSpaceXform(src, dst); } bool SkColorSpaceXform::Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* dst, @@ -30,11 +30,9 @@ bool SkColorSpaceXform::Apply(SkColorSpace* dstCS, ColorFormat dstFormat, void* class SkColorSpaceXform_skcms : public SkColorSpaceXform { public: SkColorSpaceXform_skcms(const skcms_ICCProfile& srcProfile, - const skcms_ICCProfile& dstProfile, - skcms_AlphaFormat premulFormat) + const skcms_ICCProfile& dstProfile) : fSrcProfile(srcProfile) - , fDstProfile(dstProfile) - , fPremulFormat(premulFormat) { + , fDstProfile(dstProfile) { } bool apply(ColorFormat, void*, ColorFormat, const void*, int, SkAlphaType) const override; @@ -42,7 +40,6 @@ public: private: skcms_ICCProfile fSrcProfile; skcms_ICCProfile fDstProfile; - skcms_AlphaFormat fPremulFormat; }; static skcms_PixelFormat get_skcms_format(SkColorSpaceXform::ColorFormat fmt) { @@ -71,7 +68,8 @@ bool SkColorSpaceXform_skcms::apply(ColorFormat dstFormat, void* dst, ColorFormat srcFormat, const void* src, int count, SkAlphaType alphaType) const { skcms_AlphaFormat srcAlpha = skcms_AlphaFormat_Unpremul; - skcms_AlphaFormat dstAlpha = kPremul_SkAlphaType == alphaType ? fPremulFormat + skcms_AlphaFormat dstAlpha = kPremul_SkAlphaType == alphaType + ? skcms_AlphaFormat_PremulAsEncoded : skcms_AlphaFormat_Unpremul; return skcms_Transform(src, get_skcms_format(srcFormat), srcAlpha, &fSrcProfile, @@ -98,12 +96,10 @@ void SkColorSpace::toProfile(skcms_ICCProfile* profile) const { } } -std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, SkColorSpace* dst, - SkTransferFunctionBehavior premul) { +std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, SkColorSpace* dst) { if (src && dst && dst->toXYZD50()) { // Construct skcms_ICCProfiles from each color space. For now, support A2B and XYZ. - // Eventually, only need to support XYZ. Map premul to one of the two premul formats - // in skcms. + // Eventually, only need to support XYZ. skcms_ICCProfile srcProfile, dstProfile; src->toProfile(&srcProfile); @@ -113,10 +109,7 @@ std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, SkCo return nullptr; } - skcms_AlphaFormat premulFormat = SkTransferFunctionBehavior::kRespect == premul - ? skcms_AlphaFormat_PremulLinear - : skcms_AlphaFormat_PremulAsEncoded; - return skstd::make_unique<SkColorSpaceXform_skcms>(srcProfile, dstProfile, premulFormat); + return skstd::make_unique<SkColorSpaceXform_skcms>(srcProfile, dstProfile); } return nullptr; } diff --git a/src/core/SkColorSpaceXformPriv.h b/src/core/SkColorSpaceXformPriv.h index 301e741380..f75ebf438c 100644 --- a/src/core/SkColorSpaceXformPriv.h +++ b/src/core/SkColorSpaceXformPriv.h @@ -10,13 +10,7 @@ #include "SkColorSpaceXform.h" -std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, - SkColorSpace* dst, - SkTransferFunctionBehavior); - -std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform_skcms(SkColorSpace* src, - SkColorSpace* dst, - SkTransferFunctionBehavior); +std::unique_ptr<SkColorSpaceXform> SkMakeColorSpaceXform(SkColorSpace* src, SkColorSpace* dst); static inline SkColorSpaceXform::ColorFormat select_xform_format(SkColorType colorType) { switch (colorType) { diff --git a/src/core/SkColorSpaceXformer.cpp b/src/core/SkColorSpaceXformer.cpp index 0b536ff8f4..5329294982 100644 --- a/src/core/SkColorSpaceXformer.cpp +++ b/src/core/SkColorSpaceXformer.cpp @@ -26,7 +26,7 @@ SkColorSpaceXformer::~SkColorSpaceXformer() {} std::unique_ptr<SkColorSpaceXformer> SkColorSpaceXformer::Make(sk_sp<SkColorSpace> dst) { std::unique_ptr<SkColorSpaceXform> fromSRGB = SkMakeColorSpaceXform( - SkColorSpace::MakeSRGB().get(), dst.get(), SkTransferFunctionBehavior::kIgnore); + SkColorSpace::MakeSRGB().get(), dst.get()); return fromSRGB ? std::unique_ptr<SkColorSpaceXformer>(new SkColorSpaceXformer(std::move(dst), @@ -98,7 +98,7 @@ sk_sp<SkImage> SkColorSpaceXformer::apply(const SkImage* src) { const AutoCachePurge autoPurge(this); return this->cachedApply<SkImage>(src, &fImageCache, [](const SkImage* img, SkColorSpaceXformer* xformer) { - return img->makeColorSpace(xformer->fDst, SkTransferFunctionBehavior::kIgnore); + return img->makeColorSpace(xformer->fDst); }); } @@ -109,7 +109,7 @@ sk_sp<SkImage> SkColorSpaceXformer::apply(const SkBitmap& src) { return nullptr; } - sk_sp<SkImage> xformed = image->makeColorSpace(fDst, SkTransferFunctionBehavior::kIgnore); + sk_sp<SkImage> xformed = image->makeColorSpace(fDst); // We want to be sure we don't let the kNever_SkCopyPixelsMode image escape this stack frame. SkASSERT(xformed != image); return xformed; diff --git a/src/core/SkConvertPixels.cpp b/src/core/SkConvertPixels.cpp index 0434b92c2e..ac96f20c86 100644 --- a/src/core/SkConvertPixels.cpp +++ b/src/core/SkConvertPixels.cpp @@ -87,13 +87,10 @@ void swizzle_and_multiply(const SkImageInfo& dstInfo, void* dstPixels, size_t ds } // Fast Path 3: Color space xform. -static inline bool optimized_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo, - SkTransferFunctionBehavior behavior) { +static inline bool optimized_color_xform(const SkImageInfo& dstInfo, const SkImageInfo& srcInfo) { // Unpremultiplication is unsupported by SkColorSpaceXform. Note that if |src| is non-linearly // premultiplied, we're always going to have to unpremultiply before doing anything. - if (kPremul_SkAlphaType == srcInfo.alphaType() && - (kUnpremul_SkAlphaType == dstInfo.alphaType() || - SkTransferFunctionBehavior::kIgnore == behavior)) { + if (kPremul_SkAlphaType == srcInfo.alphaType()) { return false; } @@ -119,7 +116,7 @@ static inline bool optimized_color_xform(const SkImageInfo& dstInfo, const SkIma static inline bool apply_color_xform(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, const SkImageInfo& srcInfo, const void* srcPixels, - size_t srcRB, SkTransferFunctionBehavior behavior) { + size_t srcRB) { SkColorSpaceXform::ColorFormat dstFormat = select_xform_format(dstInfo.colorType()); SkColorSpaceXform::ColorFormat srcFormat = select_xform_format(srcInfo.colorType()); SkAlphaType xformAlpha; @@ -146,8 +143,8 @@ static inline bool apply_color_xform(const SkImageInfo& dstInfo, void* dstPixels break; } - std::unique_ptr<SkColorSpaceXform> xform = - SkMakeColorSpaceXform(srcInfo.colorSpace(), dstInfo.colorSpace(), behavior); + std::unique_ptr<SkColorSpaceXform> xform = SkMakeColorSpaceXform(srcInfo.colorSpace(), + dstInfo.colorSpace()); if (!xform) { return false; } @@ -250,7 +247,7 @@ static void convert_to_alpha8(uint8_t* dst, size_t dstRB, const SkImageInfo& src // Default: Use the pipeline. static void convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, size_t dstRB, const SkImageInfo& srcInfo, const void* srcRow, size_t srcRB, - bool isColorAware, SkTransferFunctionBehavior behavior) { + bool isColorAware) { SkJumper_MemoryCtx src = { (void*)srcRow, (int)(srcRB / srcInfo.bytesPerPixel()) }, dst = { (void*)dstRow, (int)(dstRB / dstInfo.bytesPerPixel()) }; @@ -295,7 +292,7 @@ static void convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, size } SkAlphaType premulState = srcInfo.alphaType(); - if (kPremul_SkAlphaType == premulState && SkTransferFunctionBehavior::kIgnore == behavior) { + if (kPremul_SkAlphaType == premulState) { pipeline.append(SkRasterPipeline::unpremul); premulState = kUnpremul_SkAlphaType; } @@ -318,17 +315,6 @@ static void convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, size srcInfo.colorSpace(), dstInfo.colorSpace(), premulState); } - SkAlphaType dat = dstInfo.alphaType(); - if (SkTransferFunctionBehavior::kRespect == behavior) { - if (kPremul_SkAlphaType == premulState && kUnpremul_SkAlphaType == dat) { - pipeline.append(SkRasterPipeline::unpremul); - premulState = kUnpremul_SkAlphaType; - } else if (kUnpremul_SkAlphaType == premulState && kPremul_SkAlphaType == dat) { - pipeline.append(SkRasterPipeline::premul); - premulState = kPremul_SkAlphaType; - } - } - SkColorSpaceTransferFn dstFn; if (isColorAware && dstInfo.gammaCloseToSRGB()) { pipeline.append(SkRasterPipeline::to_srgb); @@ -342,8 +328,8 @@ static void convert_with_pipeline(const SkImageInfo& dstInfo, void* dstRow, size } } - if (kUnpremul_SkAlphaType == premulState && kPremul_SkAlphaType == dat && - SkTransferFunctionBehavior::kIgnore == behavior) + SkAlphaType dat = dstInfo.alphaType(); + if (kUnpremul_SkAlphaType == premulState && kPremul_SkAlphaType == dat) { pipeline.append(SkRasterPipeline::premul); premulState = kPremul_SkAlphaType; @@ -415,8 +401,7 @@ static bool swizzle_and_multiply_color_type(SkColorType ct) { } void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, - const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB, - SkTransferFunctionBehavior behavior) { + const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRB) { SkASSERT(dstInfo.dimensions() == srcInfo.dimensions()); SkASSERT(SkImageInfoValidConversion(dstInfo, srcInfo)); @@ -437,8 +422,8 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, } // Fast Path 3: Color space xform. - if (isColorAware && optimized_color_xform(dstInfo, srcInfo, behavior)) { - if (apply_color_xform(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB, behavior)) { + if (isColorAware && optimized_color_xform(dstInfo, srcInfo)) { + if (apply_color_xform(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB)) { return; } } @@ -450,6 +435,5 @@ void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, } // Default: Use the pipeline. - convert_with_pipeline(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB, isColorAware, - behavior); + convert_with_pipeline(dstInfo, dstPixels, dstRB, srcInfo, srcPixels, srcRB, isColorAware); } diff --git a/src/core/SkConvertPixels.h b/src/core/SkConvertPixels.h index 001052b7a8..ccd76c35a7 100644 --- a/src/core/SkConvertPixels.h +++ b/src/core/SkConvertPixels.h @@ -14,8 +14,7 @@ class SkColorTable; void SkConvertPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRowBytes, - const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes, - SkTransferFunctionBehavior behavior); + const SkImageInfo& srcInfo, const void* srcPixels, size_t srcRowBytes); static inline void SkRectMemcpy(void* dst, size_t dstRB, const void* src, size_t srcRB, size_t bytesPerRow, int rowCount) { diff --git a/src/core/SkPixmap.cpp b/src/core/SkPixmap.cpp index 77b174b154..d91b3cc9c1 100644 --- a/src/core/SkPixmap.cpp +++ b/src/core/SkPixmap.cpp @@ -81,7 +81,7 @@ bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { } bool SkPixmap::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB, int x, int y, - SkTransferFunctionBehavior behavior) const { + SkTransferFunctionBehavior) const { if (!SkImageInfoValidConversion(dstInfo, fInfo)) { return false; } @@ -93,8 +93,7 @@ bool SkPixmap::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t ds const void* srcPixels = this->addr(rec.fX, rec.fY); const SkImageInfo srcInfo = fInfo.makeWH(rec.fInfo.width(), rec.fInfo.height()); - SkConvertPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, srcInfo, srcPixels, this->rowBytes(), - behavior); + SkConvertPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, srcInfo, srcPixels, this->rowBytes()); return true; } |