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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Resources.h"
|
2015-10-21 17:27:10 +00:00
|
|
|
#include "SkAndroidCodec.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "SkBitmap.h"
|
|
|
|
#include "SkCodec.h"
|
2016-01-14 21:12:26 +00:00
|
|
|
#include "SkCodecImageGenerator.h"
|
2016-10-18 17:02:51 +00:00
|
|
|
#include "SkColorSpace_XYZ.h"
|
2015-10-09 18:07:34 +00:00
|
|
|
#include "SkData.h"
|
2016-08-17 15:54:08 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2016-02-18 13:59:25 +00:00
|
|
|
#include "SkFrontBufferedStream.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "SkMD5.h"
|
2015-07-22 14:16:20 +00:00
|
|
|
#include "SkRandom.h"
|
2015-11-23 16:14:40 +00:00
|
|
|
#include "SkStream.h"
|
2015-11-30 14:25:31 +00:00
|
|
|
#include "SkStreamPriv.h"
|
2015-11-23 16:14:40 +00:00
|
|
|
#include "SkPngChunkReader.h"
|
2015-03-27 19:16:53 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2015-11-23 16:14:40 +00:00
|
|
|
#include "png.h"
|
|
|
|
|
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) {
|
|
|
|
SkAutoLockPixels autoLockPixels(bm);
|
|
|
|
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);
|
|
|
|
SkAutoLockPixels autoLockPixels(bm);
|
|
|
|
|
|
|
|
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);
|
|
|
|
SkAutoLockPixels autoLockPixels(bm);
|
|
|
|
|
|
|
|
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);
|
|
|
|
SkAutoLockPixels autoLockPixels(bm);
|
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);
|
|
|
|
SkAutoLockPixels alp(bm565);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
SkAutoLockPixels alp(grayBm);
|
|
|
|
|
|
|
|
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) {
|
2015-04-01 18:25:20 +00:00
|
|
|
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2015-10-05 21:20:27 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 18:07:34 +00:00
|
|
|
|
|
|
|
SkAutoTDelete<SkCodec> codec(nullptr);
|
|
|
|
bool isIncomplete = supportsIncomplete;
|
|
|
|
if (isIncomplete) {
|
|
|
|
size_t size = stream->getLength();
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
|
2016-09-12 19:01:44 +00:00
|
|
|
codec.reset(SkCodec::NewFromData(data));
|
2015-10-09 18:07:34 +00:00
|
|
|
} else {
|
2016-03-16 20:53:35 +00:00
|
|
|
codec.reset(SkCodec::NewFromStream(stream.release()));
|
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;
|
2015-10-09 18:07:34 +00:00
|
|
|
SkCodec::Result expectedResult = isIncomplete ? 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
|
|
|
|
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 (supportsNewScanlineDecoding && !isIncomplete) {
|
|
|
|
test_incremental_decode(r, codec, 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")) {
|
|
|
|
test_in_stripes(r, codec, info, codecDigest);
|
|
|
|
}
|
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);
|
|
|
|
if (!isIncomplete) {
|
|
|
|
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);
|
|
|
|
if (!isIncomplete) {
|
|
|
|
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 = ⊂
|
|
|
|
|
|
|
|
const SkCodec::Result partialStartResult = codec->startScanlineDecode(info, &options,
|
|
|
|
nullptr, nullptr);
|
|
|
|
REPORTER_ASSERT(r, partialStartResult == SkCodec::kSuccess);
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
const int lines = codec->getScanlines(bm.getAddr(0, y), 1, 0);
|
|
|
|
if (!isIncomplete) {
|
|
|
|
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);
|
|
|
|
const SkCodec::Result result = codec->getPixels(bm.info(), bm.getPixels(), bm.rowBytes(),
|
2015-08-27 14:41:13 +00:00
|
|
|
&opts, nullptr, nullptr);
|
2015-07-22 14:16:20 +00:00
|
|
|
|
|
|
|
if (supportsSubsetDecoding) {
|
2015-10-09 18:07:34 +00:00
|
|
|
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-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2015-10-05 21:20:27 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-09 18:07:34 +00:00
|
|
|
|
2016-02-04 14:14:24 +00:00
|
|
|
SkAutoTDelete<SkAndroidCodec> androidCodec(nullptr);
|
2015-10-09 18:07:34 +00:00
|
|
|
if (isIncomplete) {
|
|
|
|
size_t size = stream->getLength();
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data((SkData::MakeFromStream(stream, 2 * size / 3)));
|
2016-09-12 19:01:44 +00:00
|
|
|
androidCodec.reset(SkAndroidCodec::NewFromData(data));
|
2015-10-09 18:07:34 +00:00
|
|
|
} else {
|
2016-03-16 20:53:35 +00:00
|
|
|
androidCodec.reset(SkAndroidCodec::NewFromStream(stream.release()));
|
2015-10-09 18:07:34 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-01-14 21:12:26 +00:00
|
|
|
if (!isIncomplete) {
|
2016-02-18 13:59:25 +00:00
|
|
|
// Test SkCodecImageGenerator
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> fullData(SkData::MakeFromStream(stream, stream->getLength()));
|
|
|
|
SkAutoTDelete<SkImageGenerator> gen(
|
|
|
|
SkCodecImageGenerator::NewFromEncodedCodec(fullData.get()));
|
2016-01-14 21:12:26 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(info);
|
|
|
|
SkAutoLockPixels autoLockPixels(bm);
|
|
|
|
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
|
2016-08-02 21:40:46 +00:00
|
|
|
SkStream* bufferedStream = SkFrontBufferedStream::Create(
|
|
|
|
new SkMemoryStream(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);
|
|
|
|
codec.reset(SkCodec::NewFromStream(bufferedStream));
|
|
|
|
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-10-09 18:07:34 +00:00
|
|
|
// If we've just tested incomplete decodes, let's run the same test again on full decodes.
|
|
|
|
if (isIncomplete) {
|
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
|
|
|
check(r, path, size, supportsScanlineDecoding, supportsSubsetDecoding, false,
|
|
|
|
supportsNewScanlineDecoding);
|
2015-10-05 21:20:27 +00:00
|
|
|
}
|
2015-03-27 19:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec, r) {
|
|
|
|
// WBMP
|
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
|
|
|
check(r, "mandrill.wbmp", SkISize::Make(512, 512), true, false, true);
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2015-06-18 19:53:43 +00:00
|
|
|
// WEBP
|
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
|
|
|
check(r, "baby_tux.webp", SkISize::Make(386, 395), false, true, true);
|
|
|
|
check(r, "color_wheel.webp", SkISize::Make(128, 128), false, true, true);
|
|
|
|
check(r, "yellow_rose.webp", SkISize::Make(400, 301), false, true, true);
|
2015-06-18 19:53:43 +00:00
|
|
|
|
2015-03-27 19:16:53 +00:00
|
|
|
// 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
|
|
|
check(r, "randPixels.bmp", SkISize::Make(8, 8), true, false, true);
|
|
|
|
check(r, "rle.bmp", SkISize::Make(320, 240), true, false, true);
|
2015-03-27 19:16:53 +00:00
|
|
|
|
|
|
|
// ICO
|
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
|
2015-12-04 16:00:50 +00:00
|
|
|
check(r, "color_wheel.ico", SkISize::Make(128, 128), true, false, false);
|
2015-04-01 19:09:21 +00:00
|
|
|
// Decodes an embedded PNG image
|
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
|
|
|
check(r, "google_chrome.ico", SkISize::Make(256, 256), false, false, false, true);
|
2015-03-27 19:16:53 +00:00
|
|
|
|
2015-04-09 19:43:10 +00:00
|
|
|
// GIF
|
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
|
|
|
check(r, "box.gif", SkISize::Make(200, 55), false, false, true, true);
|
|
|
|
check(r, "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
|
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
|
|
|
check(r, "randPixels.gif", SkISize::Make(8, 8), false, false, false, true);
|
2015-04-09 19:43:10 +00:00
|
|
|
|
2015-04-15 14:32:19 +00:00
|
|
|
// JPG
|
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
|
|
|
check(r, "CMYK.jpg", SkISize::Make(642, 516), true, false, true);
|
|
|
|
check(r, "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
|
2015-10-27 15:14:46 +00:00
|
|
|
check(r, "grayscale.jpg", SkISize::Make(128, 128), true, false, 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
|
|
|
check(r, "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
|
2015-10-27 15:14:46 +00:00
|
|
|
check(r, "randPixels.jpg", SkISize::Make(8, 8), true, false, false);
|
2015-04-15 14:32:19 +00:00
|
|
|
|
2015-03-27 19:16:53 +00:00
|
|
|
// PNG
|
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
|
|
|
check(r, "arrow.png", SkISize::Make(187, 312), false, false, true, true);
|
|
|
|
check(r, "baby_tux.png", SkISize::Make(240, 246), false, false, true, true);
|
|
|
|
check(r, "color_wheel.png", SkISize::Make(128, 128), false, false, true, true);
|
|
|
|
// half-transparent-white-pixel.png is too small to test incomplete
|
|
|
|
check(r, "half-transparent-white-pixel.png", SkISize::Make(1, 1), false, false, false, true);
|
|
|
|
check(r, "mandrill_128.png", SkISize::Make(128, 128), false, false, true, true);
|
|
|
|
check(r, "mandrill_16.png", SkISize::Make(16, 16), false, false, true, true);
|
|
|
|
check(r, "mandrill_256.png", SkISize::Make(256, 256), false, false, true, true);
|
|
|
|
check(r, "mandrill_32.png", SkISize::Make(32, 32), false, false, true, true);
|
|
|
|
check(r, "mandrill_512.png", SkISize::Make(512, 512), false, false, true, true);
|
|
|
|
check(r, "mandrill_64.png", SkISize::Make(64, 64), false, false, true, true);
|
|
|
|
check(r, "plane.png", SkISize::Make(250, 126), false, false, true, true);
|
|
|
|
check(r, "plane_interlaced.png", SkISize::Make(250, 126), false, false, true, true);
|
|
|
|
check(r, "randPixels.png", SkISize::Make(8, 8), false, false, true, true);
|
|
|
|
check(r, "yellow_rose.png", SkISize::Make(400, 301), false, false, true, true);
|
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))
|
2016-01-25 16:26:16 +00:00
|
|
|
check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false);
|
2016-02-17 16:04:00 +00:00
|
|
|
check(r, "sample_1mp_rotated.dng", SkISize::Make(600, 338), false, false, false);
|
2016-02-05 16:21:19 +00:00
|
|
|
check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false);
|
2016-01-25 19:01:34 +00:00
|
|
|
#endif
|
2015-03-27 19:16:53 +00:00
|
|
|
}
|
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.
|
2015-04-03 14:22:22 +00:00
|
|
|
SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, false));
|
2015-10-09 15:40:59 +00:00
|
|
|
REPORTER_ASSERT(r, !codec);
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
SkAndroidCodec* androidCodec =
|
|
|
|
SkAndroidCodec::NewFromStream(new SkMemoryStream(stream, len, false));
|
|
|
|
REPORTER_ASSERT(r, !androidCodec);
|
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.
|
|
|
|
SkCodec* codec = SkCodec::NewFromStream(nullptr);
|
|
|
|
REPORTER_ASSERT(r, !codec);
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
SkAndroidCodec* androidCodec = SkAndroidCodec::NewFromStream(nullptr);
|
|
|
|
REPORTER_ASSERT(r, !androidCodec);
|
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-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2015-04-15 14:32:19 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-16 20:53:35 +00:00
|
|
|
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
|
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);
|
|
|
|
size_t totalBytes = scaledInfo.getSafeSize(rowBytes);
|
|
|
|
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
|
|
|
|
test_dimensions(r, "CMYK.jpg");
|
|
|
|
test_dimensions(r, "color_wheel.jpg");
|
|
|
|
test_dimensions(r, "grayscale.jpg");
|
|
|
|
test_dimensions(r, "mandrill_512_q075.jpg");
|
|
|
|
test_dimensions(r, "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.
|
|
|
|
test_dimensions(r, "1x1.png");
|
|
|
|
test_dimensions(r, "2x2.png");
|
|
|
|
test_dimensions(r, "3x3.png");
|
|
|
|
test_dimensions(r, "3x1.png");
|
|
|
|
test_dimensions(r, "1x1.png");
|
|
|
|
test_dimensions(r, "16x1.png");
|
|
|
|
test_dimensions(r, "1x16.png");
|
|
|
|
test_dimensions(r, "mandrill_16.png");
|
|
|
|
|
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))
|
2016-01-25 16:26:16 +00:00
|
|
|
test_dimensions(r, "sample_1mp.dng");
|
2016-02-17 16:04:00 +00:00
|
|
|
test_dimensions(r, "sample_1mp_rotated.dng");
|
2016-02-05 16:21:19 +00:00
|
|
|
test_dimensions(r, "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[]) {
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2015-04-23 15:53:39 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-16 20:53:35 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(r, nullptr == codec);
|
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) {
|
|
|
|
// 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");
|
2015-04-23 15:53:39 +00:00
|
|
|
}
|
2015-08-05 19:58:26 +00:00
|
|
|
|
|
|
|
static void test_invalid_parameters(skiatest::Reporter* r, const char path[]) {
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2015-08-05 19:58:26 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-16 20:53:35 +00:00
|
|
|
SkAutoTDelete<SkCodec> decoder(SkCodec::NewFromStream(stream.release()));
|
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 (!decoder) {
|
|
|
|
SkDebugf("Missing codec for %s\n", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SkImageInfo info = decoder->getInfo().makeColorType(kIndex_8_SkColorType);
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-08-05 19:58:26 +00:00
|
|
|
// This should return kSuccess because kIndex8 is supported.
|
|
|
|
SkPMColor colorStorage[256];
|
|
|
|
int colorCount;
|
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
|
|
|
SkCodec::Result result = decoder->startScanlineDecode(info, nullptr, colorStorage,
|
|
|
|
&colorCount);
|
|
|
|
if (SkCodec::kSuccess == result) {
|
|
|
|
// This should return kInvalidParameters because, in kIndex_8 mode, we must pass in a valid
|
|
|
|
// colorPtr and a valid colorCountPtr.
|
|
|
|
result = decoder->startScanlineDecode(info, nullptr, nullptr, nullptr);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
|
|
|
|
result = decoder->startScanlineDecode(info);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
|
|
|
|
} else if (SkCodec::kUnimplemented == result) {
|
|
|
|
// New method should be supported:
|
|
|
|
SkBitmap bm;
|
|
|
|
sk_sp<SkColorTable> colorTable(new SkColorTable(colorStorage, 256));
|
|
|
|
bm.allocPixels(info, nullptr, colorTable.get());
|
|
|
|
result = decoder->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes(), nullptr,
|
|
|
|
colorStorage, &colorCount);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
result = decoder->startIncrementalDecode(info, bm.getPixels(), bm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result);
|
|
|
|
} else {
|
|
|
|
// The test is uninteresting if kIndex8 is not supported
|
|
|
|
ERRORF(r, "Should not call test_invalid_parameters for non-Index8 file: %s\n", path);
|
2015-08-05 19:58:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec_Params, r) {
|
|
|
|
test_invalid_parameters(r, "index8.png");
|
|
|
|
test_invalid_parameters(r, "mandrill.wbmp");
|
|
|
|
}
|
2015-11-23 16:14:40 +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.
|
2016-09-12 19:01:44 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(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;
|
|
|
|
bool success = decodedBm.copyTo(&tmp, bm.colorType());
|
|
|
|
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-05 16:21:19 +00:00
|
|
|
// Stream that is not an asset stream (!hasPosition() or !hasLength())
|
|
|
|
class NotAssetMemStream : public SkStream {
|
|
|
|
public:
|
2016-08-02 21:40:46 +00:00
|
|
|
NotAssetMemStream(sk_sp<SkData> data) : fStream(std::move(data)) {}
|
2016-02-05 16:21:19 +00:00
|
|
|
|
|
|
|
bool hasPosition() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasLength() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t peek(void* buf, size_t bytes) const override {
|
|
|
|
return fStream.peek(buf, bytes);
|
|
|
|
}
|
|
|
|
size_t read(void* buf, size_t bytes) override {
|
|
|
|
return fStream.read(buf, bytes);
|
|
|
|
}
|
|
|
|
bool rewind() override {
|
|
|
|
return fStream.rewind();
|
|
|
|
}
|
|
|
|
bool isAtEnd() const override {
|
|
|
|
return fStream.isAtEnd();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMemoryStream fStream;
|
|
|
|
};
|
|
|
|
|
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) {
|
|
|
|
const char* path = "dng_with_preview.dng";
|
|
|
|
SkString fullPath(GetResourcePath(path));
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeFromFileName(fullPath.c_str()));
|
2016-02-05 16:21:19 +00:00
|
|
|
if (!data) {
|
|
|
|
SkDebugf("Missing resource '%s'\n", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new 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) {
|
|
|
|
const char* path = "baby_tux.webp";
|
|
|
|
SkString fullPath(GetResourcePath(path));
|
2016-03-11 21:02:28 +00:00
|
|
|
auto data = SkData::MakeFromFileName(fullPath.c_str());
|
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.
|
2016-03-11 21:02:28 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(
|
2016-09-12 19:01:44 +00:00
|
|
|
new 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.
|
2016-09-12 19:01:44 +00:00
|
|
|
codec.reset(SkCodec::NewFromStream(new 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.
|
2015-11-30 14:25:31 +00:00
|
|
|
DEF_TEST(Codec_wbmp, r) {
|
|
|
|
const char* path = "mandrill.wbmp";
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<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-03-11 21:02:28 +00:00
|
|
|
auto data = SkCopyStreamToData(stream);
|
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.
|
2016-09-12 19:01:44 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(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
|
|
|
|
// because SkCodec only passes 14 bytes to SkWbmpCodec to determine whether the
|
|
|
|
// image is a wbmp.
|
|
|
|
DEF_TEST(Codec_wbmp_max_size, r) {
|
|
|
|
const unsigned char maxSizeWbmp[] = { 0x00, 0x00, // Header
|
|
|
|
0x83, 0xFF, 0x7F, // W: 65535
|
|
|
|
0x83, 0xFF, 0x7F }; // H: 65535
|
|
|
|
SkAutoTDelete<SkStream> stream(new SkMemoryStream(maxSizeWbmp, sizeof(maxSizeWbmp), false));
|
2016-03-16 20:53:35 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
|
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));
|
2016-03-16 20:53:35 +00:00
|
|
|
codec.reset(SkCodec::NewFromStream(stream.release()));
|
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) {
|
|
|
|
const char* path = "mandrill_512_q075.jpg";
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2016-07-18 22:56:08 +00:00
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
|
|
|
|
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;
|
|
|
|
codec->getAndroidPixels(codec->getInfo().makeWH(width / 12, height / 12), pixelStorage.get(),
|
|
|
|
rowBytes, &opts);
|
|
|
|
|
|
|
|
// Rewind the codec and perform a full image decode.
|
|
|
|
SkCodec::Result result = codec->getPixels(codec->getInfo(), pixelStorage.get(), rowBytes);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
}
|
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) {
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(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;
|
|
|
|
sk_sp<SkData> data = SkData::MakeFromFileName(
|
|
|
|
GetResourcePath("icc_profiles/HP_ZR30w.icc").c_str());
|
2016-10-24 13:24:02 +00:00
|
|
|
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeICC(data->data(), data->size());
|
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();
|
|
|
|
SkAutoMalloc pixelStorage(dstInfo.getSafeSize(rowBytes));
|
|
|
|
SkCodec::Result result = codec->getAndroidPixels(dstInfo, pixelStorage.get(), rowBytes, &opts);
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(Codec_ColorXform, r) {
|
|
|
|
check_color_xform(r, "mandrill_512_q075.jpg");
|
|
|
|
check_color_xform(r, "mandrill_512.png");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
SkPMColor colors[256];
|
|
|
|
SkAutoTUnref<SkColorTable> colorTable1(new SkColorTable(colors, 256));
|
|
|
|
bm1.allocPixels(info, nullptr, colorTable1.get());
|
|
|
|
int numColors;
|
|
|
|
SkCodec::Result result = origCodec->getPixels(info, bm1.getPixels(), bm1.rowBytes(), nullptr,
|
|
|
|
const_cast<SkPMColor*>(colorTable1->readColors()),
|
|
|
|
&numColors);
|
|
|
|
// This will fail to update colorTable1->count() but is fine for the purpose of this test.
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kSuccess == result);
|
2016-08-17 15:54:08 +00:00
|
|
|
|
|
|
|
// Encode the image to png.
|
|
|
|
sk_sp<SkData> data =
|
|
|
|
sk_sp<SkData>(SkImageEncoder::EncodeData(bm1, SkImageEncoder::kPNG_Type, 100));
|
|
|
|
|
2016-09-12 19:01:44 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(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;
|
2016-09-12 21:30:03 +00:00
|
|
|
SkAutoTUnref<SkColorTable> colorTable2(new SkColorTable(colors, 256));
|
|
|
|
bm2.allocPixels(info, nullptr, colorTable2.get());
|
|
|
|
result = codec->getPixels(info, bm2.getPixels(), bm2.rowBytes(), nullptr,
|
|
|
|
const_cast<SkPMColor*>(colorTable2->readColors()), &numColors);
|
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) {
|
|
|
|
const char* path = "mandrill_512_q075.jpg";
|
2016-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2016-08-29 21:47:49 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-08-29 21:47:49 +00:00
|
|
|
path = "grayscale.jpg";
|
2016-09-16 13:24:20 +00:00
|
|
|
stream.reset(GetResourceAsStream(path));
|
2016-08-29 21:47:49 +00:00
|
|
|
codec.reset(SkCodec::NewFromStream(stream.release()));
|
2016-09-12 21:30:03 +00:00
|
|
|
check_round_trip(r, codec.get(), codec->getInfo());
|
|
|
|
|
|
|
|
path = "yellow_rose.png";
|
2016-09-16 13:24:20 +00:00
|
|
|
stream.reset(GetResourceAsStream(path));
|
2016-09-12 21:30:03 +00:00
|
|
|
codec.reset(SkCodec::NewFromStream(stream.release()));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
path = "index8.png";
|
2016-09-16 13:24:20 +00:00
|
|
|
stream.reset(GetResourceAsStream(path));
|
2016-09-12 21:30:03 +00:00
|
|
|
codec.reset(SkCodec::NewFromStream(stream.release()));
|
|
|
|
|
|
|
|
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-09-16 13:24:20 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(GetResourceAsStream(path));
|
2016-09-08 18:55:16 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.release()));
|
|
|
|
SkImageInfo infoF16 = codec->getInfo().makeColorType(kRGBA_F16_SkColorType);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(infoF16);
|
|
|
|
SkCodec::Result result = codec->getPixels(infoF16, bm.getPixels(), bm.rowBytes());
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kInvalidConversion == 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) {
|
2016-09-08 18:55:16 +00:00
|
|
|
REPORTER_ASSERT(r, SkCodec::kInvalidConversion == 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = codec->startIncrementalDecode(infoF16, bm.getPixels(), bm.rowBytes());
|
|
|
|
if (supportsIncrementalDecoder) {
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kInvalidConversion == result);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(r, SkCodec::kUnimplemented == result);
|
2016-09-08 18:55:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-18 17:02:51 +00:00
|
|
|
SkASSERT(SkColorSpace_Base::Type::kXYZ == as_CSB(infoF16.colorSpace())->type());
|
|
|
|
SkColorSpace_XYZ* csXYZ = static_cast<SkColorSpace_XYZ*>(infoF16.colorSpace());
|
|
|
|
infoF16 = infoF16.makeColorSpace(csXYZ->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) {
|
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
|
|
|
test_conversion_possible(r, "color_wheel.webp", false, false);
|
|
|
|
test_conversion_possible(r, "mandrill_512_q075.jpg", true, false);
|
|
|
|
test_conversion_possible(r, "yellow_rose.png", false, true);
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
bm.getPixels(), bm.rowBytes(), &opts, nullptr, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
// For an animated image, we should only read enough to decode the requested
|
|
|
|
// frame if the client never calls getFrameInfo.
|
|
|
|
DEF_TEST(Codec_skipFullParse, r) {
|
|
|
|
auto path = "test640x479.gif";
|
|
|
|
SkStream* stream(GetResourceAsStream(path));
|
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromStream(stream));
|
|
|
|
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());
|
|
|
|
|
|
|
|
// Again, this should read more of the stream.
|
|
|
|
decode_frame(r, codec.get(), 2);
|
|
|
|
const size_t positionAfterThirdFrame = stream->getPosition();
|
|
|
|
REPORTER_ASSERT(r, positionAfterThirdFrame > positionAfterFirstFrame
|
|
|
|
&& positionAfterThirdFrame < stream->getLength());
|
|
|
|
|
|
|
|
// This does not need to read any more of the stream, since it has already
|
|
|
|
// parsed the second frame.
|
|
|
|
decode_frame(r, codec.get(), 1);
|
|
|
|
REPORTER_ASSERT(r, stream->getPosition() == positionAfterThirdFrame);
|
|
|
|
|
|
|
|
// This should read the rest of the frames.
|
|
|
|
decode_frame(r, codec.get(), 3);
|
|
|
|
const size_t finalPosition = stream->getPosition();
|
|
|
|
REPORTER_ASSERT(r, finalPosition > positionAfterThirdFrame);
|
|
|
|
|
|
|
|
// There may be more data in the stream.
|
|
|
|
auto frameInfo = codec->getFrameInfo();
|
|
|
|
REPORTER_ASSERT(r, frameInfo.size() == 4);
|
|
|
|
REPORTER_ASSERT(r, stream->getPosition() >= finalPosition);
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
static SkStream* Make(const char path[], size_t limit) {
|
|
|
|
SkStream* stream = GetResourceAsStream(path);
|
|
|
|
if (!stream) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new LimitedRewindingStream(stream, limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
SkAutoTDelete<SkStream> fStream;
|
|
|
|
const size_t fLimit;
|
|
|
|
size_t fPosition;
|
|
|
|
|
|
|
|
LimitedRewindingStream(SkStream* stream, size_t limit)
|
|
|
|
: fStream(stream)
|
|
|
|
, 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 = {
|
|
|
|
"CMYK.jpg",
|
|
|
|
"color_wheel.ico",
|
|
|
|
"mandrill.wbmp",
|
|
|
|
"randPixels.bmp",
|
|
|
|
};
|
|
|
|
for (auto file : files) {
|
|
|
|
SkStream* stream = LimitedRewindingStream::Make(file, 14);
|
|
|
|
if (!stream) {
|
|
|
|
SkDebugf("Missing resources (%s). Set --resourcePath.\n", file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream));
|
|
|
|
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) {
|
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream("plane.png"));
|
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::NewFromStream(stream.release()));
|
|
|
|
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) {
|
|
|
|
auto file = "plane_interlaced.png";
|
|
|
|
std::unique_ptr<SkStream> stream(GetResourceAsStream(file));
|
|
|
|
if (!stream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is enough to read the header etc, but no rows.
|
|
|
|
auto data = SkData::MakeFromStream(stream.get(), 99);
|
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::NewFromData(data));
|
|
|
|
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
|
|
|
|
|
|
|
DEF_TEST(Codec_IcoIntOverflow, r) {
|
|
|
|
// ASAN will complain if there is an issue.
|
|
|
|
SkBitmap bitmap;
|
|
|
|
const bool success = GetResourceAsBitmap("invalid_images/int_overflow.ico", &bitmap);
|
|
|
|
REPORTER_ASSERT(r, !success);
|
|
|
|
}
|