aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/codec
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-09-07 18:53:14 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-09-07 18:53:14 -0700
commit2eb00e7b7783ad612f774b6952a7ca0fa23b17af (patch)
tree71530ded37d30a8385a4568cbac2d9913f6b8b3c /src/codec
parent828ed1777da74692d0c8a5834017929f5aedcc6b (diff)
Revert of Add color xform support to SkWebpCodec (patchset #2 id:80001 of https://codereview.chromium.org/2294993002/ )
Reason for revert: Windows bots hate it when I upload new images. Original issue's description: > Add color xform support to SkWebpCodec > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2294993002 > > Committed: https://skia.googlesource.com/skia/+/828ed1777da74692d0c8a5834017929f5aedcc6b TBR=scroggo@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review-Url: https://codereview.chromium.org/2318253004
Diffstat (limited to 'src/codec')
-rw-r--r--src/codec/SkCodecPriv.h4
-rw-r--r--src/codec/SkPngCodec.cpp16
-rw-r--r--src/codec/SkWebpCodec.cpp74
3 files changed, 25 insertions, 69 deletions
diff --git a/src/codec/SkCodecPriv.h b/src/codec/SkCodecPriv.h
index 9a8a43e835..17494074b3 100644
--- a/src/codec/SkCodecPriv.h
+++ b/src/codec/SkCodecPriv.h
@@ -331,8 +331,4 @@ static inline bool needs_color_xform(const SkImageInfo& dstInfo, const SkImageIn
return !isLegacy && (needsPremul || isF16 || srcDstNotEqual);
}
-static inline SkAlphaType select_alpha_xform(SkAlphaType dstAlphaType, SkAlphaType srcAlphaType) {
- return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlphaType;
-}
-
#endif // SkCodecPriv_DEFINED
diff --git a/src/codec/SkPngCodec.cpp b/src/codec/SkPngCodec.cpp
index ac7238d3e9..1b8cadbf5e 100644
--- a/src/codec/SkPngCodec.cpp
+++ b/src/codec/SkPngCodec.cpp
@@ -94,6 +94,10 @@ private:
};
#define AutoCleanPng(...) SK_REQUIRE_LOCAL_VAR(AutoCleanPng)
+static inline SkAlphaType xform_alpha_type(SkAlphaType dstAlphaType, SkAlphaType srcAlphaType) {
+ return (kOpaque_SkAlphaType == srcAlphaType) ? kOpaque_SkAlphaType : dstAlphaType;
+}
+
// Note: SkColorTable claims to store SkPMColors, which is not necessarily the case here.
bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo, int* ctableCount) {
@@ -151,8 +155,8 @@ bool SkPngCodec::createColorTable(const SkImageInfo& dstInfo, int* ctableCount)
if (fColorXform && kRGBA_F16_SkColorType != dstInfo.colorType()) {
SkColorType xformColorType = is_rgba(dstInfo.colorType()) ?
kRGBA_8888_SkColorType : kBGRA_8888_SkColorType;
- SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(),
- this->getInfo().alphaType());
+ SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
+ this->getInfo().alphaType());
fColorXform->apply(colorTable, colorTable, numColors, xformColorType, xformAlphaType);
}
@@ -443,8 +447,8 @@ public:
return y;
}
- SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(),
- this->getInfo().alphaType());
+ SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
+ this->getInfo().alphaType());
int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width();
for (; y < count; y++) {
@@ -529,8 +533,8 @@ public:
}
}
- SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(),
- this->getInfo().alphaType());
+ SkAlphaType xformAlphaType = xform_alpha_type(dstInfo.alphaType(),
+ this->getInfo().alphaType());
int width = fSwizzler ? fSwizzler->swizzleWidth() : dstInfo.width();
srcRow = storage.get();
for (int y = 0; y < count; y++) {
diff --git a/src/codec/SkWebpCodec.cpp b/src/codec/SkWebpCodec.cpp
index 0c3aa402bd..c12b1df5ed 100644
--- a/src/codec/SkWebpCodec.cpp
+++ b/src/codec/SkWebpCodec.cpp
@@ -6,7 +6,6 @@
*/
#include "SkCodecPriv.h"
-#include "SkColorSpaceXform.h"
#include "SkWebpCodec.h"
#include "SkStreamPriv.h"
#include "SkTemplates.h"
@@ -144,20 +143,20 @@ SkCodec* SkWebpCodec::NewFromStream(SkStream* stream) {
streamDeleter.release(), demux.release(), std::move(data));
}
-static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src,
- SkColorSpaceXform* colorXform) {
+// This version is slightly different from SkCodecPriv's version of conversion_possible. It
+// supports both byte orders for 8888.
+static bool webp_conversion_possible(const SkImageInfo& dst, const SkImageInfo& src) {
if (!valid_alpha(dst.alphaType(), src.alphaType())) {
return false;
}
switch (dst.colorType()) {
- case kRGBA_F16_SkColorType:
- return nullptr != colorXform;
+ // Both byte orders are supported.
case kBGRA_8888_SkColorType:
case kRGBA_8888_SkColorType:
return true;
case kRGB_565_SkColorType:
- return nullptr == colorXform && src.alphaType() == kOpaque_SkAlphaType;
+ return src.alphaType() == kOpaque_SkAlphaType;
default:
return false;
}
@@ -211,15 +210,8 @@ bool SkWebpCodec::onGetValidSubset(SkIRect* desiredSubset) const {
SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst, size_t rowBytes,
const Options& options, SkPMColor*, int*,
- int* rowsDecodedPtr) {
-
- std::unique_ptr<SkColorSpaceXform> colorXform = nullptr;
- if (needs_color_xform(dstInfo, this->getInfo())) {
- colorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpace()),
- sk_ref_sp(dstInfo.colorSpace()));
- }
-
- if (!webp_conversion_possible(dstInfo, this->getInfo(), colorXform.get())) {
+ int* rowsDecoded) {
+ if (!webp_conversion_possible(dstInfo, this->getInfo())) {
return kInvalidConversion;
}
@@ -277,28 +269,13 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
config.options.scaled_height = dstDimensions.height();
}
- // FIXME (msarett):
- // Lossless webp is encoded as BGRA. In that case, it would be more efficient to
- // to decode BGRA and apply the color xform to a BGRA buffer.
- config.output.colorspace = colorXform ? MODE_RGBA :
- webp_decode_mode(dstInfo.colorType(), dstInfo.alphaType() == kPremul_SkAlphaType);
+ config.output.colorspace = webp_decode_mode(dstInfo.colorType(),
+ dstInfo.alphaType() == kPremul_SkAlphaType);
+ config.output.u.RGBA.rgba = (uint8_t*) dst;
+ config.output.u.RGBA.stride = (int) rowBytes;
+ config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes);
config.output.is_external_memory = 1;
- // We will decode the entire image and then perform the color transform. libwebp
- // does not provide a row-by-row API. This is a shame particularly in the F16 case,
- // where we need to allocate an extra image-sized buffer.
- SkAutoTMalloc<uint32_t> pixels;
- if (kRGBA_F16_SkColorType == dstInfo.colorType()) {
- pixels.reset(dstDimensions.width() * dstDimensions.height());
- config.output.u.RGBA.rgba = (uint8_t*) pixels.get();
- config.output.u.RGBA.stride = (int) dstDimensions.width() * sizeof(uint32_t);
- config.output.u.RGBA.size = config.output.u.RGBA.stride * dstDimensions.height();
- } else {
- config.output.u.RGBA.rgba = (uint8_t*) dst;
- config.output.u.RGBA.stride = (int) rowBytes;
- config.output.u.RGBA.size = dstInfo.getSafeSize(rowBytes);
- }
-
WebPIterator frame;
SkAutoTCallVProc<WebPIterator, WebPDemuxReleaseIterator> autoFrame(&frame);
// If this succeeded in NewFromStream(), it should succeed again here.
@@ -309,36 +286,15 @@ SkCodec::Result SkWebpCodec::onGetPixels(const SkImageInfo& dstInfo, void* dst,
return kInvalidInput;
}
- int rowsDecoded;
- SkCodec::Result result;
switch (WebPIUpdate(idec, frame.fragment.bytes, frame.fragment.size)) {
case VP8_STATUS_OK:
- rowsDecoded = dstInfo.height();
- result = kSuccess;
- break;
+ return kSuccess;
case VP8_STATUS_SUSPENDED:
- WebPIDecGetRGB(idec, rowsDecodedPtr, nullptr, nullptr, nullptr);
- rowsDecoded = *rowsDecodedPtr;
- result = kIncompleteInput;
- break;
+ WebPIDecGetRGB(idec, rowsDecoded, nullptr, nullptr, nullptr);
+ return kIncompleteInput;
default:
return kInvalidInput;
}
-
- if (colorXform) {
- SkAlphaType xformAlphaType = select_alpha_xform(dstInfo.alphaType(),
- this->getInfo().alphaType());
-
- uint32_t* src = (uint32_t*) config.output.u.RGBA.rgba;
- size_t srcRowBytes = config.output.u.RGBA.stride;
- for (int y = 0; y < rowsDecoded; y++) {
- colorXform->apply(dst, src, dstInfo.width(), dstInfo.colorType(), xformAlphaType);
- dst = SkTAddOffset<void>(dst, rowBytes);
- src = SkTAddOffset<uint32_t>(src, srcRowBytes);
- }
- }
-
- return result;
}
SkWebpCodec::SkWebpCodec(int width, int height, const SkEncodedInfo& info,