diff options
author | Leon Scroggins <scroggo@google.com> | 2017-12-05 15:38:14 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-05 15:38:22 +0000 |
commit | 1793e7bb46c1f9d430c1a699a1c3d3168159b659 (patch) | |
tree | 22362338d6b7fec5dc58ff9e6aba05b3e55997b1 /src/codec | |
parent | a2e7f5ae10e3cf0514d69edc12c9ccbca39ccb17 (diff) |
Revert "Hide SkEncodedInfo"
This reverts commit c6f7a4ffa9522159efc42f7c948bba5e66bb8844.
Reason for revert: Causing differences in Gold, stemming from the fact that this changes the recommended SkImageInfo for 16 bits-per-component PNG from N32 to F16.
- an F16 bitmap already png-encodes to a 16 bits-per-component PNG, but it does not encode a linear colorspace (possibly a bug?). when we decode this PNG using getInfo(), it fails because it has an F16 color type and non-linear colorspace. (In the encode-srgb-png gm, this results in blank results for F16.) We could correct this on the encoder side, but it seems possible that a 16 bits-per-component PNG could be encoded with a different color space. In that case, we'd want SkCodec to recommend F16/SRGBLinear, but I think we'd want the SkCodec to store the encoded SkColorSpace so that we can Xform between the two. Currently SkCodec only stores one color space, so that will require a refactor.
- When decoding 16-bits-per-component PNGs, we are now decoding them to F16. This shows differences in Gold. The srgb/gpu results now look more like F16. I think this is fine.
Original change's description:
> Hide SkEncodedInfo
>
> Bug: skia:7353
> Bug: skia:6839
>
> This contains information that is not necessary for clients to know. The
> Color enum tells the number of components in the input, but this is only
> interesting internally (to the SkSwizzler).
>
> Similarly, the Alpha enum differs from SkAlphaType in that it has
> kBinary instead of kPremul. This is useful information only internally
> for determining whether the SkColorSpaceXform needs to premultiply.
>
> The bitsPerComponent is potentially useful for a client; Android (in
> SkAndroidCodec) uses it to determine the SkColorType. Rather than
> exposing bitsPerComponent, use it to make the same decision that Android
> would have made - 16 bits per component means to set the info to F16. Add
> a test that computeOutputColorType behaves as expected.
>
> Switch conversionSupported to use an SkColorType, which is enough info.
>
> Replace the SkEncodedInfo::Alpha field on SkCodec::FrameInfo with an
> SkAlphaType.
>
> SkCodec still needs an SkEncodedInfo, so move its header (which is
> already not SK_API) to include/private.
>
> Change-Id: Ie2cf11339bf999ebfd4390c0f448f7edd6feabda
> Reviewed-on: https://skia-review.googlesource.com/79260
> Reviewed-by: Mike Reed <reed@google.com>
> Reviewed-by: Mike Klein <mtklein@chromium.org>
> Commit-Queue: Leon Scroggins <scroggo@google.com>
TBR=mtklein@chromium.org,scroggo@google.com,reed@google.com
Change-Id: I0c5dd1461e1b70d1e55349a8e7ee6b029c3f556e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7353, skia:6839
Reviewed-on: https://skia-review.googlesource.com/80660
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Leon Scroggins <scroggo@google.com>
Diffstat (limited to 'src/codec')
-rw-r--r-- | src/codec/SkAndroidCodec.cpp | 11 | ||||
-rw-r--r-- | src/codec/SkCodec.cpp | 16 | ||||
-rw-r--r-- | src/codec/SkFrameHolder.h | 10 | ||||
-rw-r--r-- | src/codec/SkGifCodec.cpp | 4 | ||||
-rw-r--r-- | src/codec/SkHeifCodec.h | 2 | ||||
-rw-r--r-- | src/codec/SkIcoCodec.h | 2 | ||||
-rw-r--r-- | src/codec/SkJpegCodec.h | 2 | ||||
-rw-r--r-- | src/codec/SkWbmpCodec.cpp | 2 | ||||
-rw-r--r-- | src/codec/SkWbmpCodec.h | 2 | ||||
-rw-r--r-- | src/codec/SkWebpCodec.cpp | 7 | ||||
-rw-r--r-- | src/codec/SkWebpCodec.h | 12 |
11 files changed, 35 insertions, 35 deletions
diff --git a/src/codec/SkAndroidCodec.cpp b/src/codec/SkAndroidCodec.cpp index 4c76bdccb4..cd23680932 100644 --- a/src/codec/SkAndroidCodec.cpp +++ b/src/codec/SkAndroidCodec.cpp @@ -64,6 +64,10 @@ SkAndroidCodec::SkAndroidCodec(SkCodec* codec) SkAndroidCodec::~SkAndroidCodec() {} +const SkEncodedInfo& SkAndroidCodec::getEncodedInfo() const { + return fCodec->getEncodedInfo(); +} + std::unique_ptr<SkAndroidCodec> SkAndroidCodec::MakeFromStream(std::unique_ptr<SkStream> stream, SkPngChunkReader* chunkReader) { auto codec = SkCodec::MakeFromStream(std::move(stream), nullptr, chunkReader); if (nullptr == codec) { @@ -108,6 +112,7 @@ std::unique_ptr<SkAndroidCodec> SkAndroidCodec::MakeFromData(sk_sp<SkData> data, } SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorType) { + bool highPrecision = fCodec->getEncodedInfo().bitsPerComponent() > 8; switch (requestedColorType) { case kARGB_4444_SkColorType: return kN32_SkColorType; @@ -133,10 +138,8 @@ SkColorType SkAndroidCodec::computeOutputColorType(SkColorType requestedColorTyp break; } - if (this->getInfo().colorType() == kRGBA_F16_SkColorType) { - return kRGBA_F16_SkColorType; - } - return kN32_SkColorType; + // F16 is the Android default for high precision images. + return highPrecision ? kRGBA_F16_SkColorType : kN32_SkColorType; } SkAlphaType SkAndroidCodec::computeOutputAlphaType(bool requestedUnpremul) { diff --git a/src/codec/SkCodec.cpp b/src/codec/SkCodec.cpp index 7de083db3c..a0f1fb2706 100644 --- a/src/codec/SkCodec.cpp +++ b/src/codec/SkCodec.cpp @@ -158,7 +158,7 @@ SkCodec::SkCodec(const SkEncodedInfo& info, const SkImageInfo& imageInfo, SkCodec::~SkCodec() {} -bool SkCodec::conversionSupported(const SkImageInfo& dst, SkColorType srcColor, +bool SkCodec::conversionSupported(const SkImageInfo& dst, SkEncodedInfo::Color srcColor, bool srcIsOpaque, const SkColorSpace* srcCS) const { if (!valid_alpha(dst.alphaType(), srcIsOpaque)) { return false; @@ -173,7 +173,7 @@ bool SkCodec::conversionSupported(const SkImageInfo& dst, SkColorType srcColor, case kRGB_565_SkColorType: return srcIsOpaque; case kGray_8_SkColorType: - return kGray_8_SkColorType == srcColor && srcIsOpaque && + return SkEncodedInfo::kGray_Color == srcColor && srcIsOpaque && !needs_color_xform(dst, srcCS, false); case kAlpha_8_SkColorType: // conceptually we can convert anything into alpha_8, but we haven't actually coded @@ -224,7 +224,7 @@ SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, const Options& options) { const int index = options.fFrameIndex; if (0 == index) { - if (!this->conversionSupported(info, fSrcInfo.colorType(), fEncodedInfo.opaque(), + if (!this->conversionSupported(info, fEncodedInfo.color(), fEncodedInfo.opaque(), fSrcInfo.colorSpace()) || !this->initializeColorXform(info, fEncodedInfo.alpha(), options.fPremulBehavior)) { @@ -253,7 +253,7 @@ SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, const auto* frame = frameHolder->getFrame(index); SkASSERT(frame); - if (!this->conversionSupported(info, fSrcInfo.colorType(), !frame->hasAlpha(), + if (!this->conversionSupported(info, fEncodedInfo.color(), !frame->hasAlpha(), fSrcInfo.colorSpace())) { return kInvalidConversion; } @@ -297,7 +297,9 @@ SkCodec::Result SkCodec::handleFrameIndex(const SkImageInfo& info, void* pixels, } } - return this->initializeColorXform(info, frame->reportedAlpha(), options.fPremulBehavior) + FrameInfo frameInfo; + SkAssertResult(this->getFrameInfo(index, &frameInfo)); + return this->initializeColorXform(info, frameInfo.fAlpha, options.fPremulBehavior) ? kSuccess : kInvalidConversion; } @@ -628,10 +630,6 @@ bool SkCodec::initializeColorXform(const SkImageInfo& dstInfo, SkEncodedInfo::Al if (!this->usesColorXform()) { return true; } - // FIXME: In SkWebpCodec, if a frame is blending with a prior frame, we don't need - // a colorXform to do a color correct premul, since the blend step will handle - // premultiplication. But there is no way to know whether we need to blend from - // inside this call. bool needsColorCorrectPremul = needs_premul(dstInfo.alphaType(), encodedAlpha) && SkTransferFunctionBehavior::kRespect == premulBehavior; if (needs_color_xform(dstInfo, fSrcInfo.colorSpace(), needsColorCorrectPremul)) { diff --git a/src/codec/SkFrameHolder.h b/src/codec/SkFrameHolder.h index ab308b39db..29539ff908 100644 --- a/src/codec/SkFrameHolder.h +++ b/src/codec/SkFrameHolder.h @@ -40,14 +40,14 @@ public: int frameId() const { return fId; } /** - * How this frame reports its alpha. + * Whether this frame reports alpha. * * This only considers the rectangle of this frame, and * considers it to have alpha even if it is opaque once * blended with the frame behind it. */ - SkEncodedInfo::Alpha reportedAlpha() const { - return this->onReportedAlpha(); + bool reportsAlpha() const { + return this->onReportsAlpha(); } /** @@ -130,7 +130,7 @@ public: } protected: - virtual SkEncodedInfo::Alpha onReportedAlpha() const = 0; + virtual bool onReportsAlpha() const = 0; private: static constexpr int kUninitialized = -2; @@ -166,7 +166,7 @@ public: /** * Compute the opacity and required frame, based on - * the frame's reportedAlpha and how it blends + * whether the frame reportsAlpha and how it blends * with prior frames. */ void setAlphaAndRequiredFrame(SkFrame*); diff --git a/src/codec/SkGifCodec.cpp b/src/codec/SkGifCodec.cpp index dff8136d75..17c8617500 100644 --- a/src/codec/SkGifCodec.cpp +++ b/src/codec/SkGifCodec.cpp @@ -144,8 +144,8 @@ bool SkGifCodec::onGetFrameInfo(int i, SkCodec::FrameInfo* frameInfo) const { frameInfo->fDuration = frameContext->getDuration(); frameInfo->fRequiredFrame = frameContext->getRequiredFrame(); frameInfo->fFullyReceived = frameContext->isComplete(); - frameInfo->fAlphaType = frameContext->hasAlpha() ? kUnpremul_SkAlphaType - : kOpaque_SkAlphaType; + frameInfo->fAlpha = frameContext->hasAlpha() ? SkEncodedInfo::kBinary_Alpha + : SkEncodedInfo::kOpaque_Alpha; frameInfo->fDisposalMethod = frameContext->getDisposalMethod(); } return true; diff --git a/src/codec/SkHeifCodec.h b/src/codec/SkHeifCodec.h index 20bec6539e..6eb8e9c3b8 100644 --- a/src/codec/SkHeifCodec.h +++ b/src/codec/SkHeifCodec.h @@ -47,7 +47,7 @@ protected: return SkEncodedImageFormat::kHEIF; } - bool conversionSupported(const SkImageInfo&, SkColorType, bool, + bool conversionSupported(const SkImageInfo&, SkEncodedInfo::Color, bool, const SkColorSpace*) const override { // This class checks for conversion after creating colorXform. return true; diff --git a/src/codec/SkIcoCodec.h b/src/codec/SkIcoCodec.h index c43fcf8cc0..06ddeba9b4 100644 --- a/src/codec/SkIcoCodec.h +++ b/src/codec/SkIcoCodec.h @@ -48,7 +48,7 @@ protected: SkScanlineOrder onGetScanlineOrder() const override; - bool conversionSupported(const SkImageInfo&, SkColorType, bool, + bool conversionSupported(const SkImageInfo&, SkEncodedInfo::Color, bool, const SkColorSpace*) const override { // This will be checked by the embedded codec. return true; diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h index 7fab209b6e..41814d2ead 100644 --- a/src/codec/SkJpegCodec.h +++ b/src/codec/SkJpegCodec.h @@ -58,7 +58,7 @@ protected: bool onDimensionsSupported(const SkISize&) override; - bool conversionSupported(const SkImageInfo&, SkColorType, bool, + bool conversionSupported(const SkImageInfo&, SkEncodedInfo::Color, bool, const SkColorSpace*) const override { // This class checks for conversion after creating colorXform. return true; diff --git a/src/codec/SkWbmpCodec.cpp b/src/codec/SkWbmpCodec.cpp index d8b10287f6..63380e109c 100644 --- a/src/codec/SkWbmpCodec.cpp +++ b/src/codec/SkWbmpCodec.cpp @@ -108,7 +108,7 @@ SkEncodedImageFormat SkWbmpCodec::onGetEncodedFormat() const { return SkEncodedImageFormat::kWBMP; } -bool SkWbmpCodec::conversionSupported(const SkImageInfo& dst, SkColorType /*srcColor*/, +bool SkWbmpCodec::conversionSupported(const SkImageInfo& dst, SkEncodedInfo::Color srcColor, bool srcIsOpaque, const SkColorSpace* srcCS) const { return valid_color_type(dst) && valid_alpha(dst.alphaType(), srcIsOpaque); } diff --git a/src/codec/SkWbmpCodec.h b/src/codec/SkWbmpCodec.h index 192189d1ec..57efe21e3b 100644 --- a/src/codec/SkWbmpCodec.h +++ b/src/codec/SkWbmpCodec.h @@ -28,7 +28,7 @@ protected: Result onGetPixels(const SkImageInfo&, void*, size_t, const Options&, int*) override; bool onRewind() override; - bool conversionSupported(const SkImageInfo& dst, SkColorType srcColor, + bool conversionSupported(const SkImageInfo& dst, SkEncodedInfo::Color srcColor, bool srcIsOpaque, const SkColorSpace* srcCS) const override; // No need to Xform; all pixels are either black or white. bool usesColorXform() const override { return false; } diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp index 2ff4681337..d5614d6213 100644 --- a/src/codec/SkWebpCodec.cpp +++ b/src/codec/SkWebpCodec.cpp @@ -192,8 +192,7 @@ static WEBP_CSP_MODE webp_decode_mode(SkColorType dstCT, bool premultiply) { SkWebpCodec::Frame* SkWebpCodec::FrameHolder::appendNewFrame(bool hasAlpha) { const int i = this->size(); - fFrames.emplace_back(i, hasAlpha ? SkEncodedInfo::kUnpremul_Alpha - : SkEncodedInfo::kOpaque_Alpha); + fFrames.emplace_back(i, hasAlpha); return &fFrames[i]; } @@ -301,8 +300,8 @@ bool SkWebpCodec::onGetFrameInfo(int i, FrameInfo* frameInfo) const { // libwebp only reports fully received frames for an // animated image. frameInfo->fFullyReceived = true; - frameInfo->fAlphaType = frame->hasAlpha() ? kUnpremul_SkAlphaType - : kOpaque_SkAlphaType; + frameInfo->fAlpha = frame->hasAlpha() ? SkEncodedInfo::kUnpremul_Alpha + : SkEncodedInfo::kOpaque_Alpha; frameInfo->fDisposalMethod = frame->getDisposalMethod(); } diff --git a/src/codec/SkWebpCodec.h b/src/codec/SkWebpCodec.h index 010771bcff..134dafa3d5 100644 --- a/src/codec/SkWebpCodec.h +++ b/src/codec/SkWebpCodec.h @@ -58,22 +58,22 @@ private: class Frame : public SkFrame { public: - Frame(int i, SkEncodedInfo::Alpha alpha) + Frame(int i, bool alpha) : INHERITED(i) - , fReportedAlpha(alpha) + , fReportsAlpha(alpha) {} Frame(Frame&& other) : INHERITED(other.frameId()) - , fReportedAlpha(other.fReportedAlpha) + , fReportsAlpha(other.fReportsAlpha) {} protected: - SkEncodedInfo::Alpha onReportedAlpha() const override { - return fReportedAlpha; + bool onReportsAlpha() const override { + return fReportsAlpha; } private: - const SkEncodedInfo::Alpha fReportedAlpha; + const bool fReportsAlpha; typedef SkFrame INHERITED; }; |