2015-03-27 19:16:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-12-16 16:39:51 +00:00
|
|
|
#include "FakeStreams.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "Resources.h"
|
2015-10-21 17:27:10 +00:00
|
|
|
#include "SkAndroidCodec.h"
|
2017-01-11 17:44:43 +00:00
|
|
|
#include "SkAutoMalloc.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "SkBitmap.h"
|
2018-02-16 17:03:03 +00:00
|
|
|
#include "SkCanvas.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "SkCodec.h"
|
2016-01-14 21:12:26 +00:00
|
|
|
#include "SkCodecImageGenerator.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkColorSpace.h"
|
2017-03-15 21:50:08 +00:00
|
|
|
#include "SkColorSpacePriv.h"
|
2015-10-09 18:07:34 +00:00
|
|
|
#include "SkData.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#include "SkEncodedImageFormat.h"
|
2017-01-11 17:21:57 +00:00
|
|
|
#include "SkFrontBufferedStream.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#include "SkImage.h"
|
|
|
|
#include "SkImageGenerator.h"
|
|
|
|
#include "SkImageInfo.h"
|
2018-03-12 20:04:31 +00:00
|
|
|
#include "SkJpegEncoder.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#include "SkMD5.h"
|
|
|
|
#include "SkMakeUnique.h"
|
|
|
|
#include "SkMalloc.h"
|
|
|
|
#include "SkMatrix44.h"
|
|
|
|
#include "SkPixmap.h"
|
2017-01-11 17:44:43 +00:00
|
|
|
#include "SkPngChunkReader.h"
|
2017-05-05 15:13:26 +00:00
|
|
|
#include "SkPngEncoder.h"
|
2015-07-22 14:16:20 +00:00
|
|
|
#include "SkRandom.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#include "SkRect.h"
|
|
|
|
#include "SkRefCnt.h"
|
|
|
|
#include "SkSize.h"
|
2015-11-23 16:14:40 +00:00
|
|
|
#include "SkStream.h"
|
2015-11-30 14:25:31 +00:00
|
|
|
#include "SkStreamPriv.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkTemplates.h"
|
|
|
|
#include "SkTypes.h"
|
2018-02-16 17:03:03 +00:00
|
|
|
#include "SkUnPreMultiply.h"
|
2017-05-05 18:02:13 +00:00
|
|
|
#include "SkWebpEncoder.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "Test.h"
|
2015-11-23 16:14:40 +00:00
|
|
|
#include "png.h"
|
2018-03-12 20:04:31 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2018-03-12 17:46:21 +00:00
|
|
|
|
2018-03-12 17:46:21 +00:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <memory>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
#if PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR < 5
|
|
|
|
// FIXME (scroggo): Google3 needs to be updated to use a newer version of libpng. In
|
|
|
|
// the meantime, we had to break some pieces of SkPngCodec in order to support Google3.
|
|
|
|
// The parts that are broken are likely not used by Google3.
|
|
|
|
#define SK_PNG_DISABLE_TESTS
|
|
|
|
#endif
|
|
|
|
|
2015-03-27 19:16:53 +00:00
|
|
|
static void md5(const SkBitmap& bm, SkMD5::Digest* digest) {
|
|
|
|
SkASSERT(bm.getPixels());
|
|
|
|
SkMD5 md5;
|
|
|
|
size_t rowLen = bm.info().bytesPerPixel() * bm.width();
|
|
|
|
for (int y = 0; y < bm.height(); ++y) {
|
2016-04-25 17:29:36 +00:00
|
|
|
md5.write(bm.getAddr(0, y), rowLen);
|
2015-03-27 19:16:53 +00:00
|
|
|
}
|
|
|
|
md5.finish(*digest);
|
|
|
|
}
|
|
|
|
|
Allow creating multiple scanline decoders.
Make getScanlineDecoder return a new object each time, which is
owned by the caller, and independent from any existing scanline
decoders and the SkCodec itself.
Since the SkCodec already contains the entire state machine, and it
is used by the scanline decoders, simply create a new SkCodec which
is now owned by the scanline decoder.
Move code that cleans up after using a scanline decoder into its
destructor
One side effect is that creating the first scanline decoder requires
a duplication of the stream and re-reading the header. (With some
more complexity/changes, we could pass the state machine to the
scanline decoder and make the SkCodec recreate its own state machine
instead.) The typical client of the scanline decoder (region decoder)
uses an SkMemoryStream, so the duplication is cheap, although we
should consider the extra time to reread the header/recreate the state
machine. (If/when we use the scanline decoder for other purposes,
where the stream may not be cheaply duplicated, we should consider
passing the state machine.)
One (intended) result of this change is that a client can create a
new scanline decoder in a new thread, and decode different pieces of
the image simultaneously.
In SkPngCodec::decodePalette, use fBitDepth rather than a parameter.
Review URL: https://codereview.chromium.org/1230033004
2015-07-10 19:07:02 +00:00
|
|
|
/**
|
|
|
|
* Compute the digest for bm and compare it to a known good digest.
|
|
|
|
* @param r Reporter to assert that bm's digest matches goodDigest.
|
|
|
|
* @param goodDigest The known good digest to compare to.
|
|
|
|
* @param bm The bitmap to test.
|
|
|
|
*/
|
|
|
|
static void compare_to_good_digest(skiatest::Reporter* r, const SkMD5::Digest& goodDigest,
|
|
|
|
const SkBitmap& bm) {
|
|
|
|
SkMD5::Digest digest;
|
|
|
|
md5(bm, &digest);
|
|
|
|
REPORTER_ASSERT(r, digest == goodDigest);
|
|
|
|
}
|
|
|
|
|
2015-08-12 15:31:44 +00:00
|
|
|
/**
|
|
|
|
* Test decoding an SkCodec to a particular SkImageInfo.
|
|
|
|
*
|
2015-08-27 14:41:13 +00:00
|
|
|
* Calling getPixels(info) should return expectedResult, and if goodDigest is non nullptr,
|
2015-08-12 15:31:44 +00:00
|
|
|
* the resulting decode should match.
|
|
|
|
*/
|
2016-02-04 14:14:24 +00:00
|
|
|
template<typename Codec>
|
|
|
|
static void test_info(skiatest::Reporter* r, Codec* codec, const SkImageInfo& info,
|
2015-08-12 15:31:44 +00:00
|
|
|
SkCodec::Result expectedResult, const SkMD5::Digest* goodDigest) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
|
|
|
|
SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, result == expectedResult);
|
|
|
|
|
|
|
|
if (goodDigest) {
|
|
|
|
compare_to_good_digest(r, *goodDigest, bm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-22 14:16:20 +00:00
|
|
|
SkIRect generate_random_subset(SkRandom* rand, int w, int h) {
|
|
|
|
SkIRect rect;
|
|
|
|
do {
|
|
|
|
rect.fLeft = rand->nextRangeU(0, w);
|
|
|
|
rect.fTop = rand->nextRangeU(0, h);
|
|
|
|
rect.fRight = rand->nextRangeU(0, w);
|
|
|
|
rect.fBottom = rand->nextRangeU(0, h);
|
|
|
|
rect.sort();
|
|
|
|
} while (rect.isEmpty());
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
static void test_incremental_decode(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info,
|
|
|
|
const SkMD5::Digest& goodDigest) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == codec->startIncrementalDecode(info, bm.getPixels(),
|
|
|
|
bm.rowBytes()));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == codec->incrementalDecode());
|
|
|
|
|
|
|
|
compare_to_good_digest(r, goodDigest, bm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test in stripes, similar to DM's kStripe_Mode
|
|
|
|
static void test_in_stripes(skiatest::Reporter* r, SkCodec* codec, const SkImageInfo& info,
|
|
|
|
const SkMD5::Digest& goodDigest) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
bm.eraseColor(SK_ColorYELLOW);
|
|
|
|
|
|
|
|
const int height = info.height();
|
|
|
|
// Note that if numStripes does not evenly divide height there will be an extra
|
|
|
|
// stripe.
|
|
|
|
const int numStripes = 4;
|
|
|
|
|
|
|
|
if (numStripes > height) {
|
|
|
|
// Image is too small.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int stripeHeight = height / numStripes;
|
|
|
|
|
|
|
|
// Iterate through the image twice. Once to decode odd stripes, and once for even.
|
|
|
|
for (int oddEven = 1; oddEven >= 0; oddEven--) {
|
|
|
|
for (int y = oddEven * stripeHeight; y < height; y += 2 * stripeHeight) {
|
|
|
|
SkIRect subset = SkIRect::MakeLTRB(0, y, info.width(),
|
|
|
|
SkTMin(y + stripeHeight, height));
|
|
|
|
SkCodec::Options options;
|
|
|
|
options.fSubset = ⊂
|
|
|
|
if (SkCodec::kSuccess != codec->startIncrementalDecode(info, bm.getAddr(0, y),
|
|
|
|
bm.rowBytes(), &options)) {
|
|
|
|
ERRORF(r, "failed to start incremental decode!\ttop: %i\tbottom%i\n",
|
|
|
|
subset.top(), subset.bottom());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (SkCodec::kSuccess != codec->incrementalDecode()) {
|
|
|
|
ERRORF(r, "failed incremental decode starting from line %i\n", y);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
compare_to_good_digest(r, goodDigest, bm);
|
|
|
|
}
|
|
|
|
|
2016-02-04 14:14:24 +00:00
|
|
|
template<typename Codec>
|
|
|
|
static void test_codec(skiatest::Reporter* r, Codec* codec, SkBitmap& bm, const SkImageInfo& info,
|
2015-10-27 15:14:46 +00:00
|
|
|
const SkISize& size, SkCodec::Result expectedResult, SkMD5::Digest* digest,
|
|
|
|
const SkMD5::Digest* goodDigest) {
|
2015-10-09 18:07:34 +00:00
|
|
|
|
2015-03-27 19:16:53 +00:00
|
|
|
REPORTER_ASSERT(r, info.dimensions() == size);
|
|
|
|
bm.allocPixels(info);
|
2015-10-05 21:20:27 +00:00
|
|
|
|
|
|
|
SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes());
|
2015-10-09 18:07:34 +00:00
|
|
|
REPORTER_ASSERT(r, result == expectedResult);
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2015-10-05 21:20:27 +00:00
|
|
|
md5(bm, digest);
|
|
|
|
if (goodDigest) {
|
|
|
|
REPORTER_ASSERT(r, *digest == *goodDigest);
|
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2015-09-18 19:06:04 +00:00
|
|
|
{
|
|
|
|
// Test decoding to 565
|
|
|
|
SkImageInfo info565 = info.makeColorType(kRGB_565_SkColorType);
|
2016-05-20 20:56:13 +00:00
|
|
|
if (info.alphaType() == kOpaque_SkAlphaType) {
|
|
|
|
// Decoding to 565 should succeed.
|
|
|
|
SkBitmap bm565;
|
|
|
|
bm565.allocPixels(info565);
|
|
|
|
|
|
|
|
// This will allow comparison even if the image is incomplete.
|
|
|
|
bm565.eraseColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, expectedResult == codec->getPixels(info565,
|
|
|
|
bm565.getPixels(), bm565.rowBytes()));
|
|
|
|
|
|
|
|
SkMD5::Digest digest565;
|
|
|
|
md5(bm565, &digest565);
|
|
|
|
|
|
|
|
// A dumb client's request for non-opaque should also succeed.
|
|
|
|
for (auto alpha : { kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
|
|
|
|
info565 = info565.makeAlphaType(alpha);
|
|
|
|
test_info(r, codec, info565, expectedResult, &digest565);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
test_info(r, codec, info565, SkCodec::kInvalidConversion, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codec->getInfo().colorType() == kGray_8_SkColorType) {
|
|
|
|
SkImageInfo grayInfo = codec->getInfo();
|
|
|
|
SkBitmap grayBm;
|
|
|
|
grayBm.allocPixels(grayInfo);
|
|
|
|
|
|
|
|
grayBm.eraseColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, expectedResult == codec->getPixels(grayInfo,
|
|
|
|
grayBm.getPixels(), grayBm.rowBytes()));
|
|
|
|
|
|
|
|
SkMD5::Digest grayDigest;
|
|
|
|
md5(grayBm, &grayDigest);
|
|
|
|
|
|
|
|
for (auto alpha : { kPremul_SkAlphaType, kUnpremul_SkAlphaType }) {
|
|
|
|
grayInfo = grayInfo.makeAlphaType(alpha);
|
|
|
|
test_info(r, codec, grayInfo, expectedResult, &grayDigest);
|
|
|
|
}
|
2015-09-18 19:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that re-decoding gives the same result. It is interesting to check this after
|
|
|
|
// a decode to 565, since choosing to decode to 565 may result in some of the decode
|
|
|
|
// options being modified. These options should return to their defaults on another
|
|
|
|
// decode to kN32, so the new digest should match the old digest.
|
2015-10-09 18:07:34 +00:00
|
|
|
test_info(r, codec, info, expectedResult, digest);
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2015-08-12 15:31:44 +00:00
|
|
|
{
|
|
|
|
// Check alpha type conversions
|
|
|
|
if (info.alphaType() == kOpaque_SkAlphaType) {
|
|
|
|
test_info(r, codec, info.makeAlphaType(kUnpremul_SkAlphaType),
|
2016-02-03 17:42:42 +00:00
|
|
|
expectedResult, digest);
|
2015-08-12 15:31:44 +00:00
|
|
|
test_info(r, codec, info.makeAlphaType(kPremul_SkAlphaType),
|
2016-02-03 17:42:42 +00:00
|
|
|
expectedResult, digest);
|
2015-08-12 15:31:44 +00:00
|
|
|
} else {
|
|
|
|
// Decoding to opaque should fail
|
|
|
|
test_info(r, codec, info.makeAlphaType(kOpaque_SkAlphaType),
|
2015-08-27 14:41:13 +00:00
|
|
|
SkCodec::kInvalidConversion, nullptr);
|
2015-08-12 15:31:44 +00:00
|
|
|
SkAlphaType otherAt = info.alphaType();
|
|
|
|
if (kPremul_SkAlphaType == otherAt) {
|
|
|
|
otherAt = kUnpremul_SkAlphaType;
|
|
|
|
} else {
|
|
|
|
otherAt = kPremul_SkAlphaType;
|
|
|
|
}
|
|
|
|
// The other non-opaque alpha type should always succeed, but not match.
|
2015-10-09 18:07:34 +00:00
|
|
|
test_info(r, codec, info.makeAlphaType(otherAt), expectedResult, nullptr);
|
2015-08-12 15:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 21:20:27 +00:00
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2016-02-11 18:24:55 +00:00
|
|
|
static bool supports_partial_scanlines(const char path[]) {
|
2015-10-09 15:40:59 +00:00
|
|
|
static const char* const exts[] = {
|
|
|
|
"jpg", "jpeg", "png", "webp"
|
|
|
|
"JPG", "JPEG", "PNG", "WEBP"
|
|
|
|
};
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
|
|
|
|
if (SkStrEndsWith(path, exts[i])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
// FIXME: Break up this giant function
|
2015-10-05 21:20:27 +00:00
|
|
|
static void check(skiatest::Reporter* r,
|
|
|
|
const char path[],
|
|
|
|
SkISize size,
|
|
|
|
bool supportsScanlineDecoding,
|
|
|
|
bool supportsSubsetDecoding,
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
bool supportsIncomplete,
|
|
|
|
bool supportsNewScanlineDecoding = false) {
|
2018-07-31 23:59:38 +00:00
|
|
|
// If we're testing incomplete decodes, let's run the same test on full decodes.
|
|
|
|
if (supportsIncomplete) {
|
|
|
|
check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, false,
|
|
|
|
supportsNewScanlineDecoding);
|
|
|
|
}
|
2015-04-01 18:25:20 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
2015-10-05 21:20:27 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 18:07:34 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(nullptr);
|
2018-07-31 23:59:38 +00:00
|
|
|
if (supportsIncomplete) {
|
2015-10-09 18:07:34 +00:00
|
|
|
size_t size = stream->getLength();
|
2017-07-23 19:30:02 +00:00
|
|
|
codec = SkCodec::MakeFromData(SkData::MakeFromStream(stream.get(), 2 * size / 3));
|
2015-10-09 18:07:34 +00:00
|
|
|
} else {
|
2017-07-23 19:30:02 +00:00
|
|
|
codec = SkCodec::MakeFromStream(std::move(stream));
|
2015-10-09 18:07:34 +00:00
|
|
|
}
|
2015-10-05 21:20:27 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Unable to decode '%s'", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test full image decodes with SkCodec
|
|
|
|
SkMD5::Digest codecDigest;
|
2016-02-18 13:59:25 +00:00
|
|
|
const SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
|
2015-10-05 21:20:27 +00:00
|
|
|
SkBitmap bm;
|
2018-07-31 23:59:38 +00:00
|
|
|
SkCodec::Result expectedResult =
|
|
|
|
supportsIncomplete ? SkCodec::kIncompleteInput : SkCodec::kSuccess;
|
2016-02-04 14:14:24 +00:00
|
|
|
test_codec(r, codec.get(), bm, info, size, expectedResult, &codecDigest, nullptr);
|
2015-10-05 21:20:27 +00:00
|
|
|
|
|
|
|
// Scanline decoding follows.
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
|
2018-07-31 23:59:38 +00:00
|
|
|
if (supportsNewScanlineDecoding && !supportsIncomplete) {
|
2016-11-03 18:40:50 +00:00
|
|
|
test_incremental_decode(r, codec.get(), info, codecDigest);
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
// This is only supported by codecs that use incremental decoding to
|
|
|
|
// support subset decodes - png and jpeg (once SkJpegCodec is
|
|
|
|
// converted).
|
|
|
|
if (SkStrEndsWith(path, "png") || SkStrEndsWith(path, "PNG")) {
|
2016-11-03 18:40:50 +00:00
|
|
|
test_in_stripes(r, codec.get(), info, codecDigest);
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
}
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Need to call startScanlineDecode() first.
|
|
|
|
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0) == 0);
|
|
|
|
REPORTER_ASSERT(r, !codec->skipScanlines(1));
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
const SkCodec::Result startResult = codec->startScanlineDecode(info);
|
2015-04-01 18:25:20 +00:00
|
|
|
if (supportsScanlineDecoding) {
|
|
|
|
bm.eraseColor(SK_ColorYELLOW);
|
2015-07-01 13:50:35 +00:00
|
|
|
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
REPORTER_ASSERT(r, startResult == SkCodec::kSuccess);
|
Allow creating multiple scanline decoders.
Make getScanlineDecoder return a new object each time, which is
owned by the caller, and independent from any existing scanline
decoders and the SkCodec itself.
Since the SkCodec already contains the entire state machine, and it
is used by the scanline decoders, simply create a new SkCodec which
is now owned by the scanline decoder.
Move code that cleans up after using a scanline decoder into its
destructor
One side effect is that creating the first scanline decoder requires
a duplication of the stream and re-reading the header. (With some
more complexity/changes, we could pass the state machine to the
scanline decoder and make the SkCodec recreate its own state machine
instead.) The typical client of the scanline decoder (region decoder)
uses an SkMemoryStream, so the duplication is cheap, although we
should consider the extra time to reread the header/recreate the state
machine. (If/when we use the scanline decoder for other purposes,
where the stream may not be cheaply duplicated, we should consider
passing the state machine.)
One (intended) result of this change is that a client can create a
new scanline decoder in a new thread, and decode different pieces of
the image simultaneously.
In SkPngCodec::decodePalette, use fBitDepth rather than a parameter.
Review URL: https://codereview.chromium.org/1230033004
2015-07-10 19:07:02 +00:00
|
|
|
|
2015-04-01 18:25:20 +00:00
|
|
|
for (int y = 0; y < info.height(); y++) {
|
2015-10-09 18:07:34 +00:00
|
|
|
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
|
2018-07-31 23:59:38 +00:00
|
|
|
if (!supportsIncomplete) {
|
2015-10-09 18:07:34 +00:00
|
|
|
REPORTER_ASSERT(r, 1 == lines);
|
|
|
|
}
|
2015-04-01 18:25:20 +00:00
|
|
|
}
|
|
|
|
// verify that scanline decoding gives the same result.
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
if (SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder()) {
|
2015-10-05 21:20:27 +00:00
|
|
|
compare_to_good_digest(r, codecDigest, bm);
|
2015-08-31 13:55:13 +00:00
|
|
|
}
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
|
|
|
// Cannot continue to decode scanlines beyond the end
|
|
|
|
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
|
2015-10-09 18:07:34 +00:00
|
|
|
== 0);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
|
|
|
|
// Interrupting a scanline decode with a full decode starts from
|
|
|
|
// scratch
|
|
|
|
REPORTER_ASSERT(r, codec->startScanlineDecode(info) == SkCodec::kSuccess);
|
2015-10-09 18:07:34 +00:00
|
|
|
const int lines = codec->getScanlines(bm.getAddr(0, 0), 1, 0);
|
2018-07-31 23:59:38 +00:00
|
|
|
if (!supportsIncomplete) {
|
2015-10-09 18:07:34 +00:00
|
|
|
REPORTER_ASSERT(r, lines == 1);
|
|
|
|
}
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
REPORTER_ASSERT(r, codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes())
|
2015-10-09 18:07:34 +00:00
|
|
|
== expectedResult);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
REPORTER_ASSERT(r, codec->getScanlines(bm.getAddr(0, 0), 1, 0)
|
2015-10-09 18:07:34 +00:00
|
|
|
== 0);
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
REPORTER_ASSERT(r, codec->skipScanlines(1)
|
2015-10-09 18:07:34 +00:00
|
|
|
== 0);
|
2015-10-16 17:54:12 +00:00
|
|
|
|
|
|
|
// Test partial scanline decodes
|
2016-02-11 18:24:55 +00:00
|
|
|
if (supports_partial_scanlines(path) && info.width() >= 3) {
|
2015-10-16 17:54:12 +00:00
|
|
|
SkCodec::Options options;
|
|
|
|
int width = info.width();
|
|
|
|
int height = info.height();
|
|
|
|
SkIRect subset = SkIRect::MakeXYWH(2 * (width / 3), 0, width / 3, height);
|
|
|
|
options.fSubset = ⊂
|
|
|
|
|
2017-07-11 17:35:31 +00:00
|
|
|
const auto partialStartResult = codec->startScanlineDecode(info, &options);
|
2015-10-16 17:54:12 +00:00
|
|
|
REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess);
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
|
2018-07-31 23:59:38 +00:00
|
|
|
if (!supportsIncomplete) {
|
2015-10-16 17:54:12 +00:00
|
|
|
REPORTER_ASSERT(r, 1 == lines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-01 18:25:20 +00:00
|
|
|
} else {
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
REPORTER_ASSERT(r, startResult == SkCodec::kUnimplemented);
|
2015-03-27 19:16:53 +00:00
|
|
|
}
|
2015-07-22 14:16:20 +00:00
|
|
|
|
|
|
|
// The rest of this function tests decoding subsets, and will decode an arbitrary number of
|
|
|
|
// random subsets.
|
|
|
|
// Do not attempt to decode subsets of an image of only once pixel, since there is no
|
|
|
|
// meaningful subset.
|
|
|
|
if (size.width() * size.height() == 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkRandom rand;
|
|
|
|
SkIRect subset;
|
|
|
|
SkCodec::Options opts;
|
|
|
|
opts.fSubset = ⊂
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
subset = generate_random_subset(&rand, size.width(), size.height());
|
|
|
|
SkASSERT(!subset.isEmpty());
|
|
|
|
const bool supported = codec->getValidSubset(&subset);
|
|
|
|
REPORTER_ASSERT(r, supported == supportsSubsetDecoding);
|
|
|
|
|
|
|
|
SkImageInfo subsetInfo = info.makeWH(subset.width(), subset.height());
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(subsetInfo);
|
2017-07-11 17:35:31 +00:00
|
|
|
const auto result = codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes(), &opts);
|
2015-07-22 14:16:20 +00:00
|
|
|
|
|
|
|
if (supportsSubsetDecoding) {
|
2016-12-20 14:49:25 +00:00
|
|
|
if (expectedResult == SkCodec::kSuccess) {
|
|
|
|
REPORTER_ASSERT(r, result == expectedResult);
|
|
|
|
}
|
2015-07-22 14:16:20 +00:00
|
|
|
// Webp is the only codec that supports subsets, and it will have modified the subset
|
|
|
|
// to have even left/top.
|
|
|
|
REPORTER_ASSERT(r, SkIsAlign2(subset.fLeft) && SkIsAlign2(subset.fTop));
|
|
|
|
} else {
|
|
|
|
// No subsets will work.
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kUnimplemented);
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 21:20:27 +00:00
|
|
|
|
2016-02-11 18:24:55 +00:00
|
|
|
// SkAndroidCodec tests
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (supportsScanlineDecoding || supportsSubsetDecoding || supportsNewScanlineDecoding) {
|
2015-10-09 15:40:59 +00:00
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
2015-10-05 21:20:27 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 18:07:34 +00:00
|
|
|
|
2018-01-04 18:26:30 +00:00
|
|
|
auto androidCodec = SkAndroidCodec::MakeFromCodec(std::move(codec));
|
2016-02-04 14:14:24 +00:00
|
|
|
if (!androidCodec) {
|
2015-10-05 21:20:27 +00:00
|
|
|
ERRORF(r, "Unable to decode '%s'", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap bm;
|
2016-02-11 18:24:55 +00:00
|
|
|
SkMD5::Digest androidCodecDigest;
|
|
|
|
test_codec(r, androidCodec.get(), bm, info, size, expectedResult, &androidCodecDigest,
|
2016-02-04 14:14:24 +00:00
|
|
|
&codecDigest);
|
2015-10-09 18:07:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 23:59:38 +00:00
|
|
|
if (!supportsIncomplete) {
|
2016-02-18 13:59:25 +00:00
|
|
|
// Test SkCodecImageGenerator
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
|
|
|
sk_sp<SkData> fullData(SkData::MakeFromStream(stream.get(), stream->getLength()));
|
|
|
|
std::unique_ptr<SkImageGenerator> gen(
|
2017-02-15 20:14:16 +00:00
|
|
|
SkCodecImageGenerator::MakeFromEncodedCodec(fullData));
|
2016-01-14 21:12:26 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
REPORTER_ASSERT(r, gen->getPixels(info, bm.getPixels(), bm.rowBytes()));
|
|
|
|
compare_to_good_digest(r, codecDigest, bm);
|
2016-02-18 13:59:25 +00:00
|
|
|
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
#ifndef SK_PNG_DISABLE_TESTS
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
// Test using SkFrontBufferedStream, as Android does
|
2017-09-16 01:39:47 +00:00
|
|
|
auto bufferedStream = SkFrontBufferedStream::Make(
|
|
|
|
SkMemoryStream::Make(std::move(fullData)), SkCodec::MinBufferedBytesNeeded());
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
REPORTER_ASSERT(r, bufferedStream);
|
2017-09-16 01:39:47 +00:00
|
|
|
codec = SkCodec::MakeFromStream(std::move(bufferedStream));
|
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ )
Reason for revert:
Still causing problems in Google3, e.g.
https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm
Original issue's description:
> Make SkPngCodec decode progressively.
>
> This is a step towards using SkCodec in Chromium, where progressive
> decoding is necessary.
>
> Switch from using png_read_row (which expects all the data to be
> available) to png_process_data, which uses callbacks when rows are
> available.
>
> Create a new API for SkCodec, which supports progressive decoding and
> scanline decoding. Future changes will switch the other clients off of
> startScanlineDecode and get/skip-Scanlines to the new API.
>
> Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
> PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
> updateCurrScanline(), which was only used by the old implementation for
> interlaced PNG.
>
> DMSrcSink:
> - In CodecSrc::kScanline_Mode, use the new method for scanline decoding
> for the supported formats (just PNG and PNG-in-ICO for now).
>
> fuzz.cpp:
> - Remove reference to kNone_ScanlineOrder
>
> SkCodec:
> - Add new APIs:
> - startIncrementalDecode
> - incrementalDecode
> - Remove kNone_SkScanlineOrder and updateCurrScanline()
>
> SkPngCodec:
> - Implement new APIs
> - Switch from sk_read_fn/png_read_row etc to png_process_data
> - Expand AutoCleanPng's role to decode the header and create the
> SkPngCodec
> - Make the interlaced PNG decoder report how many lines were
> initialized during an incomplete decode
> - Make initializeSwizzler return a bool instead of an SkCodec::Result
> (It only returned kSuccess or kInvalidInput anyway)
>
> SkIcoCodec:
> - Implement the new APIs; supported for PNG in ICO
>
> SkSampledCodec:
> - Call the new method for decoding scanlines, and fall back to the old
> method if the new version is unimplemented
> - Remove references to kNone_SkScanlineOrder
>
> tests/CodecPartial:
> - Add a test which decodes part of an image, then finishes the decode,
> and compares it to the straightforward method
>
> tests/CodecTest:
> - Add a test which decodes all scanlines using the new method
> - Repurpose the Codec_stripes test to decode using the new method in
> sections rather than all at once
> - In the method check(), add a parameter for whether the image supports
> the new method of scanline decoding, and be explicit about whether an
> image supports incomplete
> - Test incomplete PNG decodes. We should have been doing it anyway for
> non-interlaced (except for an image that is too small - one row), but
> the new method supports interlaced incomplete as well
> - Make test_invalid_parameters test the new method
> - Add a test to ensure that it's safe to fall back to scanline decoding without
> rewinding
>
> BUG=skia:4211
>
> The new version was generally faster than the old version (but not significantly so).
>
> Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
>
> Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
>
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
>
> Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e
>
> Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965
>
> Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f
TBR=reed@google.com,msarett@google.com,scroggo@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:4211
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002
Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
if (codec) {
|
|
|
|
test_info(r, codec.get(), info, SkCodec::kSuccess, &codecDigest);
|
2016-02-18 13:59:25 +00:00
|
|
|
}
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
#endif
|
2016-01-14 21:12:26 +00:00
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_wbmp, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/mandrill.wbmp", SkISize::Make(512, 512), true, false, true);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_webp, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/baby_tux.webp", SkISize::Make(386, 395), false, true, true);
|
|
|
|
check(r, "images/color_wheel.webp", SkISize::Make(128, 128), false, true, true);
|
|
|
|
check(r, "images/yellow_rose.webp", SkISize::Make(400, 301), false, true, true);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2015-06-18 19:53:43 +00:00
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_bmp, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/randPixels.bmp", SkISize::Make(8, 8), true, false, true);
|
|
|
|
check(r, "images/rle.bmp", SkISize::Make(320, 240), true, false, true);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_ico, r) {
|
2015-10-09 18:07:34 +00:00
|
|
|
// FIXME: We are not ready to test incomplete ICOs
|
2015-04-01 19:09:21 +00:00
|
|
|
// These two tests examine interestingly different behavior:
|
|
|
|
// Decodes an embedded BMP image
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/color_wheel.ico", SkISize::Make(128, 128), true, false, false);
|
2015-04-01 19:09:21 +00:00
|
|
|
// Decodes an embedded PNG image
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/google_chrome.ico", SkISize::Make(256, 256), false, false, false, true);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_gif, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/box.gif", SkISize::Make(200, 55), false, false, true, true);
|
|
|
|
check(r, "images/color_wheel.gif", SkISize::Make(128, 128), false, false, true, true);
|
2015-10-09 18:07:34 +00:00
|
|
|
// randPixels.gif is too small to test incomplete
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/randPixels.gif", SkISize::Make(8, 8), false, false, false, true);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2015-04-09 19:43:10 +00:00
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_jpg, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/CMYK.jpg", SkISize::Make(642, 516), true, false, true);
|
|
|
|
check(r, "images/color_wheel.jpg", SkISize::Make(128, 128), true, false, true);
|
2015-10-09 18:07:34 +00:00
|
|
|
// grayscale.jpg is too small to test incomplete
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/grayscale.jpg", SkISize::Make(128, 128), true, false, false);
|
|
|
|
check(r, "images/mandrill_512_q075.jpg", SkISize::Make(512, 512), true, false, true);
|
2015-10-09 18:07:34 +00:00
|
|
|
// randPixels.jpg is too small to test incomplete
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/randPixels.jpg", SkISize::Make(8, 8), true, false, false);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2015-04-15 14:32:19 +00:00
|
|
|
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_png, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/arrow.png", SkISize::Make(187, 312), false, false, true, true);
|
|
|
|
check(r, "images/baby_tux.png", SkISize::Make(240, 246), false, false, true, true);
|
|
|
|
check(r, "images/color_wheel.png", SkISize::Make(128, 128), false, false, true, true);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
// half-transparent-white-pixel.png is too small to test incomplete
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/half-transparent-white-pixel.png", SkISize::Make(1, 1), false, false, false, true);
|
|
|
|
check(r, "images/mandrill_128.png", SkISize::Make(128, 128), false, false, true, true);
|
2018-07-09 18:57:48 +00:00
|
|
|
// mandrill_16.png is too small (relative to embedded sRGB profile) to test incomplete
|
|
|
|
check(r, "images/mandrill_16.png", SkISize::Make(16, 16), false, false, false, true);
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/mandrill_256.png", SkISize::Make(256, 256), false, false, true, true);
|
|
|
|
check(r, "images/mandrill_32.png", SkISize::Make(32, 32), false, false, true, true);
|
|
|
|
check(r, "images/mandrill_512.png", SkISize::Make(512, 512), false, false, true, true);
|
|
|
|
check(r, "images/mandrill_64.png", SkISize::Make(64, 64), false, false, true, true);
|
|
|
|
check(r, "images/plane.png", SkISize::Make(250, 126), false, false, true, true);
|
|
|
|
check(r, "images/plane_interlaced.png", SkISize::Make(250, 126), false, false, true, true);
|
|
|
|
check(r, "images/randPixels.png", SkISize::Make(8, 8), false, false, true, true);
|
|
|
|
check(r, "images/yellow_rose.png", SkISize::Make(400, 301), false, false, true, true);
|
2016-12-06 15:58:02 +00:00
|
|
|
}
|
2016-01-25 16:26:16 +00:00
|
|
|
|
2016-02-29 15:14:42 +00:00
|
|
|
// Disable RAW tests for Win32.
|
|
|
|
#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_raw, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check(r, "images/sample_1mp.dng", SkISize::Make(600, 338), false, false, false);
|
|
|
|
check(r, "images/sample_1mp_rotated.dng", SkISize::Make(600, 338), false, false, false);
|
|
|
|
check(r, "images/dng_with_preview.dng", SkISize::Make(600, 338), true, false, false);
|
2015-03-27 19:16:53 +00:00
|
|
|
}
|
2016-12-06 15:58:02 +00:00
|
|
|
#endif
|
2015-04-03 14:22:22 +00:00
|
|
|
|
|
|
|
static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_t len) {
|
2015-10-09 15:40:59 +00:00
|
|
|
// Neither of these calls should return a codec. Bots should catch us if we leaked anything.
|
2017-07-23 19:30:02 +00:00
|
|
|
REPORTER_ASSERT(r, !SkCodec::MakeFromStream(
|
|
|
|
skstd::make_unique<SkMemoryStream>(stream, len, false)));
|
|
|
|
REPORTER_ASSERT(r, !SkAndroidCodec::MakeFromStream(
|
|
|
|
skstd::make_unique<SkMemoryStream>(stream, len, false)));
|
2015-04-03 14:22:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that SkCodec::NewFromStream handles freeing the passed in SkStream,
|
|
|
|
// even on failure. Test some bad streams.
|
|
|
|
DEF_TEST(Codec_leaks, r) {
|
|
|
|
// No codec should claim this as their format, so this tests SkCodec::NewFromStream.
|
|
|
|
const char nonSupportedStream[] = "hello world";
|
|
|
|
// The other strings should look like the beginning of a file type, so we'll call some
|
|
|
|
// internal version of NewFromStream, which must also delete the stream on failure.
|
|
|
|
const unsigned char emptyPng[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
|
|
|
|
const unsigned char emptyJpeg[] = { 0xFF, 0xD8, 0xFF };
|
|
|
|
const char emptyWebp[] = "RIFF1234WEBPVP";
|
|
|
|
const char emptyBmp[] = { 'B', 'M' };
|
|
|
|
const char emptyIco[] = { '\x00', '\x00', '\x01', '\x00' };
|
|
|
|
const char emptyGif[] = "GIFVER";
|
|
|
|
|
|
|
|
test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream));
|
|
|
|
test_invalid_stream(r, emptyPng, sizeof(emptyPng));
|
|
|
|
test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg));
|
|
|
|
test_invalid_stream(r, emptyWebp, sizeof(emptyWebp));
|
|
|
|
test_invalid_stream(r, emptyBmp, sizeof(emptyBmp));
|
|
|
|
test_invalid_stream(r, emptyIco, sizeof(emptyIco));
|
|
|
|
test_invalid_stream(r, emptyGif, sizeof(emptyGif));
|
|
|
|
}
|
2015-04-15 14:32:19 +00:00
|
|
|
|
2015-10-09 15:40:59 +00:00
|
|
|
DEF_TEST(Codec_null, r) {
|
2016-02-11 18:24:55 +00:00
|
|
|
// Attempting to create an SkCodec or an SkAndroidCodec with null should not
|
2015-10-09 15:40:59 +00:00
|
|
|
// crash.
|
2017-07-23 19:30:02 +00:00
|
|
|
REPORTER_ASSERT(r, !SkCodec::MakeFromStream(nullptr));
|
|
|
|
REPORTER_ASSERT(r, !SkAndroidCodec::MakeFromStream(nullptr));
|
2015-10-09 15:40:59 +00:00
|
|
|
}
|
|
|
|
|
2015-04-15 14:32:19 +00:00
|
|
|
static void test_dimensions(skiatest::Reporter* r, const char path[]) {
|
|
|
|
// Create the codec from the resource file
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
2015-04-15 14:32:19 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
|
2015-04-15 14:32:19 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Unable to create codec '%s'", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the decode is successful for a variety of scales
|
2015-11-03 15:55:11 +00:00
|
|
|
for (int sampleSize = 1; sampleSize < 32; sampleSize++) {
|
2015-04-15 14:32:19 +00:00
|
|
|
// Scale the output dimensions
|
2015-10-21 17:27:10 +00:00
|
|
|
SkISize scaledDims = codec->getSampledDimensions(sampleSize);
|
2015-08-18 20:22:46 +00:00
|
|
|
SkImageInfo scaledInfo = codec->getInfo()
|
|
|
|
.makeWH(scaledDims.width(), scaledDims.height())
|
|
|
|
.makeColorType(kN32_SkColorType);
|
2015-04-15 14:32:19 +00:00
|
|
|
|
|
|
|
// Set up for the decode
|
|
|
|
size_t rowBytes = scaledDims.width() * sizeof(SkPMColor);
|
2017-10-03 18:47:21 +00:00
|
|
|
size_t totalBytes = scaledInfo.computeByteSize(rowBytes);
|
2015-04-15 14:32:19 +00:00
|
|
|
SkAutoTMalloc<SkPMColor> pixels(totalBytes);
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
SkAndroidCodec::AndroidOptions options;
|
|
|
|
options.fSampleSize = sampleSize;
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
SkCodec::Result result =
|
2015-10-21 17:27:10 +00:00
|
|
|
codec->getAndroidPixels(scaledInfo, pixels.get(), rowBytes, &options);
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
2015-04-15 14:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that onGetScaledDimensions returns valid image dimensions to use for decodes
|
|
|
|
DEF_TEST(Codec_Dimensions, r) {
|
|
|
|
// JPG
|
2017-12-08 15:21:31 +00:00
|
|
|
test_dimensions(r, "images/CMYK.jpg");
|
|
|
|
test_dimensions(r, "images/color_wheel.jpg");
|
|
|
|
test_dimensions(r, "images/grayscale.jpg");
|
|
|
|
test_dimensions(r, "images/mandrill_512_q075.jpg");
|
|
|
|
test_dimensions(r, "images/randPixels.jpg");
|
2015-08-18 20:22:46 +00:00
|
|
|
|
|
|
|
// Decoding small images with very large scaling factors is a potential
|
|
|
|
// source of bugs and crashes. We disable these tests in Gold because
|
|
|
|
// tiny images are not very useful to look at.
|
|
|
|
// Here we make sure that we do not crash or access illegal memory when
|
|
|
|
// performing scaled decodes on small images.
|
2017-12-08 15:21:31 +00:00
|
|
|
test_dimensions(r, "images/1x1.png");
|
|
|
|
test_dimensions(r, "images/2x2.png");
|
|
|
|
test_dimensions(r, "images/3x3.png");
|
|
|
|
test_dimensions(r, "images/3x1.png");
|
|
|
|
test_dimensions(r, "images/1x1.png");
|
|
|
|
test_dimensions(r, "images/16x1.png");
|
|
|
|
test_dimensions(r, "images/1x16.png");
|
|
|
|
test_dimensions(r, "images/mandrill_16.png");
|
2015-08-18 20:22:46 +00:00
|
|
|
|
2016-01-25 16:26:16 +00:00
|
|
|
// RAW
|
2016-02-29 15:14:42 +00:00
|
|
|
// Disable RAW tests for Win32.
|
|
|
|
#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
|
2017-12-08 15:21:31 +00:00
|
|
|
test_dimensions(r, "images/sample_1mp.dng");
|
|
|
|
test_dimensions(r, "images/sample_1mp_rotated.dng");
|
|
|
|
test_dimensions(r, "images/dng_with_preview.dng");
|
2016-01-25 21:10:58 +00:00
|
|
|
#endif
|
2015-04-15 14:32:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-12 15:08:56 +00:00
|
|
|
static void test_invalid(skiatest::Reporter* r, const char path[]) {
|
2018-02-13 21:41:03 +00:00
|
|
|
auto data = GetResourceAsData(path);
|
|
|
|
if (!data) {
|
2018-02-15 14:25:11 +00:00
|
|
|
ERRORF(r, "Failed to get resource %s", path);
|
2015-04-23 15:53:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-02-13 21:41:03 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(r, !SkCodec::MakeFromData(data));
|
2015-04-23 15:53:39 +00:00
|
|
|
}
|
2015-04-15 14:32:19 +00:00
|
|
|
|
2015-04-23 15:53:39 +00:00
|
|
|
DEF_TEST(Codec_Empty, r) {
|
2018-02-13 21:41:03 +00:00
|
|
|
if (GetResourcePath().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-04-23 15:53:39 +00:00
|
|
|
// Test images that should not be able to create a codec
|
2015-08-12 15:08:56 +00:00
|
|
|
test_invalid(r, "empty_images/zero-dims.gif");
|
|
|
|
test_invalid(r, "empty_images/zero-embedded.ico");
|
|
|
|
test_invalid(r, "empty_images/zero-width.bmp");
|
|
|
|
test_invalid(r, "empty_images/zero-height.bmp");
|
|
|
|
test_invalid(r, "empty_images/zero-width.jpg");
|
|
|
|
test_invalid(r, "empty_images/zero-height.jpg");
|
|
|
|
test_invalid(r, "empty_images/zero-width.png");
|
|
|
|
test_invalid(r, "empty_images/zero-height.png");
|
|
|
|
test_invalid(r, "empty_images/zero-width.wbmp");
|
|
|
|
test_invalid(r, "empty_images/zero-height.wbmp");
|
|
|
|
// This image is an ico with an embedded mask-bmp. This is illegal.
|
|
|
|
test_invalid(r, "invalid_images/mask-bmp-ico.ico");
|
2017-02-07 22:01:16 +00:00
|
|
|
// It is illegal for a webp frame to not be fully contained by the canvas.
|
|
|
|
test_invalid(r, "invalid_images/invalid-offset.webp");
|
2016-12-02 21:47:53 +00:00
|
|
|
#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
|
|
|
|
test_invalid(r, "empty_images/zero_height.tiff");
|
|
|
|
#endif
|
2017-07-14 15:48:52 +00:00
|
|
|
test_invalid(r, "invalid_images/b37623797.ico");
|
2018-02-13 21:41:03 +00:00
|
|
|
test_invalid(r, "invalid_images/osfuzz6295.webp");
|
2018-02-15 14:25:11 +00:00
|
|
|
test_invalid(r, "invalid_images/osfuzz6288.bmp");
|
2018-02-22 21:09:33 +00:00
|
|
|
test_invalid(r, "invalid_images/ossfuzz6347");
|
2015-04-23 15:53:39 +00:00
|
|
|
}
|
2015-08-05 19:58:26 +00:00
|
|
|
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
|
|
|
|
|
|
|
#ifndef SK_PNG_DISABLE_TESTS // reading chunks does not work properly with older versions.
|
|
|
|
// It does not appear that anyone in Google3 is reading chunks.
|
|
|
|
|
2015-11-23 16:14:40 +00:00
|
|
|
static void codex_test_write_fn(png_structp png_ptr, png_bytep data, png_size_t len) {
|
|
|
|
SkWStream* sk_stream = (SkWStream*)png_get_io_ptr(png_ptr);
|
|
|
|
if (!sk_stream->write(data, len)) {
|
|
|
|
png_error(png_ptr, "sk_write_fn Error!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec_pngChunkReader, r) {
|
|
|
|
// Create a dummy bitmap. Use unpremul RGBA for libpng.
|
|
|
|
SkBitmap bm;
|
|
|
|
const int w = 1;
|
|
|
|
const int h = 1;
|
|
|
|
const SkImageInfo bmInfo = SkImageInfo::Make(w, h, kRGBA_8888_SkColorType,
|
|
|
|
kUnpremul_SkAlphaType);
|
|
|
|
bm.setInfo(bmInfo);
|
|
|
|
bm.allocPixels();
|
|
|
|
bm.eraseColor(SK_ColorBLUE);
|
|
|
|
SkMD5::Digest goodDigest;
|
|
|
|
md5(bm, &goodDigest);
|
|
|
|
|
|
|
|
// Write to a png file.
|
|
|
|
png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
|
|
|
REPORTER_ASSERT(r, png);
|
|
|
|
if (!png) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
png_infop info = png_create_info_struct(png);
|
|
|
|
REPORTER_ASSERT(r, info);
|
|
|
|
if (!info) {
|
|
|
|
png_destroy_write_struct(&png, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setjmp(png_jmpbuf(png))) {
|
|
|
|
ERRORF(r, "failed writing png");
|
|
|
|
png_destroy_write_struct(&png, &info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkDynamicMemoryWStream wStream;
|
|
|
|
png_set_write_fn(png, (void*) (&wStream), codex_test_write_fn, nullptr);
|
|
|
|
|
|
|
|
png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
|
|
|
|
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
|
|
|
|
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
|
|
|
|
|
|
// Create some chunks that match the Android framework's use.
|
|
|
|
static png_unknown_chunk gUnknowns[] = {
|
2016-01-07 19:03:25 +00:00
|
|
|
{ "npOl", (png_byte*)"outline", sizeof("outline"), PNG_HAVE_IHDR },
|
|
|
|
{ "npLb", (png_byte*)"layoutBounds", sizeof("layoutBounds"), PNG_HAVE_IHDR },
|
|
|
|
{ "npTc", (png_byte*)"ninePatchData", sizeof("ninePatchData"), PNG_HAVE_IHDR },
|
2015-11-23 16:14:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
png_set_keep_unknown_chunks(png, PNG_HANDLE_CHUNK_ALWAYS, (png_byte*)"npOl\0npLb\0npTc\0", 3);
|
|
|
|
png_set_unknown_chunks(png, info, gUnknowns, SK_ARRAY_COUNT(gUnknowns));
|
|
|
|
#if PNG_LIBPNG_VER < 10600
|
|
|
|
/* Deal with unknown chunk location bug in 1.5.x and earlier */
|
2016-01-07 19:03:25 +00:00
|
|
|
png_set_unknown_chunk_location(png, info, 0, PNG_HAVE_IHDR);
|
|
|
|
png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_IHDR);
|
2015-11-23 16:14:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
png_write_info(png, info);
|
|
|
|
|
|
|
|
for (int j = 0; j < h; j++) {
|
|
|
|
png_bytep row = (png_bytep)(bm.getAddr(0, j));
|
|
|
|
png_write_rows(png, &row, 1);
|
|
|
|
}
|
|
|
|
png_write_end(png, info);
|
|
|
|
png_destroy_write_struct(&png, &info);
|
|
|
|
|
|
|
|
class ChunkReader : public SkPngChunkReader {
|
|
|
|
public:
|
|
|
|
ChunkReader(skiatest::Reporter* r)
|
|
|
|
: fReporter(r)
|
|
|
|
{
|
|
|
|
this->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool readChunk(const char tag[], const void* data, size_t length) override {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gUnknowns); ++i) {
|
|
|
|
if (!strcmp(tag, (const char*) gUnknowns[i].name)) {
|
|
|
|
// Tag matches. This should have been the first time we see it.
|
|
|
|
REPORTER_ASSERT(fReporter, !fSeen[i]);
|
|
|
|
fSeen[i] = true;
|
|
|
|
|
|
|
|
// Data and length should match
|
|
|
|
REPORTER_ASSERT(fReporter, length == gUnknowns[i].size);
|
|
|
|
REPORTER_ASSERT(fReporter, !strcmp((const char*) data,
|
|
|
|
(const char*) gUnknowns[i].data));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ERRORF(fReporter, "Saw an unexpected unknown chunk.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool allHaveBeenSeen() {
|
|
|
|
bool ret = true;
|
|
|
|
for (auto seen : fSeen) {
|
|
|
|
ret &= seen;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
sk_bzero(fSeen, sizeof(fSeen));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
skiatest::Reporter* fReporter; // Unowned
|
|
|
|
bool fSeen[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
ChunkReader chunkReader(r);
|
|
|
|
|
|
|
|
// Now read the file with SkCodec.
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(wStream.detachAsData(), &chunkReader));
|
2015-11-23 16:14:40 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
if (!codec) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now compare to the original.
|
|
|
|
SkBitmap decodedBm;
|
|
|
|
decodedBm.setInfo(codec->getInfo());
|
|
|
|
decodedBm.allocPixels();
|
|
|
|
SkCodec::Result result = codec->getPixels(codec->getInfo(), decodedBm.getPixels(),
|
|
|
|
decodedBm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
|
|
|
|
if (decodedBm.colorType() != bm.colorType()) {
|
|
|
|
SkBitmap tmp;
|
2017-04-28 15:15:22 +00:00
|
|
|
bool success = sk_tool_utils::copy_to(&tmp, bm.colorType(), decodedBm);
|
2015-11-23 16:14:40 +00:00
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp.swap(decodedBm);
|
|
|
|
}
|
|
|
|
|
|
|
|
compare_to_good_digest(r, goodDigest, decodedBm);
|
|
|
|
REPORTER_ASSERT(r, chunkReader.allHaveBeenSeen());
|
|
|
|
|
|
|
|
// Decoding again will read the chunks again.
|
|
|
|
chunkReader.reset();
|
|
|
|
REPORTER_ASSERT(r, !chunkReader.allHaveBeenSeen());
|
|
|
|
result = codec->getPixels(codec->getInfo(), decodedBm.getPixels(), decodedBm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
REPORTER_ASSERT(r, chunkReader.allHaveBeenSeen());
|
|
|
|
}
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
#endif // SK_PNG_DISABLE_TESTS
|
2015-11-23 16:14:40 +00:00
|
|
|
#endif // PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
2015-11-30 14:25:31 +00:00
|
|
|
|
2015-12-09 02:54:13 +00:00
|
|
|
// Stream that can only peek up to a limit
|
|
|
|
class LimitedPeekingMemStream : public SkStream {
|
|
|
|
public:
|
2016-09-12 19:01:44 +00:00
|
|
|
LimitedPeekingMemStream(sk_sp<SkData> data, size_t limit)
|
|
|
|
: fStream(std::move(data))
|
2015-12-09 02:54:13 +00:00
|
|
|
, fLimit(limit) {}
|
|
|
|
|
|
|
|
size_t peek(void* buf, size_t bytes) const override {
|
|
|
|
return fStream.peek(buf, SkTMin(bytes, fLimit));
|
|
|
|
}
|
|
|
|
size_t read(void* buf, size_t bytes) override {
|
|
|
|
return fStream.read(buf, bytes);
|
|
|
|
}
|
|
|
|
bool rewind() override {
|
|
|
|
return fStream.rewind();
|
|
|
|
}
|
|
|
|
bool isAtEnd() const override {
|
2016-09-07 18:23:28 +00:00
|
|
|
return fStream.isAtEnd();
|
2015-12-09 02:54:13 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMemoryStream fStream;
|
|
|
|
const size_t fLimit;
|
|
|
|
};
|
|
|
|
|
2016-02-29 15:14:42 +00:00
|
|
|
// Disable RAW tests for Win32.
|
|
|
|
#if defined(SK_CODEC_DECODES_RAW) && (!defined(_WIN32))
|
2016-02-05 16:21:19 +00:00
|
|
|
// Test that the RawCodec works also for not asset stream. This will test the code path using
|
|
|
|
// SkRawBufferedStream instead of SkRawAssetStream.
|
|
|
|
DEF_TEST(Codec_raw_notseekable, r) {
|
2017-12-09 01:27:41 +00:00
|
|
|
constexpr char path[] = "images/dng_with_preview.dng";
|
|
|
|
sk_sp<SkData> data(GetResourceAsData(path));
|
2016-02-05 16:21:19 +00:00
|
|
|
if (!data) {
|
|
|
|
SkDebugf("Missing resource '%s'\n", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
|
|
|
|
skstd::make_unique<NotAssetMemStream>(std::move(data))));
|
2016-02-05 16:21:19 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
|
|
|
|
test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-09 02:54:13 +00:00
|
|
|
// Test that even if webp_parse_header fails to peek enough, it will fall back to read()
|
|
|
|
// + rewind() and succeed.
|
|
|
|
DEF_TEST(Codec_webp_peek, r) {
|
2017-12-09 01:27:41 +00:00
|
|
|
constexpr char path[] = "images/baby_tux.webp";
|
|
|
|
auto data = GetResourceAsData(path);
|
2015-12-09 02:54:13 +00:00
|
|
|
if (!data) {
|
|
|
|
SkDebugf("Missing resource '%s'\n", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The limit is less than webp needs to peek or read.
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(
|
|
|
|
skstd::make_unique<LimitedPeekingMemStream>(data, 25)));
|
2015-12-09 02:54:13 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
|
2016-02-04 14:14:24 +00:00
|
|
|
test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
|
2015-12-09 02:54:13 +00:00
|
|
|
|
|
|
|
// Similarly, a stream which does not peek should still succeed.
|
2017-07-23 19:30:02 +00:00
|
|
|
codec = SkCodec::MakeFromStream(skstd::make_unique<LimitedPeekingMemStream>(data, 0));
|
2015-12-09 02:54:13 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
|
2016-02-04 14:14:24 +00:00
|
|
|
test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
|
2015-12-09 02:54:13 +00:00
|
|
|
}
|
|
|
|
|
2016-03-01 20:12:27 +00:00
|
|
|
// SkCodec's wbmp decoder was initially unnecessarily restrictive.
|
|
|
|
// It required the second byte to be zero. The wbmp specification allows
|
|
|
|
// a couple of bits to be 1 (so long as they do not overlap with 0x9F).
|
|
|
|
// Test that SkCodec now supports an image with these bits set.
|
2016-12-06 15:58:02 +00:00
|
|
|
DEF_TEST(Codec_wbmp_restrictive, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
const char* path = "images/mandrill.wbmp";
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
2015-11-30 14:25:31 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Modify the stream to contain a second byte with some bits set.
|
2016-11-03 18:40:50 +00:00
|
|
|
auto data = SkCopyStreamToData(stream.get());
|
2015-11-30 14:25:31 +00:00
|
|
|
uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data());
|
|
|
|
writeableData[1] = static_cast<uint8_t>(~0x9F);
|
|
|
|
|
2016-03-01 20:12:27 +00:00
|
|
|
// SkCodec should support this.
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
|
2015-11-30 14:25:31 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
if (!codec) {
|
|
|
|
return;
|
|
|
|
}
|
2016-02-04 14:14:24 +00:00
|
|
|
test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
|
2015-11-30 14:25:31 +00:00
|
|
|
}
|
2015-12-09 02:54:13 +00:00
|
|
|
|
|
|
|
// wbmp images have a header that can be arbitrarily large, depending on the
|
|
|
|
// size of the image. We cap the size at 65535, meaning we only need to look at
|
|
|
|
// 8 bytes to determine whether we can read the image. This is important
|
2017-08-17 19:13:20 +00:00
|
|
|
// because SkCodec only passes a limited number of bytes to SkWbmpCodec to
|
|
|
|
// determine whether the image is a wbmp.
|
2015-12-09 02:54:13 +00:00
|
|
|
DEF_TEST(Codec_wbmp_max_size, r) {
|
|
|
|
const unsigned char maxSizeWbmp[] = { 0x00, 0x00, // Header
|
|
|
|
0x83, 0xFF, 0x7F, // W: 65535
|
|
|
|
0x83, 0xFF, 0x7F }; // H: 65535
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(new SkMemoryStream(maxSizeWbmp, sizeof(maxSizeWbmp), false));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2015-12-09 02:54:13 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
if (!codec) return;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, codec->getInfo().width() == 65535);
|
|
|
|
REPORTER_ASSERT(r, codec->getInfo().height() == 65535);
|
|
|
|
|
|
|
|
// Now test an image which is too big. Any image with a larger header (i.e.
|
|
|
|
// has bigger width/height) is also too big.
|
|
|
|
const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
|
|
|
|
0x84, 0x80, 0x00, // W: 65536
|
|
|
|
0x84, 0x80, 0x00 }; // H: 65536
|
|
|
|
stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
|
2017-07-23 19:30:02 +00:00
|
|
|
codec = SkCodec::MakeFromStream(std::move(stream));
|
2015-12-09 02:54:13 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(r, !codec);
|
|
|
|
}
|
2016-07-18 22:56:08 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_jpeg_rewind, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
const char* path = "images/mandrill_512_q075.jpg";
|
2017-01-27 18:16:28 +00:00
|
|
|
sk_sp<SkData> data(GetResourceAsData(path));
|
|
|
|
if (!data) {
|
2016-07-18 22:56:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-27 18:16:28 +00:00
|
|
|
|
|
|
|
data = SkData::MakeSubset(data.get(), 0, data->size() / 2);
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(data));
|
2016-07-18 22:56:08 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Unable to create codec '%s'.", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int width = codec->getInfo().width();
|
|
|
|
const int height = codec->getInfo().height();
|
|
|
|
size_t rowBytes = sizeof(SkPMColor) * width;
|
|
|
|
SkAutoMalloc pixelStorage(height * rowBytes);
|
|
|
|
|
|
|
|
// Perform a sampled decode.
|
|
|
|
SkAndroidCodec::AndroidOptions opts;
|
|
|
|
opts.fSampleSize = 12;
|
2017-01-27 18:16:28 +00:00
|
|
|
auto sampledInfo = codec->getInfo().makeWH(width / 12, height / 12);
|
|
|
|
auto result = codec->getAndroidPixels(sampledInfo, pixelStorage.get(), rowBytes, &opts);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kIncompleteInput == result);
|
2016-07-18 22:56:08 +00:00
|
|
|
|
|
|
|
// Rewind the codec and perform a full image decode.
|
2017-01-25 16:58:11 +00:00
|
|
|
result = codec->getPixels(codec->getInfo(), pixelStorage.get(), rowBytes);
|
2017-01-27 18:16:28 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kIncompleteInput == result);
|
2017-01-25 16:58:11 +00:00
|
|
|
|
|
|
|
// Now perform a subset decode.
|
|
|
|
{
|
|
|
|
opts.fSampleSize = 1;
|
|
|
|
SkIRect subset = SkIRect::MakeWH(100, 100);
|
|
|
|
opts.fSubset = ⊂
|
|
|
|
result = codec->getAndroidPixels(codec->getInfo().makeWH(100, 100), pixelStorage.get(),
|
|
|
|
rowBytes, &opts);
|
2017-01-27 18:16:28 +00:00
|
|
|
// Though we only have half the data, it is enough to decode this subset.
|
2017-01-25 16:58:11 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Perform another full image decode. ASAN will detect if we look at the subset when it is
|
|
|
|
// out of scope. This would happen if we depend on the old state in the codec.
|
2017-01-27 18:16:28 +00:00
|
|
|
// This tests two layers of bugs: both SkJpegCodec::readRows and SkCodec::fillIncompleteImage
|
|
|
|
// used to look at the old subset.
|
2017-01-25 16:58:11 +00:00
|
|
|
opts.fSubset = nullptr;
|
|
|
|
result = codec->getAndroidPixels(codec->getInfo(), pixelStorage.get(), rowBytes, &opts);
|
2017-01-27 18:16:28 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kIncompleteInput == result);
|
2016-07-18 22:56:08 +00:00
|
|
|
}
|
2016-08-17 15:54:08 +00:00
|
|
|
|
2016-08-22 14:41:28 +00:00
|
|
|
static void check_color_xform(skiatest::Reporter* r, const char* path) {
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(GetResourceAsStream(path)));
|
2016-08-22 14:41:28 +00:00
|
|
|
|
|
|
|
SkAndroidCodec::AndroidOptions opts;
|
|
|
|
opts.fSampleSize = 3;
|
|
|
|
const int subsetWidth = codec->getInfo().width() / 2;
|
|
|
|
const int subsetHeight = codec->getInfo().height() / 2;
|
|
|
|
SkIRect subset = SkIRect::MakeWH(subsetWidth, subsetHeight);
|
|
|
|
opts.fSubset = ⊂
|
|
|
|
|
|
|
|
const int dstWidth = subsetWidth / opts.fSampleSize;
|
|
|
|
const int dstHeight = subsetHeight / opts.fSampleSize;
|
2018-05-23 17:12:18 +00:00
|
|
|
auto colorSpace = SkColorSpace::MakeRGB(g2Dot2_TransferFn, SkColorSpace::kAdobeRGB_Gamut);
|
2016-08-22 14:41:28 +00:00
|
|
|
SkImageInfo dstInfo = codec->getInfo().makeWH(dstWidth, dstHeight)
|
|
|
|
.makeColorType(kN32_SkColorType)
|
|
|
|
.makeColorSpace(colorSpace);
|
|
|
|
|
|
|
|
size_t rowBytes = dstInfo.minRowBytes();
|
2017-10-03 18:47:21 +00:00
|
|
|
SkAutoMalloc pixelStorage(dstInfo.computeByteSize(rowBytes));
|
2016-08-22 14:41:28 +00:00
|
|
|
SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get(), rowBytes, &opts);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec_ColorXform, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
check_color_xform(r, "images/mandrill_512_q075.jpg");
|
|
|
|
check_color_xform(r, "images/mandrill_512.png");
|
2016-08-22 14:41:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-12 21:30:03 +00:00
|
|
|
static bool color_type_match(SkColorType origColorType, SkColorType codecColorType) {
|
|
|
|
switch (origColorType) {
|
|
|
|
case kRGBA_8888_SkColorType:
|
|
|
|
case kBGRA_8888_SkColorType:
|
|
|
|
return kRGBA_8888_SkColorType == codecColorType ||
|
|
|
|
kBGRA_8888_SkColorType == codecColorType;
|
|
|
|
default:
|
|
|
|
return origColorType == codecColorType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool alpha_type_match(SkAlphaType origAlphaType, SkAlphaType codecAlphaType) {
|
|
|
|
switch (origAlphaType) {
|
|
|
|
case kUnpremul_SkAlphaType:
|
|
|
|
case kPremul_SkAlphaType:
|
|
|
|
return kUnpremul_SkAlphaType == codecAlphaType ||
|
|
|
|
kPremul_SkAlphaType == codecAlphaType;
|
|
|
|
default:
|
|
|
|
return origAlphaType == codecAlphaType;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_round_trip(skiatest::Reporter* r, SkCodec* origCodec, const SkImageInfo& info) {
|
|
|
|
SkBitmap bm1;
|
2017-07-11 17:35:31 +00:00
|
|
|
bm1.allocPixels(info);
|
|
|
|
SkCodec::Result result = origCodec->getPixels(info, bm1.getPixels(), bm1.rowBytes());
|
2016-09-12 21:30:03 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
2016-08-17 15:54:08 +00:00
|
|
|
|
|
|
|
// Encode the image to png.
|
|
|
|
sk_sp<SkData> data =
|
2016-11-23 15:55:18 +00:00
|
|
|
sk_sp<SkData>(sk_tool_utils::EncodeImageToData(bm1, SkEncodedImageFormat::kPNG, 100));
|
2016-08-17 15:54:08 +00:00
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(data));
|
2016-09-12 21:30:03 +00:00
|
|
|
REPORTER_ASSERT(r, color_type_match(info.colorType(), codec->getInfo().colorType()));
|
|
|
|
REPORTER_ASSERT(r, alpha_type_match(info.alphaType(), codec->getInfo().alphaType()));
|
2016-08-17 15:54:08 +00:00
|
|
|
|
|
|
|
SkBitmap bm2;
|
2017-07-11 17:35:31 +00:00
|
|
|
bm2.allocPixels(info);
|
|
|
|
result = codec->getPixels(info, bm2.getPixels(), bm2.rowBytes());
|
2016-08-17 15:54:08 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
|
|
|
|
SkMD5::Digest d1, d2;
|
|
|
|
md5(bm1, &d1);
|
|
|
|
md5(bm2, &d2);
|
|
|
|
REPORTER_ASSERT(r, d1 == d2);
|
|
|
|
}
|
2016-08-29 21:47:49 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_PngRoundTrip, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
auto codec = SkCodec::MakeFromStream(GetResourceAsStream("images/mandrill_512_q075.jpg"));
|
2016-08-29 21:47:49 +00:00
|
|
|
|
2016-09-12 21:30:03 +00:00
|
|
|
SkColorType colorTypesOpaque[] = {
|
|
|
|
kRGB_565_SkColorType, kRGBA_8888_SkColorType, kBGRA_8888_SkColorType
|
|
|
|
};
|
|
|
|
for (SkColorType colorType : colorTypesOpaque) {
|
|
|
|
SkImageInfo newInfo = codec->getInfo().makeColorType(colorType);
|
|
|
|
check_round_trip(r, codec.get(), newInfo);
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
codec = SkCodec::MakeFromStream(GetResourceAsStream("images/grayscale.jpg"));
|
2016-09-12 21:30:03 +00:00
|
|
|
check_round_trip(r, codec.get(), codec->getInfo());
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
codec = SkCodec::MakeFromStream(GetResourceAsStream("images/yellow_rose.png"));
|
2016-09-12 21:30:03 +00:00
|
|
|
|
|
|
|
SkColorType colorTypesWithAlpha[] = {
|
|
|
|
kRGBA_8888_SkColorType, kBGRA_8888_SkColorType
|
|
|
|
};
|
|
|
|
SkAlphaType alphaTypes[] = {
|
|
|
|
kUnpremul_SkAlphaType, kPremul_SkAlphaType
|
|
|
|
};
|
|
|
|
for (SkColorType colorType : colorTypesWithAlpha) {
|
|
|
|
for (SkAlphaType alphaType : alphaTypes) {
|
|
|
|
// Set color space to nullptr because color correct premultiplies do not round trip.
|
|
|
|
SkImageInfo newInfo = codec->getInfo().makeColorType(colorType)
|
|
|
|
.makeAlphaType(alphaType)
|
|
|
|
.makeColorSpace(nullptr);
|
|
|
|
check_round_trip(r, codec.get(), newInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 15:21:31 +00:00
|
|
|
codec = SkCodec::MakeFromStream(GetResourceAsStream("images/index8.png"));
|
2016-09-12 21:30:03 +00:00
|
|
|
|
|
|
|
for (SkAlphaType alphaType : alphaTypes) {
|
|
|
|
SkImageInfo newInfo = codec->getInfo().makeAlphaType(alphaType)
|
|
|
|
.makeColorSpace(nullptr);
|
|
|
|
check_round_trip(r, codec.get(), newInfo);
|
|
|
|
}
|
2016-08-29 21:47:49 +00:00
|
|
|
}
|
2016-09-08 18:55:16 +00:00
|
|
|
|
|
|
|
static void test_conversion_possible(skiatest::Reporter* r, const char* path,
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
bool supportsScanlineDecoder,
|
|
|
|
bool supportsIncrementalDecoder) {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(path));
|
2017-01-30 14:59:28 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2017-01-30 14:59:28 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "failed to create a codec for %s", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-08 18:55:16 +00:00
|
|
|
SkImageInfo infoF16 = codec->getInfo().makeColorType(kRGBA_F16_SkColorType);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(infoF16);
|
|
|
|
SkCodec::Result result = codec->getPixels(infoF16, bm.getPixels(), bm.rowBytes());
|
2018-05-10 15:29:15 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
|
|
|
|
result = codec->startScanlineDecode(infoF16);
|
|
|
|
if (supportsScanlineDecoder) {
|
2018-05-10 15:29:15 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
} else {
|
2017-08-15 16:24:02 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result
|
2018-05-10 15:29:15 +00:00
|
|
|
|| SkCodec::kSuccess == result);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
result = codec->startIncrementalDecode(infoF16, bm.getPixels(), bm.rowBytes());
|
|
|
|
if (supportsIncrementalDecoder) {
|
2018-05-10 15:29:15 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
} else {
|
2017-08-15 16:24:02 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result
|
2018-05-10 15:29:15 +00:00
|
|
|
|| SkCodec::kSuccess == result);
|
2016-09-08 18:55:16 +00:00
|
|
|
}
|
|
|
|
|
2017-12-12 19:09:31 +00:00
|
|
|
infoF16 = infoF16.makeColorSpace(infoF16.colorSpace()->makeLinearGamma());
|
2016-09-08 18:55:16 +00:00
|
|
|
result = codec->getPixels(infoF16, bm.getPixels(), bm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
result = codec->startScanlineDecode(infoF16);
|
|
|
|
if (supportsScanlineDecoder) {
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = codec->startIncrementalDecode(infoF16, bm.getPixels(), bm.rowBytes());
|
|
|
|
if (supportsIncrementalDecoder) {
|
2016-09-08 18:55:16 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result);
|
2016-09-08 18:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec_F16ConversionPossible, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
test_conversion_possible(r, "images/color_wheel.webp", false, false);
|
|
|
|
test_conversion_possible(r, "images/mandrill_512_q075.jpg", true, false);
|
|
|
|
test_conversion_possible(r, "images/yellow_rose.png", false, true);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
}
|
|
|
|
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
static void decode_frame(skiatest::Reporter* r, SkCodec* codec, size_t frame) {
|
|
|
|
SkBitmap bm;
|
|
|
|
auto info = codec->getInfo().makeColorType(kN32_SkColorType);
|
|
|
|
bm.allocPixels(info);
|
|
|
|
|
|
|
|
SkCodec::Options opts;
|
|
|
|
opts.fFrameIndex = frame;
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == codec->getPixels(info,
|
2017-07-11 17:35:31 +00:00
|
|
|
bm.getPixels(), bm.rowBytes(), &opts));
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-12 20:41:09 +00:00
|
|
|
// For an animated GIF, we should only read enough to decode frame 0 if the
|
|
|
|
// client never calls getFrameInfo and only decodes frame 0.
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
DEF_TEST(Codec_skipFullParse, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
auto path = "images/test640x479.gif";
|
2017-07-23 17:14:10 +00:00
|
|
|
auto streamObj = GetResourceAsStream(path);
|
|
|
|
if (!streamObj) {
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-23 17:14:10 +00:00
|
|
|
SkStream* stream = streamObj.get();
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
|
|
|
|
// Note that we cheat and hold on to the stream pointer, but SkCodec will
|
|
|
|
// take ownership. We will not refer to the stream after the SkCodec
|
|
|
|
// deletes it.
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(streamObj)));
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Failed to create codec for %s", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, stream->hasPosition());
|
|
|
|
const size_t sizePosition = stream->getPosition();
|
|
|
|
REPORTER_ASSERT(r, stream->hasLength() && sizePosition < stream->getLength());
|
|
|
|
|
|
|
|
// This should read more of the stream, but not the whole stream.
|
|
|
|
decode_frame(r, codec.get(), 0);
|
|
|
|
const size_t positionAfterFirstFrame = stream->getPosition();
|
|
|
|
REPORTER_ASSERT(r, positionAfterFirstFrame > sizePosition
|
|
|
|
&& positionAfterFirstFrame < stream->getLength());
|
|
|
|
|
2017-06-12 20:41:09 +00:00
|
|
|
// There is more data in the stream.
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
auto frameInfo = codec->getFrameInfo();
|
|
|
|
REPORTER_ASSERT(r, frameInfo.size() == 4);
|
2017-06-12 20:41:09 +00:00
|
|
|
REPORTER_ASSERT(r, stream->getPosition() > positionAfterFirstFrame);
|
Add support for multiple frames in SkCodec
Add an interface to decode frames beyond the first in SkCodec, and
add an implementation for SkGifCodec.
Add getFrameData to SkCodec. This method reads ahead in the stream
to return a vector containing meta data about each frame in the image.
This is not required in order to decode frames beyond the first, but
it allows a client to learn extra information:
- how long the frame should be displayed
- whether a frame should be blended with a prior frame, allowing the
client to provide the prior frame to speed up decoding
Add a new fields to SkCodec::Options:
- fFrameIndex
- fHasPriorFrame
The API is designed so that SkCodec never caches frames. If a
client wants a frame beyond the first, they specify the frame in
Options.fFrameIndex. If the client does not have the
frame's required frame (the frame that this frame must be blended on
top of) cached, they pass false for
Options.fHasPriorFrame. Unless the frame is
independent, the codec will then recursively decode all frames
necessary to decode fFrameIndex. If the client has the required frame
cached, they can put it in the dst they pass to the codec, and the
codec will only draw fFrameIndex onto it.
Replace SkGifCodec's scanline decoding support with progressive
decoding, and update the tests accordingly.
Implement new APIs in SkGifCodec. Instead of using gif_lib, use
GIFImageReader, imported from Chromium (along with its copyright
headers) with the following changes:
- SkGifCodec is now the client
- Replace blink types
- Combine GIFColorMap::buildTable and ::getTable into a method that
creates and returns an SkColorTable
- Input comes from an SkStream, instead of a SegmentReader. Add
SkStreamBuffer, which buffers the (potentially partial) stream in
order to decode progressively.
(FIXME: This requires copying data that previously was read directly
from the SegmentReader. Does this hurt performance? If so, can we
fix it?)
- Remove UMA code
- Instead of reporting screen width and height to the client, allow the
client to query for it
- Fail earlier if the first frame AND screen have size of zero
- Compute required previous frame when adding a new one
- Move GIFParseQuery from GIFImageDecoder to GIFImageReader
- Allow parsing up to a specific frame (to skip parsing the rest of the
stream if a client only wants the first frame)
- Compute whether the first frame has alpha and supports index 8, to
create the SkImageInfo. This happens before reporting that the size
has been decoded.
Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from
Chromium (along with its copyright header), with the following changes:
- Add support for sampling
- Use the swizzler
- Keep track of the rows decoded
- Do *not* keep track of whether we've seen alpha
Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF
scanline decoding.
Call onRewind even if there is no stream (SkGifCodec needs to clear its
decoded state so it will decode from the beginning).
Add a method to SkSwizzler to access the offset into the dst, taking
subsetting into account.
Add a GM that animates a GIF.
Add tests for the new APIs.
*** Behavior changes:
* Previously, we reported that an image with a subset frame and no transparent
index was opaque and used the background index (if present) to fill the
background. This is necessary in order to support index 8, but it does not
match viewers/browsers I have seen. Examples:
- Chromium and Gimp render the background transparent
- Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for
a single frame image)
This CL matches Chromium's behavior and renders the background transparent.
This allows us to have consistent behavior across products and simplifies
the code (relative to what we would have to do to continue the old behavior
on Android). It also means that we will no longer support index 8 for some
GIFs.
* Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a.
This matches Chromium. I suspect that bugs would have been reported if valid
GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode
in Chromium).
*** Future work not included in this CL:
* Move some checks out of haveDecodedRow, since they are the same for the
entire frame e.g.
- intersecting the frameRect with the full image size
- whether there is a color table
* Change when we write transparent pixels
- In some cases, Chromium deemed this unnecessary, but I suspect it is slower
than the fallback case. There will continue to be cases where we should
*not* write them, but for e.g. the first pass where we have already
cleared to transparent (which we may also be able to skip) writing the
transparent pixels will not make anything incorrect.
* Report color type and alpha type per frame
- Depending on alpha values, disposal methods, frame rects, etc, subsequent
frames may have different properties than the first.
* Skip copies of the encoded data
- We copy the encoded data in case the stream is one that cannot be rewound,
so we can parse and then decode (possibly not immediately). For some input
streams, this is unnecessary.
- I was concerned this cause a performance regression, but on average the
new code is faster than the old for the images I tested [1].
- It may cause a performance regression for Chromium, though, where we can
always move back in the stream, so this should be addressed.
Design doc:
https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/
[1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002
Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
|
|
|
}
|
|
|
|
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
// Only rewinds up to a limit.
|
|
|
|
class LimitedRewindingStream : public SkStream {
|
|
|
|
public:
|
2017-07-23 17:14:10 +00:00
|
|
|
static std::unique_ptr<SkStream> Make(const char path[], size_t limit) {
|
|
|
|
auto stream = GetResourceAsStream(path);
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!stream) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-07-23 17:14:10 +00:00
|
|
|
return std::unique_ptr<SkStream>(new LimitedRewindingStream(std::move(stream), limit));
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t read(void* buffer, size_t size) override {
|
|
|
|
const size_t bytes = fStream->read(buffer, size);
|
|
|
|
fPosition += bytes;
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isAtEnd() const override {
|
|
|
|
return fStream->isAtEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rewind() override {
|
|
|
|
if (fPosition <= fLimit && fStream->rewind()) {
|
|
|
|
fPosition = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkStream> fStream;
|
|
|
|
const size_t fLimit;
|
|
|
|
size_t fPosition;
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
|
2017-07-23 17:14:10 +00:00
|
|
|
LimitedRewindingStream(std::unique_ptr<SkStream> stream, size_t limit)
|
|
|
|
: fStream(std::move(stream))
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
, fLimit(limit)
|
|
|
|
, fPosition(0)
|
|
|
|
{
|
|
|
|
SkASSERT(fStream);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_TEST(Codec_fallBack, r) {
|
|
|
|
// SkAndroidCodec needs to be able to fall back to scanline decoding
|
|
|
|
// if incremental decoding does not work. Make sure this does not
|
|
|
|
// require a rewind.
|
|
|
|
|
|
|
|
// Formats that currently do not support incremental decoding
|
|
|
|
auto files = {
|
2017-12-08 15:21:31 +00:00
|
|
|
"images/CMYK.jpg",
|
|
|
|
"images/color_wheel.ico",
|
|
|
|
"images/mandrill.wbmp",
|
|
|
|
"images/randPixels.bmp",
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
};
|
|
|
|
for (auto file : files) {
|
2017-08-17 19:13:20 +00:00
|
|
|
auto stream = LimitedRewindingStream::Make(file, SkCodec::MinBufferedBytesNeeded());
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!stream) {
|
|
|
|
SkDebugf("Missing resources (%s). Set --resourcePath.\n", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
Make SkPngCodec decode progressively.
This is a step towards using SkCodec in Chromium, where progressive
decoding is necessary.
Switch from using png_read_row (which expects all the data to be
available) to png_process_data, which uses callbacks when rows are
available.
Create a new API for SkCodec, which supports progressive decoding and
scanline decoding. Future changes will switch the other clients off of
startScanlineDecode and get/skip-Scanlines to the new API.
Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced
PNG images. In the new API, interlaced PNG fits kTopDown. Also remove
updateCurrScanline(), which was only used by the old implementation for
interlaced PNG.
DMSrcSink:
- In CodecSrc::kScanline_Mode, use the new method for scanline decoding
for the supported formats (just PNG and PNG-in-ICO for now).
fuzz.cpp:
- Remove reference to kNone_ScanlineOrder
SkCodec:
- Add new APIs:
- startIncrementalDecode
- incrementalDecode
- Remove kNone_SkScanlineOrder and updateCurrScanline()
- Set fDstInfo and fOptions in getPixels(). This may not be necessary
for all implementations, but it simplifies things for SkPngCodec.
SkPngCodec:
- Implement new APIs
- Switch from sk_read_fn/png_read_row etc to png_process_data
- Expand AutoCleanPng's role to decode the header and create the
SkPngCodec
- Make the interlaced PNG decoder report how many lines were
initialized during an incomplete decode
SkIcoCodec:
- Implement the new APIs; supported for PNG in ICO
SkSampledCodec:
- Call the new method for decoding scanlines, and fall back to the old
method if the new version is unimplemented
- Remove references to kNone_SkScanlineOrder
tests/CodecPartial:
- Add a test which decodes part of an image, then finishes the decode,
and compares it to the straightforward method
tests/CodecTest:
- Add a test which decodes all scanlines using the new method
- Repurpose the Codec_stripes test to decode using the new method in
sections rather than all at once
- In the method check(), add a parameter for whether the image supports
the new method of scanline decoding, and be explicit about whether an
image supports incomplete
- Test incomplete PNG decodes. We should have been doing it anyway for
non-interlaced (except for an image that is too small - one row), but
the new method supports interlaced incomplete as well
- Make test_invalid_parameters test the new method
- Add a test to ensure that it's safe to fall back to scanline decoding without
rewinding
BUG=skia:4211
The new version was generally faster than the old version (but not significantly so).
Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/
Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003
Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Failed to create codec for %s,", file);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType);
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
|
|
|
|
if (SkCodec::kUnimplemented != codec->startIncrementalDecode(info, bm.getPixels(),
|
|
|
|
bm.rowBytes())) {
|
|
|
|
ERRORF(r, "Is scanline decoding now implemented for %s?", file);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scanline decoding should not require a rewind.
|
|
|
|
SkCodec::Result result = codec->startScanlineDecode(info);
|
|
|
|
if (SkCodec::kSuccess != result) {
|
|
|
|
ERRORF(r, "Scanline decoding failed for %s with %i", file, result);
|
|
|
|
}
|
|
|
|
}
|
2016-09-08 18:55:16 +00:00
|
|
|
}
|
2016-10-10 13:45:32 +00:00
|
|
|
|
|
|
|
// This test verifies that we fixed an assert statement that fired when reusing a png codec
|
|
|
|
// after scaling.
|
|
|
|
DEF_TEST(Codec_reusePng, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream("images/plane.png"));
|
2016-10-10 13:45:32 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromStream(std::move(stream)));
|
2016-10-10 13:45:32 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Failed to create codec\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAndroidCodec::AndroidOptions opts;
|
|
|
|
opts.fSampleSize = 5;
|
|
|
|
auto size = codec->getSampledDimensions(opts.fSampleSize);
|
|
|
|
auto info = codec->getInfo().makeWH(size.fWidth, size.fHeight).makeColorType(kN32_SkColorType);
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
auto result = codec->getAndroidPixels(info, bm.getPixels(), bm.rowBytes(), &opts);
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
|
|
|
|
|
|
|
|
info = codec->getInfo().makeColorType(kN32_SkColorType);
|
|
|
|
bm.allocPixels(info);
|
|
|
|
opts.fSampleSize = 1;
|
|
|
|
result = codec->getAndroidPixels(info, bm.getPixels(), bm.rowBytes(), &opts);
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
|
|
|
|
}
|
2016-10-10 14:17:32 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_rowsDecoded, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
auto file = "images/plane_interlaced.png";
|
2016-10-10 14:17:32 +00:00
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(file));
|
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is enough to read the header etc, but no rows.
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(SkData::MakeFromStream(stream.get(), 99)));
|
2016-10-10 14:17:32 +00:00
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Failed to create codec\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto info = codec->getInfo().makeColorType(kN32_SkColorType);
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
auto result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kSuccess);
|
|
|
|
|
|
|
|
// This is an arbitrary value. The important fact is that it is not zero, and rowsDecoded
|
|
|
|
// should get set to zero by incrementalDecode.
|
|
|
|
int rowsDecoded = 77;
|
|
|
|
result = codec->incrementalDecode(&rowsDecoded);
|
|
|
|
REPORTER_ASSERT(r, result == SkCodec::kIncompleteInput);
|
|
|
|
REPORTER_ASSERT(r, rowsDecoded == 0);
|
|
|
|
}
|
2016-10-17 18:32:46 +00:00
|
|
|
|
2017-04-26 14:59:48 +00:00
|
|
|
static void test_invalid_images(skiatest::Reporter* r, const char* path,
|
|
|
|
SkCodec::Result expectedResult) {
|
2017-07-23 17:14:10 +00:00
|
|
|
auto stream = GetResourceAsStream(path);
|
2017-04-26 14:59:48 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2017-04-26 14:59:48 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
|
|
|
|
test_info(r, codec.get(), codec->getInfo().makeColorType(kN32_SkColorType), expectedResult,
|
|
|
|
nullptr);
|
2016-10-25 18:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec_InvalidImages, r) {
|
|
|
|
// ASAN will complain if there is an issue.
|
2017-07-06 16:26:09 +00:00
|
|
|
test_invalid_images(r, "invalid_images/skbug5887.gif", SkCodec::kErrorInInput);
|
2017-04-26 14:59:48 +00:00
|
|
|
test_invalid_images(r, "invalid_images/many-progressive-scans.jpg", SkCodec::kInvalidInput);
|
|
|
|
test_invalid_images(r, "invalid_images/b33251605.bmp", SkCodec::kIncompleteInput);
|
|
|
|
test_invalid_images(r, "invalid_images/bad_palette.png", SkCodec::kInvalidInput);
|
2016-10-17 18:32:46 +00:00
|
|
|
}
|
2016-12-12 22:10:46 +00:00
|
|
|
|
2017-04-26 14:59:48 +00:00
|
|
|
static void test_invalid_header(skiatest::Reporter* r, const char* path) {
|
2017-12-09 01:27:41 +00:00
|
|
|
auto data = GetResourceAsData(path);
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
std::unique_ptr<SkStreamAsset> stream(new SkMemoryStream(std::move(data)));
|
2017-07-26 15:35:53 +00:00
|
|
|
if (!stream) {
|
2017-01-18 17:39:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2017-04-26 14:59:48 +00:00
|
|
|
REPORTER_ASSERT(r, !codec);
|
|
|
|
}
|
2017-01-18 17:39:07 +00:00
|
|
|
|
2017-04-26 14:59:48 +00:00
|
|
|
DEF_TEST(Codec_InvalidHeader, r) {
|
|
|
|
test_invalid_header(r, "invalid_images/int_overflow.ico");
|
|
|
|
|
|
|
|
// These files report values that have caused problems with SkFILEStreams.
|
|
|
|
// They are invalid, and should not create SkCodecs.
|
|
|
|
test_invalid_header(r, "invalid_images/b33651913.bmp");
|
|
|
|
test_invalid_header(r, "invalid_images/b34778578.bmp");
|
2017-01-18 17:39:07 +00:00
|
|
|
}
|
|
|
|
|
2016-12-12 22:10:46 +00:00
|
|
|
DEF_TEST(Codec_InvalidAnimated, r) {
|
|
|
|
// ASAN will complain if there is an issue.
|
|
|
|
auto path = "invalid_images/skbug6046.gif";
|
2017-07-23 17:14:10 +00:00
|
|
|
auto stream = GetResourceAsStream(path);
|
2016-12-12 22:10:46 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromStream(std::move(stream)));
|
2016-12-12 22:10:46 +00:00
|
|
|
REPORTER_ASSERT(r, codec);
|
|
|
|
if (!codec) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto info = codec->getInfo().makeColorType(kN32_SkColorType);
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
|
|
|
|
auto frameInfos = codec->getFrameInfo();
|
|
|
|
SkCodec::Options opts;
|
2017-04-17 16:46:33 +00:00
|
|
|
for (int i = 0; static_cast<size_t>(i) < frameInfos.size(); i++) {
|
2016-12-12 22:10:46 +00:00
|
|
|
opts.fFrameIndex = i;
|
2017-06-07 16:31:51 +00:00
|
|
|
const auto reqFrame = frameInfos[i].fRequiredFrame;
|
|
|
|
opts.fPriorFrame = reqFrame == i - 1 ? reqFrame : SkCodec::kNone;
|
2016-12-12 22:10:46 +00:00
|
|
|
auto result = codec->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes(), &opts);
|
|
|
|
if (result != SkCodec::kSuccess) {
|
|
|
|
ERRORF(r, "Failed to start decoding frame %i (out of %i) with error %i\n", i,
|
|
|
|
frameInfos.size(), result);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
codec->incrementalDecode();
|
|
|
|
}
|
|
|
|
}
|
2017-03-15 21:50:08 +00:00
|
|
|
|
2017-03-22 21:52:47 +00:00
|
|
|
static void encode_format(SkDynamicMemoryWStream* stream, const SkPixmap& pixmap,
|
2017-05-05 15:13:26 +00:00
|
|
|
SkEncodedImageFormat format) {
|
2017-03-22 21:52:47 +00:00
|
|
|
switch (format) {
|
|
|
|
case SkEncodedImageFormat::kPNG:
|
2018-07-12 18:44:27 +00:00
|
|
|
SkPngEncoder::Encode(stream, pixmap, SkPngEncoder::Options());
|
2017-03-22 21:52:47 +00:00
|
|
|
break;
|
|
|
|
case SkEncodedImageFormat::kJPEG:
|
2017-05-02 20:04:56 +00:00
|
|
|
SkJpegEncoder::Encode(stream, pixmap, SkJpegEncoder::Options());
|
2017-03-22 21:52:47 +00:00
|
|
|
break;
|
2017-04-05 22:33:22 +00:00
|
|
|
case SkEncodedImageFormat::kWEBP:
|
2018-07-12 18:44:27 +00:00
|
|
|
SkWebpEncoder::Encode(stream, pixmap, SkWebpEncoder::Options());
|
2017-04-05 22:33:22 +00:00
|
|
|
break;
|
2017-03-22 21:52:47 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 18:44:27 +00:00
|
|
|
static void test_encode_icc(skiatest::Reporter* r, SkEncodedImageFormat format) {
|
2017-03-15 21:50:08 +00:00
|
|
|
// Test with sRGB color space.
|
|
|
|
SkBitmap srgbBitmap;
|
|
|
|
SkImageInfo srgbInfo = SkImageInfo::MakeS32(1, 1, kOpaque_SkAlphaType);
|
|
|
|
srgbBitmap.allocPixels(srgbInfo);
|
|
|
|
*srgbBitmap.getAddr32(0, 0) = 0;
|
|
|
|
SkPixmap pixmap;
|
|
|
|
srgbBitmap.peekPixels(&pixmap);
|
|
|
|
SkDynamicMemoryWStream srgbBuf;
|
2018-07-12 18:44:27 +00:00
|
|
|
encode_format(&srgbBuf, pixmap, format);
|
2017-03-15 21:50:08 +00:00
|
|
|
sk_sp<SkData> srgbData = srgbBuf.detachAsData();
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> srgbCodec(SkCodec::MakeFromData(srgbData));
|
2018-07-25 17:05:17 +00:00
|
|
|
REPORTER_ASSERT(r, srgbCodec->getInfo().colorSpace() == sk_srgb_singleton());
|
2017-03-15 21:50:08 +00:00
|
|
|
|
|
|
|
// Test with P3 color space.
|
|
|
|
SkDynamicMemoryWStream p3Buf;
|
|
|
|
sk_sp<SkColorSpace> p3 = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
|
|
|
|
SkColorSpace::kDCIP3_D65_Gamut);
|
|
|
|
pixmap.setColorSpace(p3);
|
2018-07-12 18:44:27 +00:00
|
|
|
encode_format(&p3Buf, pixmap, format);
|
2017-03-15 21:50:08 +00:00
|
|
|
sk_sp<SkData> p3Data = p3Buf.detachAsData();
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> p3Codec(SkCodec::MakeFromData(p3Data));
|
2017-03-15 21:50:08 +00:00
|
|
|
REPORTER_ASSERT(r, p3Codec->getInfo().colorSpace()->gammaCloseToSRGB());
|
|
|
|
SkMatrix44 mat0(SkMatrix44::kUninitialized_Constructor);
|
|
|
|
SkMatrix44 mat1(SkMatrix44::kUninitialized_Constructor);
|
|
|
|
bool success = p3->toXYZD50(&mat0);
|
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
success = p3Codec->getInfo().colorSpace()->toXYZD50(&mat1);
|
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
for (int j = 0; j < 4; j++) {
|
2017-03-22 21:52:47 +00:00
|
|
|
REPORTER_ASSERT(r, color_space_almost_equal(mat0.get(i, j), mat1.get(i, j)));
|
2017-03-15 21:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-22 21:52:47 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_EncodeICC, r) {
|
2018-07-12 18:44:27 +00:00
|
|
|
test_encode_icc(r, SkEncodedImageFormat::kPNG);
|
|
|
|
test_encode_icc(r, SkEncodedImageFormat::kJPEG);
|
|
|
|
test_encode_icc(r, SkEncodedImageFormat::kWEBP);
|
2017-03-22 21:52:47 +00:00
|
|
|
}
|
2017-09-27 20:31:08 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_webp_rowsDecoded, r) {
|
2017-12-08 15:21:31 +00:00
|
|
|
const char* path = "images/baby_tux.webp";
|
2017-09-27 20:31:08 +00:00
|
|
|
sk_sp<SkData> data(GetResourceAsData(path));
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Truncate this file so that the header is available but no rows can be
|
|
|
|
// decoded. This should create a codec but fail to decode.
|
|
|
|
size_t truncatedSize = 5000;
|
|
|
|
sk_sp<SkData> subset = SkData::MakeSubset(data.get(), 0, truncatedSize);
|
|
|
|
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(std::move(subset));
|
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "Failed to create a codec for %s truncated to only %lu bytes",
|
|
|
|
path, truncatedSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_info(r, codec.get(), codec->getInfo(), SkCodec::kInvalidInput, nullptr);
|
|
|
|
}
|
2018-02-16 17:03:03 +00:00
|
|
|
|
|
|
|
DEF_TEST(Codec_ossfuzz6274, r) {
|
|
|
|
if (GetResourcePath().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* file = "invalid_images/ossfuzz6274.gif";
|
|
|
|
auto image = GetResourceAsImage(file);
|
|
|
|
if (!image) {
|
|
|
|
ERRORF(r, "Missing %s", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(r, image->width() == 32);
|
|
|
|
REPORTER_ASSERT(r, image->height() == 32);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(32, 32))) {
|
|
|
|
ERRORF(r, "Failed to allocate pixels");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.drawImage(image, 0, 0, nullptr);
|
|
|
|
|
|
|
|
for (int i = 0; i < image->width(); ++i)
|
|
|
|
for (int j = 0; j < image->height(); ++j) {
|
|
|
|
SkColor actual = SkUnPreMultiply::PMColorToColor(*bm.getAddr32(i, j));
|
|
|
|
if (actual != SK_ColorTRANSPARENT) {
|
|
|
|
ERRORF(r, "did not initialize pixels! %i, %i is %x", i, j, actual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-28 21:24:18 +00:00
|
|
|
|
2018-06-26 14:49:42 +00:00
|
|
|
DEF_TEST(Codec_78329453, r) {
|
|
|
|
if (GetResourcePath().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* file = "images/b78329453.jpeg";
|
|
|
|
auto data = GetResourceAsData(file);
|
|
|
|
if (!data) {
|
|
|
|
ERRORF(r, "Missing %s", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto codec = SkAndroidCodec::MakeFromCodec(SkCodec::MakeFromData(data));
|
|
|
|
if (!codec) {
|
|
|
|
ERRORF(r, "failed to create codec from %s", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A bug in jpeg_skip_scanlines resulted in an infinite loop for this specific
|
|
|
|
// sample size on this image. Other sample sizes could have had the same result,
|
|
|
|
// but the ones tested by DM happen to not.
|
|
|
|
constexpr int kSampleSize = 19;
|
|
|
|
const auto size = codec->getSampledDimensions(kSampleSize);
|
|
|
|
auto info = codec->getInfo().makeWH(size.width(), size.height());
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
|
|
|
|
SkAndroidCodec::AndroidOptions options;
|
|
|
|
options.fSampleSize = kSampleSize;
|
|
|
|
auto result = codec->getAndroidPixels(info, bm.getPixels(), bm.rowBytes(), &options);
|
|
|
|
if (result != SkCodec::kSuccess) {
|
|
|
|
ERRORF(r, "failed to decode with error %s", SkCodec::ResultToString(result));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-28 21:24:18 +00:00
|
|
|
DEF_TEST(Codec_crbug807324, r) {
|
|
|
|
if (GetResourcePath().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* file = "images/crbug807324.png";
|
|
|
|
auto image = GetResourceAsImage(file);
|
|
|
|
if (!image) {
|
|
|
|
ERRORF(r, "Missing %s", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int kWidth = image->width();
|
|
|
|
const int kHeight = image->height();
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
if (!bm.tryAllocPixels(SkImageInfo::MakeN32Premul(kWidth, kHeight))) {
|
|
|
|
ERRORF(r, "Could not allocate pixels (%i x %i)", kWidth, kHeight);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bm.eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
|
|
|
|
SkCanvas canvas(bm);
|
|
|
|
canvas.drawImage(image, 0, 0, nullptr);
|
|
|
|
|
|
|
|
for (int i = 0; i < kWidth; ++i)
|
|
|
|
for (int j = 0; j < kHeight; ++j) {
|
|
|
|
if (*bm.getAddr32(i, j) == SK_ColorTRANSPARENT) {
|
|
|
|
ERRORF(r, "image should not be transparent! %i, %i is 0", i, j);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|