2013-06-14 15:33:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "Resources.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkBitmap.h"
|
2013-07-18 20:06:28 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkColor.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkColorPriv.h"
|
2013-07-18 20:06:28 +00:00
|
|
|
#include "SkData.h"
|
2013-12-20 16:35:22 +00:00
|
|
|
#include "SkDecodingImageGenerator.h"
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
#include "SkDiscardableMemoryPool.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkForceLinking.h"
|
2013-07-18 20:06:28 +00:00
|
|
|
#include "SkGradientShader.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkImageDecoder.h"
|
2013-07-18 20:06:28 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2014-05-27 14:14:22 +00:00
|
|
|
#include "SkImageGeneratorPriv.h"
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
#include "SkImagePriv.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkOSFile.h"
|
2013-07-18 20:06:28 +00:00
|
|
|
#include "SkPoint.h"
|
|
|
|
#include "SkShader.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
2014-01-24 20:56:26 +00:00
|
|
|
#include "Test.h"
|
2013-06-14 15:33:20 +00:00
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Interprets c as an unpremultiplied color, and returns the
|
|
|
|
* premultiplied equivalent.
|
|
|
|
*/
|
|
|
|
static SkPMColor premultiply_unpmcolor(SkPMColor c) {
|
|
|
|
U8CPU a = SkGetPackedA32(c);
|
|
|
|
U8CPU r = SkGetPackedR32(c);
|
|
|
|
U8CPU g = SkGetPackedG32(c);
|
|
|
|
U8CPU b = SkGetPackedB32(c);
|
|
|
|
return SkPreMultiplyARGB(a, r, g, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if this stream format should be skipped, due
|
|
|
|
* to do being an opaque format or not a valid format.
|
|
|
|
*/
|
|
|
|
static bool skip_image_format(SkImageDecoder::Format format) {
|
|
|
|
switch (format) {
|
|
|
|
case SkImageDecoder::kPNG_Format:
|
|
|
|
case SkImageDecoder::kWEBP_Format:
|
|
|
|
return false;
|
|
|
|
// Skip unknown since it will not be decoded anyway.
|
|
|
|
case SkImageDecoder::kUnknown_Format:
|
|
|
|
// Technically ICO and BMP supports alpha channels, but our image
|
|
|
|
// decoders do not, so skip them as well.
|
|
|
|
case SkImageDecoder::kICO_Format:
|
|
|
|
case SkImageDecoder::kBMP_Format:
|
2014-08-07 19:58:38 +00:00
|
|
|
// KTX and ASTC are texture formats so it's not particularly clear how to
|
|
|
|
// decode the alpha from them.
|
2014-06-03 20:04:35 +00:00
|
|
|
case SkImageDecoder::kKTX_Format:
|
2014-08-07 19:58:38 +00:00
|
|
|
case SkImageDecoder::kASTC_Format:
|
2013-06-14 15:33:20 +00:00
|
|
|
// The rest of these are opaque.
|
2014-05-22 18:40:29 +00:00
|
|
|
case SkImageDecoder::kPKM_Format:
|
2013-06-14 15:33:20 +00:00
|
|
|
case SkImageDecoder::kWBMP_Format:
|
|
|
|
case SkImageDecoder::kGIF_Format:
|
|
|
|
case SkImageDecoder::kJPEG_Format:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
SkASSERT(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test decoding an image in premultiplied mode and unpremultiplied mode and compare
|
|
|
|
* them.
|
|
|
|
*/
|
|
|
|
static void compare_unpremul(skiatest::Reporter* reporter, const SkString& filename) {
|
|
|
|
// Decode a resource:
|
|
|
|
SkBitmap bm8888;
|
|
|
|
SkBitmap bm8888Unpremul;
|
|
|
|
|
|
|
|
SkFILEStream stream(filename.c_str());
|
|
|
|
|
|
|
|
SkImageDecoder::Format format = SkImageDecoder::GetStreamFormat(&stream);
|
|
|
|
if (skip_image_format(format)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream));
|
|
|
|
if (NULL == decoder.get()) {
|
|
|
|
SkDebugf("couldn't decode %s\n", filename.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-13 00:40:00 +00:00
|
|
|
bool success = decoder->decode(&stream, &bm8888, kN32_SkColorType,
|
2014-10-22 19:07:00 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode) != SkImageDecoder::kFailure;
|
2013-06-14 15:33:20 +00:00
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = stream.rewind();
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder->setRequireUnpremultipliedColors(true);
|
2014-06-13 00:40:00 +00:00
|
|
|
success = decoder->decode(&stream, &bm8888Unpremul, kN32_SkColorType,
|
2014-10-22 19:07:00 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode) != SkImageDecoder::kFailure;
|
2013-06-14 15:33:20 +00:00
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool dimensionsMatch = bm8888.width() == bm8888Unpremul.width()
|
|
|
|
&& bm8888.height() == bm8888Unpremul.height();
|
|
|
|
REPORTER_ASSERT(reporter, dimensionsMatch);
|
|
|
|
if (!dimensionsMatch) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only do the comparison if the two bitmaps are both 8888.
|
2014-06-13 00:40:00 +00:00
|
|
|
if (bm8888.colorType() != kN32_SkColorType || bm8888Unpremul.colorType() != kN32_SkColorType) {
|
2013-06-14 15:33:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now compare the two bitmaps.
|
|
|
|
for (int i = 0; i < bm8888.width(); ++i) {
|
|
|
|
for (int j = 0; j < bm8888.height(); ++j) {
|
|
|
|
// "c0" is the color of the premultiplied bitmap at (i, j).
|
|
|
|
const SkPMColor c0 = *bm8888.getAddr32(i, j);
|
|
|
|
// "c1" is the result of premultiplying the color of the unpremultiplied
|
|
|
|
// bitmap at (i, j).
|
|
|
|
const SkPMColor c1 = premultiply_unpmcolor(*bm8888Unpremul.getAddr32(i, j));
|
|
|
|
// Compute the difference for each component.
|
|
|
|
int da = SkAbs32(SkGetPackedA32(c0) - SkGetPackedA32(c1));
|
|
|
|
int dr = SkAbs32(SkGetPackedR32(c0) - SkGetPackedR32(c1));
|
|
|
|
int dg = SkAbs32(SkGetPackedG32(c0) - SkGetPackedG32(c1));
|
|
|
|
int db = SkAbs32(SkGetPackedB32(c0) - SkGetPackedB32(c1));
|
|
|
|
|
|
|
|
// Alpha component must be exactly the same.
|
|
|
|
REPORTER_ASSERT(reporter, 0 == da);
|
2013-06-14 20:39:48 +00:00
|
|
|
|
|
|
|
// Color components may not match exactly due to rounding error.
|
|
|
|
REPORTER_ASSERT(reporter, dr <= 1);
|
|
|
|
REPORTER_ASSERT(reporter, dg <= 1);
|
|
|
|
REPORTER_ASSERT(reporter, db <= 1);
|
2013-06-14 15:33:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-18 19:34:49 +00:00
|
|
|
static void test_unpremul(skiatest::Reporter* reporter) {
|
2013-06-14 15:33:20 +00:00
|
|
|
// This test cannot run if there is no resource path.
|
2014-06-18 21:32:48 +00:00
|
|
|
SkString resourcePath = GetResourcePath();
|
2013-06-14 15:33:20 +00:00
|
|
|
if (resourcePath.isEmpty()) {
|
2013-10-24 21:39:35 +00:00
|
|
|
SkDebugf("Could not run unpremul test because resourcePath not specified.");
|
2013-06-14 15:33:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkOSFile::Iter iter(resourcePath.c_str());
|
|
|
|
SkString basename;
|
|
|
|
if (iter.next(&basename)) {
|
|
|
|
do {
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString filename = SkOSPath::Join(resourcePath.c_str(), basename.c_str());
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
// SkDebugf("about to decode \"%s\"\n", filename.c_str());
|
2013-06-14 15:33:20 +00:00
|
|
|
compare_unpremul(reporter, filename);
|
|
|
|
} while (iter.next(&basename));
|
|
|
|
} else {
|
|
|
|
SkDebugf("Failed to find any files :(\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-24 18:55:13 +00:00
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
|
|
|
|
// Test that the alpha type is what we expect.
|
|
|
|
static void test_alphaType(skiatest::Reporter* reporter, const SkString& filename,
|
|
|
|
bool requireUnpremul) {
|
|
|
|
SkBitmap bm;
|
|
|
|
SkFILEStream stream(filename.c_str());
|
|
|
|
|
|
|
|
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream));
|
|
|
|
if (NULL == decoder.get()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder->setRequireUnpremultipliedColors(requireUnpremul);
|
|
|
|
|
|
|
|
// Decode just the bounds. This should always succeed.
|
2014-06-13 00:40:00 +00:00
|
|
|
bool success = decoder->decode(&stream, &bm, kN32_SkColorType,
|
2014-04-24 18:55:13 +00:00
|
|
|
SkImageDecoder::kDecodeBounds_Mode);
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep track of the alpha type for testing later. If the full decode
|
|
|
|
// succeeds, the alpha type should be the same, unless the full decode
|
|
|
|
// determined that the alpha type should actually be opaque, which may
|
|
|
|
// not be known when only decoding the bounds.
|
|
|
|
const SkAlphaType boundsAlphaType = bm.alphaType();
|
|
|
|
|
|
|
|
// rewind should always succeed on SkFILEStream.
|
|
|
|
success = stream.rewind();
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-13 00:40:00 +00:00
|
|
|
success = decoder->decode(&stream, &bm, kN32_SkColorType, SkImageDecoder::kDecodePixels_Mode);
|
2014-04-24 18:55:13 +00:00
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
// When the decoder is set to require unpremul, if it does not support
|
|
|
|
// unpremul it will fail. This is the only reason the decode should
|
|
|
|
// fail (since we know the files we are using to test can be decoded).
|
|
|
|
REPORTER_ASSERT(reporter, requireUnpremul);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The bounds decode should return with either the requested
|
|
|
|
// premul/unpremul or opaque, if that value could be determined when only
|
|
|
|
// decoding the bounds.
|
|
|
|
if (requireUnpremul) {
|
|
|
|
REPORTER_ASSERT(reporter, kUnpremul_SkAlphaType == boundsAlphaType
|
2015-03-27 19:16:53 +00:00
|
|
|
|| kOpaque_SkAlphaType == boundsAlphaType
|
|
|
|
|| filename.endsWith(".ico"));
|
|
|
|
// TODO(halcanary): Find out why color_wheel.ico fails this test.
|
2014-04-24 18:55:13 +00:00
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, kPremul_SkAlphaType == boundsAlphaType
|
|
|
|
|| kOpaque_SkAlphaType == boundsAlphaType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When decoding the full image, the alpha type should match the one
|
|
|
|
// returned by the bounds decode, unless the full decode determined that
|
|
|
|
// the alpha type is actually opaque.
|
|
|
|
REPORTER_ASSERT(reporter, bm.alphaType() == boundsAlphaType
|
|
|
|
|| bm.alphaType() == kOpaque_SkAlphaType);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(ImageDecoding_alphaType, reporter) {
|
2014-06-18 21:32:48 +00:00
|
|
|
SkString resourcePath = GetResourcePath();
|
2014-04-24 18:55:13 +00:00
|
|
|
if (resourcePath.isEmpty()) {
|
|
|
|
SkDebugf("Could not run alphaType test because resourcePath not specified.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkOSFile::Iter iter(resourcePath.c_str());
|
|
|
|
SkString basename;
|
|
|
|
if (iter.next(&basename)) {
|
|
|
|
do {
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString filename = SkOSPath::Join(resourcePath.c_str(), basename.c_str());
|
2014-04-24 18:55:13 +00:00
|
|
|
for (int truth = 0; truth <= 1; ++truth) {
|
|
|
|
test_alphaType(reporter, filename, SkToBool(truth));
|
|
|
|
}
|
|
|
|
} while (iter.next(&basename));
|
|
|
|
} else {
|
|
|
|
SkDebugf("Failed to find any files :(\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Using known images, test that decoding into unpremul and premul behave as expected.
|
|
|
|
DEF_TEST(ImageDecoding_unpremul, reporter) {
|
2014-06-18 21:32:48 +00:00
|
|
|
SkString resourcePath = GetResourcePath();
|
2014-04-24 18:55:13 +00:00
|
|
|
if (resourcePath.isEmpty()) {
|
|
|
|
SkDebugf("Could not run unpremul test because resourcePath not specified.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const char* root = "half-transparent-white-pixel";
|
|
|
|
const char* suffixes[] = { ".png", ".webp" };
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(suffixes); ++i) {
|
|
|
|
SkString basename = SkStringPrintf("%s%s", root, suffixes[i]);
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString fullName = SkOSPath::Join(resourcePath.c_str(), basename.c_str());
|
2014-04-24 18:55:13 +00:00
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
SkFILEStream stream(fullName.c_str());
|
|
|
|
|
|
|
|
if (!stream.isValid()) {
|
|
|
|
SkDebugf("file %s missing from resource directoy %s\n",
|
|
|
|
basename.c_str(), resourcePath.c_str());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should never fail since we know the images we're decoding.
|
|
|
|
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(&stream));
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, decoder.get());
|
2014-04-24 18:55:13 +00:00
|
|
|
if (NULL == decoder.get()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test unpremultiplied. We know what color this should result in.
|
|
|
|
decoder->setRequireUnpremultipliedColors(true);
|
2014-06-13 00:40:00 +00:00
|
|
|
bool success = decoder->decode(&stream, &bm, kN32_SkColorType,
|
2014-04-24 18:55:13 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode);
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, bm.width() == 1 && bm.height() == 1);
|
|
|
|
{
|
|
|
|
SkAutoLockPixels alp(bm);
|
|
|
|
REPORTER_ASSERT(reporter, bm.getAddr32(0, 0)[0] == 0x7fffffff);
|
|
|
|
}
|
|
|
|
|
|
|
|
success = stream.rewind();
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test premultiplied. Once again, we know which color this should
|
|
|
|
// result in.
|
|
|
|
decoder->setRequireUnpremultipliedColors(false);
|
2014-06-13 00:40:00 +00:00
|
|
|
success = decoder->decode(&stream, &bm, kN32_SkColorType,
|
2014-04-24 18:55:13 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode);
|
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, bm.width() == 1 && bm.height() == 1);
|
|
|
|
{
|
|
|
|
SkAutoLockPixels alp(bm);
|
|
|
|
REPORTER_ASSERT(reporter, bm.getAddr32(0, 0)[0] == 0x7f7f7f7f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // SK_BUILD_FOR_UNIX/ANDROID skbug.com/2388
|
|
|
|
|
2013-07-18 20:06:28 +00:00
|
|
|
#ifdef SK_DEBUG
|
Add an option on SkImageDecoder to skip writing 0s.
Only implemented for PNG.
Add a getter and setter, and sets the default to false in the
constructor. Also copies the setting in copyFieldsToOther.
Fix an indpendent bug where fDitherImage was not being copied in
copyFieldsToOther.
In SkScaledBitmapSampler::begin, consolidate the settings passed in
by passing a const reference to the decoder. The decoder can be
referenced for its settings of dither, unpremultiplied, and now
skipping writing zeroes. Update callers to use the new API. In png
decoder, rather than passing around a pointer to an initial
read of getDitherImage, and potentially changing it, look at the
field on the decoder itself, and modify it directly. This is a
change in behavior - now if that same decoder is used to decode
a different image, the dither setting has changed. I think this is
okay because A) the typical use case is to use a new decoder for
each decode, B) we do not make any promises that a decode does not
change the decoder and C) it makes the code in SkScaledBitmapSampler
much cleaner.
In SkScaledBitmapScampler, add new row procs for skipping zeroes. Now
that choosing the row proc has five dimensions (src config, dst config,
dither, skip writing zeroes, unpremultiplied), use a new method: each
src/dst combination has a function for choosing the right proc depending
on the decoder.
SkScaledBitmapScampler::RowProc is now public for convenience.
Remove Sample_Gray_D8888_Unpremul, which is effectively no different
from Sample_Gray_D8888.
In cases where unpremultiplied was trivial, such as 565 and when
sampling from gray, decoding may now succeed.
Add a benchmark (currently disabled) for comparing the speed of skipping
writing zeroes versus not skipping. For this particular image, which is
mostly transparent pixels, normal decoding took about 3.6 milliseconds,
while skipping zeroes in the decode took only about 2.5 milliseconds
(this is on a Nexus 4). Presumably it would be slower on an image
with a small amount of transparency, but there will be no slowdown
for an image which reports that it has no transparency.
In SkImageRef_ashmem, always skip writing zeroes, since ashmem
memory is guaranteed to be initialized to 0.
Add a flag to skip writing zeroes in skimage.
Add a regression test for choosing the rowproc to ensure I did not
change any behavior accidentally.
BUG=skia:1661
R=reed@google.com
Review URL: https://codereview.chromium.org/24269006
git-svn-id: http://skia.googlecode.com/svn/trunk@11558 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-01 17:27:15 +00:00
|
|
|
// Test inside SkScaledBitmapSampler.cpp
|
|
|
|
extern void test_row_proc_choice();
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
#endif // SK_DEBUG
|
2013-07-18 20:06:28 +00:00
|
|
|
|
2013-12-12 21:11:12 +00:00
|
|
|
DEF_TEST(ImageDecoding, reporter) {
|
2013-07-18 19:34:49 +00:00
|
|
|
test_unpremul(reporter);
|
2013-07-18 20:06:28 +00:00
|
|
|
#ifdef SK_DEBUG
|
Add an option on SkImageDecoder to skip writing 0s.
Only implemented for PNG.
Add a getter and setter, and sets the default to false in the
constructor. Also copies the setting in copyFieldsToOther.
Fix an indpendent bug where fDitherImage was not being copied in
copyFieldsToOther.
In SkScaledBitmapSampler::begin, consolidate the settings passed in
by passing a const reference to the decoder. The decoder can be
referenced for its settings of dither, unpremultiplied, and now
skipping writing zeroes. Update callers to use the new API. In png
decoder, rather than passing around a pointer to an initial
read of getDitherImage, and potentially changing it, look at the
field on the decoder itself, and modify it directly. This is a
change in behavior - now if that same decoder is used to decode
a different image, the dither setting has changed. I think this is
okay because A) the typical use case is to use a new decoder for
each decode, B) we do not make any promises that a decode does not
change the decoder and C) it makes the code in SkScaledBitmapSampler
much cleaner.
In SkScaledBitmapScampler, add new row procs for skipping zeroes. Now
that choosing the row proc has five dimensions (src config, dst config,
dither, skip writing zeroes, unpremultiplied), use a new method: each
src/dst combination has a function for choosing the right proc depending
on the decoder.
SkScaledBitmapScampler::RowProc is now public for convenience.
Remove Sample_Gray_D8888_Unpremul, which is effectively no different
from Sample_Gray_D8888.
In cases where unpremultiplied was trivial, such as 565 and when
sampling from gray, decoding may now succeed.
Add a benchmark (currently disabled) for comparing the speed of skipping
writing zeroes versus not skipping. For this particular image, which is
mostly transparent pixels, normal decoding took about 3.6 milliseconds,
while skipping zeroes in the decode took only about 2.5 milliseconds
(this is on a Nexus 4). Presumably it would be slower on an image
with a small amount of transparency, but there will be no slowdown
for an image which reports that it has no transparency.
In SkImageRef_ashmem, always skip writing zeroes, since ashmem
memory is guaranteed to be initialized to 0.
Add a flag to skip writing zeroes in skimage.
Add a regression test for choosing the rowproc to ensure I did not
change any behavior accidentally.
BUG=skia:1661
R=reed@google.com
Review URL: https://codereview.chromium.org/24269006
git-svn-id: http://skia.googlecode.com/svn/trunk@11558 2bbb7eff-a529-9590-31e7-b0007b416f81
2013-10-01 17:27:15 +00:00
|
|
|
test_row_proc_choice();
|
2013-07-18 20:06:28 +00:00
|
|
|
#endif
|
2013-07-18 19:34:49 +00:00
|
|
|
}
|
2013-12-20 16:35:22 +00:00
|
|
|
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
// expected output for 8x8 bitmap
|
2014-01-21 23:39:22 +00:00
|
|
|
static const int kExpectedWidth = 8;
|
|
|
|
static const int kExpectedHeight = 8;
|
|
|
|
static const SkColor kExpectedPixels[] = {
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
0xffbba570, 0xff395f5d, 0xffe25c39, 0xff197666,
|
|
|
|
0xff3cba27, 0xffdefcb0, 0xffc13874, 0xfffa0093,
|
|
|
|
0xffbda60e, 0xffc01db6, 0xff2bd688, 0xff9362d4,
|
|
|
|
0xffc641b2, 0xffa5cede, 0xff606eba, 0xff8f4bf3,
|
|
|
|
0xff3bf742, 0xff8f02a8, 0xff5509df, 0xffc7027e,
|
|
|
|
0xff24aa8a, 0xff886c96, 0xff625481, 0xff403689,
|
|
|
|
0xffc52152, 0xff78ccd6, 0xffdcb4ab, 0xff09d27d,
|
|
|
|
0xffca00f3, 0xff605d47, 0xff446fb2, 0xff576e46,
|
|
|
|
0xff273df9, 0xffb41a83, 0xfff812c3, 0xffccab67,
|
|
|
|
0xff034218, 0xff7db9a7, 0xff821048, 0xfffe4ab4,
|
|
|
|
0xff6fac98, 0xff941d27, 0xff5fe411, 0xfffbb283,
|
|
|
|
0xffd86e99, 0xff169162, 0xff71128c, 0xff39cab4,
|
|
|
|
0xffa7fe63, 0xff4c956b, 0xffbc22e0, 0xffb272e4,
|
|
|
|
0xff129f4a, 0xffe34513, 0xff3d3742, 0xffbd190a,
|
|
|
|
0xffb07222, 0xff2e23f8, 0xfff089d9, 0xffb35738,
|
|
|
|
0xffa86022, 0xff3340fe, 0xff95fe71, 0xff6a71df
|
|
|
|
};
|
|
|
|
SK_COMPILE_ASSERT((kExpectedWidth * kExpectedHeight)
|
|
|
|
== SK_ARRAY_COUNT(kExpectedPixels), array_size_mismatch);
|
2013-12-20 16:35:22 +00:00
|
|
|
|
|
|
|
DEF_TEST(WebP, reporter) {
|
|
|
|
const unsigned char encodedWebP[] = {
|
|
|
|
0x52, 0x49, 0x46, 0x46, 0x2c, 0x01, 0x00, 0x00, 0x57, 0x45, 0x42, 0x50,
|
|
|
|
0x56, 0x50, 0x38, 0x4c, 0x20, 0x01, 0x00, 0x00, 0x2f, 0x07, 0xc0, 0x01,
|
|
|
|
0x00, 0xff, 0x01, 0x45, 0x03, 0x00, 0xe2, 0xd5, 0xae, 0x60, 0x2b, 0xad,
|
|
|
|
0xd9, 0x68, 0x76, 0xb6, 0x8d, 0x6a, 0x1d, 0xc0, 0xe6, 0x19, 0xd6, 0x16,
|
|
|
|
0xb7, 0xb4, 0xef, 0xcf, 0xc3, 0x15, 0x6c, 0xb3, 0xbd, 0x77, 0x0d, 0x85,
|
|
|
|
0x6d, 0x1b, 0xa9, 0xb1, 0x2b, 0xdc, 0x3d, 0x83, 0xdb, 0x00, 0x00, 0xc8,
|
|
|
|
0x26, 0xe5, 0x01, 0x99, 0x8a, 0xd5, 0xdd, 0xfc, 0x82, 0xcd, 0xcd, 0x9a,
|
|
|
|
0x8c, 0x13, 0xcc, 0x1b, 0xba, 0xf5, 0x05, 0xdb, 0xee, 0x6a, 0xdb, 0x38,
|
|
|
|
0x60, 0xfe, 0x43, 0x2c, 0xd4, 0x6a, 0x99, 0x4d, 0xc6, 0xc0, 0xd3, 0x28,
|
|
|
|
0x1b, 0xc1, 0xb1, 0x17, 0x4e, 0x43, 0x0e, 0x3d, 0x27, 0xe9, 0xe4, 0x84,
|
|
|
|
0x4f, 0x24, 0x62, 0x69, 0x85, 0x43, 0x8d, 0xc2, 0x04, 0x00, 0x07, 0x59,
|
|
|
|
0x60, 0xfd, 0x8b, 0x4d, 0x60, 0x32, 0x72, 0xcf, 0x88, 0x0c, 0x2f, 0x2f,
|
|
|
|
0xad, 0x62, 0xbd, 0x27, 0x09, 0x16, 0x70, 0x78, 0x6c, 0xd9, 0x82, 0xef,
|
|
|
|
0x1a, 0xa2, 0xcc, 0xf0, 0xf1, 0x6f, 0xd8, 0x78, 0x2e, 0x39, 0xa1, 0xcf,
|
|
|
|
0x14, 0x4b, 0x89, 0xb4, 0x1b, 0x48, 0x15, 0x7c, 0x48, 0x6f, 0x8c, 0x20,
|
|
|
|
0xb7, 0x00, 0xcf, 0xfc, 0xdb, 0xd0, 0xe9, 0xe7, 0x42, 0x09, 0xa4, 0x03,
|
|
|
|
0x40, 0xac, 0xda, 0x40, 0x01, 0x00, 0x5f, 0xa1, 0x3d, 0x64, 0xe1, 0xf4,
|
|
|
|
0x03, 0x45, 0x29, 0xe0, 0xe2, 0x4a, 0xc3, 0xa2, 0xe8, 0xe0, 0x25, 0x12,
|
|
|
|
0x74, 0xc6, 0xe8, 0xfb, 0x93, 0x4f, 0x9f, 0x5e, 0xc0, 0xa6, 0x91, 0x1b,
|
|
|
|
0xa4, 0x24, 0x82, 0xc3, 0x61, 0x07, 0x4c, 0x49, 0x4f, 0x53, 0xae, 0x5f,
|
|
|
|
0x5d, 0x39, 0x36, 0xc0, 0x5b, 0x57, 0x54, 0x60, 0x10, 0x00, 0x00, 0xd1,
|
|
|
|
0x68, 0xb6, 0x6d, 0xdb, 0x36, 0x22, 0xfa, 0x1f, 0x35, 0x75, 0x22, 0xec,
|
|
|
|
0x31, 0xbc, 0x5d, 0x8f, 0x87, 0x53, 0xa2, 0x05, 0x8c, 0x2f, 0xcd, 0xa8,
|
|
|
|
0xa7, 0xf3, 0xa3, 0xbd, 0x83, 0x8b, 0x2a, 0xc8, 0x58, 0xf5, 0xac, 0x80,
|
|
|
|
0xe3, 0xfe, 0x66, 0xa4, 0x7c, 0x1b, 0x6c, 0xd1, 0xa9, 0xd8, 0x14, 0xd0,
|
|
|
|
0xc5, 0xb5, 0x39, 0x71, 0x97, 0x19, 0x19, 0x1b
|
|
|
|
};
|
|
|
|
SkAutoDataUnref encoded(SkData::NewWithCopy(encodedWebP,
|
|
|
|
sizeof(encodedWebP)));
|
|
|
|
SkBitmap bm;
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
2015-01-08 02:04:45 +00:00
|
|
|
bool success = SkInstallDiscardablePixelRef(encoded, &bm);
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
2013-12-20 16:35:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, success);
|
|
|
|
if (!success) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkAutoLockPixels alp(bm);
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
2014-01-03 07:01:45 +00:00
|
|
|
bool rightSize = ((kExpectedWidth == bm.width())
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
&& (kExpectedHeight == bm.height()));
|
2013-12-20 16:35:22 +00:00
|
|
|
REPORTER_ASSERT(reporter, rightSize);
|
|
|
|
if (rightSize) {
|
|
|
|
bool error = false;
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
const SkColor* correctPixel = kExpectedPixels;
|
2013-12-20 16:35:22 +00:00
|
|
|
for (int y = 0; y < bm.height(); ++y) {
|
|
|
|
for (int x = 0; x < bm.width(); ++x) {
|
|
|
|
error |= (*correctPixel != bm.getColor(x, y));
|
|
|
|
++correctPixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, !error);
|
|
|
|
}
|
|
|
|
}
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// example of how Android will do this inside their BitmapFactory
|
|
|
|
static SkPixelRef* install_pixel_ref(SkBitmap* bitmap,
|
|
|
|
SkStreamRewindable* stream,
|
|
|
|
int sampleSize, bool ditherImage) {
|
|
|
|
SkASSERT(bitmap != NULL);
|
|
|
|
SkASSERT(stream != NULL);
|
|
|
|
SkASSERT(stream->rewind());
|
2014-02-11 18:21:45 +00:00
|
|
|
SkColorType colorType = bitmap->colorType();
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
SkDecodingImageGenerator::Options opts(sampleSize, ditherImage, colorType);
|
2014-05-23 20:25:15 +00:00
|
|
|
if (SkInstallDiscardablePixelRef(
|
|
|
|
SkDecodingImageGenerator::Create(stream, opts), bitmap)) {
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
return bitmap->pixelRef();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* A test for the SkDecodingImageGenerator::Create and
|
|
|
|
* SkInstallDiscardablePixelRef functions.
|
|
|
|
*/
|
|
|
|
DEF_TEST(ImprovedBitmapFactory, reporter) {
|
2014-07-01 19:35:49 +00:00
|
|
|
SkString pngFilename = GetResourcePath("randPixels.png");
|
2015-01-21 20:09:53 +00:00
|
|
|
SkAutoTDelete<SkStreamRewindable> stream(SkStream::NewFromFile(pngFilename.c_str()));
|
2014-07-01 19:35:49 +00:00
|
|
|
if (sk_exists(pngFilename.c_str())) {
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
SkBitmap bm;
|
2014-05-30 13:26:10 +00:00
|
|
|
SkAssertResult(bm.setInfo(SkImageInfo::MakeN32Premul(1, 1)));
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2014-09-05 20:34:00 +00:00
|
|
|
install_pixel_ref(&bm, stream.detach(), 1, true));
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
SkAutoLockPixels alp(bm);
|
2014-09-05 20:34:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, bm.getPixels());
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
|
|
|
|
static inline bool check_rounding(int value, int dividend, int divisor) {
|
2014-05-09 18:08:24 +00:00
|
|
|
// returns true if the value is greater than floor(dividend/divisor)
|
|
|
|
// and less than SkNextPow2(ceil(dividend - divisor))
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
return (((divisor * value) > (dividend - divisor))
|
2014-05-09 18:08:24 +00:00
|
|
|
&& value <= SkNextPow2(((dividend - 1) / divisor) + 1));
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
}
|
|
|
|
#endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
|
|
|
|
|
|
|
|
|
|
|
|
#if SK_PMCOLOR_BYTE_ORDER(B,G,R,A)
|
|
|
|
#define kBackwards_SkColorType kRGBA_8888_SkColorType
|
|
|
|
#elif SK_PMCOLOR_BYTE_ORDER(R,G,B,A)
|
|
|
|
#define kBackwards_SkColorType kBGRA_8888_SkColorType
|
|
|
|
#else
|
|
|
|
#error "SK_*32_SHFIT values must correspond to BGRA or RGBA byte order"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline const char* SkColorType_to_string(SkColorType colorType) {
|
|
|
|
switch(colorType) {
|
|
|
|
case kAlpha_8_SkColorType: return "Alpha_8";
|
|
|
|
case kRGB_565_SkColorType: return "RGB_565";
|
|
|
|
case kARGB_4444_SkColorType: return "ARGB_4444";
|
2014-04-11 17:15:40 +00:00
|
|
|
case kN32_SkColorType: return "N32";
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
case kBackwards_SkColorType: return "Backwards";
|
|
|
|
case kIndex_8_SkColorType: return "Index_8";
|
|
|
|
default: return "ERROR";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 14:58:10 +00:00
|
|
|
static inline const char* options_colorType(
|
|
|
|
const SkDecodingImageGenerator::Options& opts) {
|
|
|
|
if (opts.fUseRequestedColorType) {
|
|
|
|
return SkColorType_to_string(opts.fRequestedColorType);
|
|
|
|
} else {
|
|
|
|
return "(none)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char* yn(bool value) {
|
|
|
|
if (value) {
|
|
|
|
return "yes";
|
|
|
|
} else {
|
|
|
|
return "no";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
/**
|
|
|
|
* Given either a SkStream or a SkData, try to decode the encoded
|
|
|
|
* image using the specified options and report errors.
|
|
|
|
*/
|
|
|
|
static void test_options(skiatest::Reporter* reporter,
|
|
|
|
const SkDecodingImageGenerator::Options& opts,
|
|
|
|
SkStreamRewindable* encodedStream,
|
|
|
|
SkData* encodedData,
|
|
|
|
bool useData,
|
|
|
|
const SkString& path) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bool success = false;
|
|
|
|
if (useData) {
|
|
|
|
if (NULL == encodedData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
success = SkInstallDiscardablePixelRef(
|
2014-05-27 14:14:22 +00:00
|
|
|
SkDecodingImageGenerator::Create(encodedData, opts), &bm);
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
} else {
|
|
|
|
if (NULL == encodedStream) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
success = SkInstallDiscardablePixelRef(
|
2014-05-27 14:14:22 +00:00
|
|
|
SkDecodingImageGenerator::Create(encodedStream->duplicate(), opts), &bm);
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
}
|
|
|
|
if (!success) {
|
|
|
|
if (opts.fUseRequestedColorType
|
|
|
|
&& (kARGB_4444_SkColorType == opts.fRequestedColorType)) {
|
|
|
|
return; // Ignore known conversion inabilities.
|
|
|
|
}
|
|
|
|
// If we get here, it's a failure and we will need more
|
|
|
|
// information about why it failed.
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "Bounds decode failed [sampleSize=%d dither=%s "
|
|
|
|
"colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
|
|
|
|
options_colorType(opts), path.c_str());
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_UNIX)
|
|
|
|
// Android is the only system that use Skia's image decoders in
|
|
|
|
// production. For now, we'll only verify that samplesize works
|
|
|
|
// on systems where it already is known to work.
|
|
|
|
REPORTER_ASSERT(reporter, check_rounding(bm.height(), kExpectedHeight,
|
|
|
|
opts.fSampleSize));
|
|
|
|
REPORTER_ASSERT(reporter, check_rounding(bm.width(), kExpectedWidth,
|
|
|
|
opts.fSampleSize));
|
2014-05-09 18:08:24 +00:00
|
|
|
// The ImageDecoder API doesn't guarantee that SampleSize does
|
|
|
|
// anything at all, but the decoders that this test excercises all
|
|
|
|
// produce an output size in the following range:
|
|
|
|
// (((sample_size * out_size) > (in_size - sample_size))
|
|
|
|
// && out_size <= SkNextPow2(((in_size - 1) / sample_size) + 1));
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
#endif // SK_BUILD_FOR_ANDROID || SK_BUILD_FOR_UNIX
|
|
|
|
SkAutoLockPixels alp(bm);
|
|
|
|
if (bm.getPixels() == NULL) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "Pixel decode failed [sampleSize=%d dither=%s "
|
|
|
|
"colorType=%s %s]", opts.fSampleSize, yn(opts.fDitherImage),
|
|
|
|
options_colorType(opts), path.c_str());
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-13 00:40:00 +00:00
|
|
|
SkColorType requestedColorType = opts.fRequestedColorType;
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
(!opts.fUseRequestedColorType)
|
2014-06-13 00:40:00 +00:00
|
|
|
|| (bm.colorType() == requestedColorType));
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
|
|
|
|
// Condition under which we should check the decoding results:
|
2014-06-13 00:40:00 +00:00
|
|
|
if ((kN32_SkColorType == bm.colorType())
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
&& (!path.endsWith(".jpg")) // lossy
|
|
|
|
&& (opts.fSampleSize == 1)) { // scaled
|
|
|
|
const SkColor* correctPixels = kExpectedPixels;
|
|
|
|
SkASSERT(bm.height() == kExpectedHeight);
|
|
|
|
SkASSERT(bm.width() == kExpectedWidth);
|
|
|
|
int pixelErrors = 0;
|
|
|
|
for (int y = 0; y < bm.height(); ++y) {
|
|
|
|
for (int x = 0; x < bm.width(); ++x) {
|
|
|
|
if (*correctPixels != bm.getColor(x, y)) {
|
|
|
|
++pixelErrors;
|
|
|
|
}
|
|
|
|
++correctPixels;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pixelErrors != 0) {
|
2014-01-10 14:58:10 +00:00
|
|
|
ERRORF(reporter, "Pixel-level mismatch (%d of %d) "
|
|
|
|
"[sampleSize=%d dither=%s colorType=%s %s]",
|
|
|
|
pixelErrors, kExpectedHeight * kExpectedWidth,
|
|
|
|
opts.fSampleSize, yn(opts.fDitherImage),
|
|
|
|
options_colorType(opts), path.c_str());
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SkDecodingImageGenerator has an Options struct which lets the
|
|
|
|
* client of the generator set sample size, dithering, and bitmap
|
|
|
|
* config. This test loops through many possible options and tries
|
|
|
|
* them on a set of 5 small encoded images (each in a different
|
|
|
|
* format). We test both SkData and SkStreamRewindable decoding.
|
|
|
|
*/
|
|
|
|
DEF_TEST(ImageDecoderOptions, reporter) {
|
|
|
|
const char* files[] = {
|
|
|
|
"randPixels.bmp",
|
|
|
|
"randPixels.jpg",
|
|
|
|
"randPixels.png",
|
|
|
|
"randPixels.webp",
|
|
|
|
#if !defined(SK_BUILD_FOR_WIN)
|
|
|
|
// TODO(halcanary): Find out why this fails sometimes.
|
|
|
|
"randPixels.gif",
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2014-06-18 21:32:48 +00:00
|
|
|
SkString resourceDir = GetResourcePath();
|
2014-05-09 18:08:24 +00:00
|
|
|
if (!sk_exists(resourceDir.c_str())) {
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int scaleList[] = {1, 2, 3, 4};
|
|
|
|
bool ditherList[] = {true, false};
|
|
|
|
SkColorType colorList[] = {
|
|
|
|
kAlpha_8_SkColorType,
|
|
|
|
kRGB_565_SkColorType,
|
|
|
|
kARGB_4444_SkColorType, // Most decoders will fail on 4444.
|
2014-04-11 17:15:40 +00:00
|
|
|
kN32_SkColorType
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
// Note that indexed color is left out of the list. Lazy
|
|
|
|
// decoding doesn't do indexed color.
|
|
|
|
};
|
|
|
|
const bool useDataList[] = {true, false};
|
|
|
|
|
|
|
|
for (size_t fidx = 0; fidx < SK_ARRAY_COUNT(files); ++fidx) {
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString path = SkOSPath::Join(resourceDir.c_str(), files[fidx]);
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
if (!sk_exists(path.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoDataUnref encodedData(SkData::NewFromFileName(path.c_str()));
|
|
|
|
REPORTER_ASSERT(reporter, encodedData.get() != NULL);
|
2015-01-21 20:09:53 +00:00
|
|
|
SkAutoTDelete<SkStreamRewindable> encodedStream(
|
Add Options to SkDecodingImageGenerator, simplify API.
Motivation: We want to remove redundant classes from Skia. To
that end we want to remove SkImageRef and its subclasses and
replace their uses with SkDiscardablePixelRef +
SkDecodingImageGenerator. Since Android uses SkImageRef, we need
to make sure that SkDecodingImageGenerator allows all of the
settings that Android exposes in BitmapFactory.Options.
To that end, we have created an Options struct for the
SkDecodingImageGenerator which lets the client of the generator set
sample size, dithering, and bitmap config.
We have made the SkDecodingImageGenerator constructor private
and replaced the SkDecodingImageGenerator::Install functions
with a SkDecodingImageGenerator::Create functions (one for
SkData and one for SkStream) which now take a
SkDecodingImageGenerator::Options struct.
Also added a ImageDecoderOptions test which loops through a list
of sets of options and tries them on a set of 5 small encoded
images.
Also updated several users of SkDecodingImageGenerator::Install to
follow new call signature - gm/factory.cpp, LazyDecodeBitmap.cpp,
and PictureTest.cpp, CachedDecodingPixelRefTest.cpp.
We also added a new ImprovedBitmapFactory Test which simulates the
exact function that Android will need to modify to use this,
installPixelRef() in BitmapFactory.
R=reed@google.com, scroggo@google.com
Committed: https://code.google.com/p/skia/source/detail?r=12744
Review URL: https://codereview.chromium.org/93703004
git-svn-id: http://skia.googlecode.com/svn/trunk@12855 2bbb7eff-a529-9590-31e7-b0007b416f81
2014-01-02 13:15:13 +00:00
|
|
|
SkStream::NewFromFile(path.c_str()));
|
|
|
|
REPORTER_ASSERT(reporter, encodedStream.get() != NULL);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(scaleList); ++i) {
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(ditherList); ++j) {
|
|
|
|
for (size_t m = 0; m < SK_ARRAY_COUNT(useDataList); ++m) {
|
|
|
|
for (size_t k = 0; k < SK_ARRAY_COUNT(colorList); ++k) {
|
|
|
|
SkDecodingImageGenerator::Options opts(scaleList[i],
|
|
|
|
ditherList[j],
|
|
|
|
colorList[k]);
|
|
|
|
test_options(reporter, opts, encodedStream, encodedData,
|
|
|
|
useDataList[m], path);
|
|
|
|
|
|
|
|
}
|
|
|
|
SkDecodingImageGenerator::Options options(scaleList[i],
|
|
|
|
ditherList[j]);
|
|
|
|
test_options(reporter, options, encodedStream, encodedData,
|
|
|
|
useDataList[m], path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-28 15:23:55 +00:00
|
|
|
|
|
|
|
DEF_TEST(DiscardablePixelRef_SecondLockColorTableCheck, r) {
|
|
|
|
SkString resourceDir = GetResourcePath();
|
2014-07-29 02:26:58 +00:00
|
|
|
SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.gif");
|
2014-07-28 15:23:55 +00:00
|
|
|
if (!sk_exists(path.c_str())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkAutoDataUnref encoded(SkData::NewFromFileName(path.c_str()));
|
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!SkInstallDiscardablePixelRef(
|
|
|
|
SkDecodingImageGenerator::Create(
|
|
|
|
encoded, SkDecodingImageGenerator::Options()), &bitmap)) {
|
2014-07-28 17:54:26 +00:00
|
|
|
#ifndef SK_BUILD_FOR_WIN
|
2014-07-28 15:23:55 +00:00
|
|
|
ERRORF(r, "SkInstallDiscardablePixelRef [randPixels.gif] failed.");
|
2014-07-28 17:54:26 +00:00
|
|
|
#endif
|
2014-07-28 15:23:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-07-28 15:56:35 +00:00
|
|
|
if (kIndex_8_SkColorType != bitmap.colorType()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-28 15:23:55 +00:00
|
|
|
{
|
|
|
|
SkAutoLockPixels alp(bitmap);
|
|
|
|
REPORTER_ASSERT(r, bitmap.getColorTable() && "first pass");
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SkAutoLockPixels alp(bitmap);
|
|
|
|
REPORTER_ASSERT(r, bitmap.getColorTable() && "second pass");
|
|
|
|
}
|
|
|
|
}
|
2014-08-01 17:31:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
namespace {
|
|
|
|
class SingleAllocator : public SkBitmap::Allocator {
|
|
|
|
public:
|
|
|
|
SingleAllocator(void* p, size_t s) : fPixels(p), fSize(s) { }
|
|
|
|
~SingleAllocator() {}
|
|
|
|
// If the pixels in fPixels are big enough, use them.
|
2015-03-26 01:17:31 +00:00
|
|
|
bool allocPixelRef(SkBitmap* bm, SkColorTable* ct) override {
|
2014-08-01 17:31:48 +00:00
|
|
|
SkASSERT(bm);
|
|
|
|
if (bm->info().getSafeSize(bm->rowBytes()) <= fSize) {
|
|
|
|
bm->setPixels(fPixels, ct);
|
|
|
|
fPixels = NULL;
|
|
|
|
fSize = 0;
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-02 19:50:45 +00:00
|
|
|
return bm->tryAllocPixels(NULL, ct);
|
2014-08-01 17:31:48 +00:00
|
|
|
}
|
|
|
|
bool ready() { return fPixels != NULL; }
|
|
|
|
private:
|
|
|
|
void* fPixels;
|
|
|
|
size_t fSize;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
/* This tests for a bug in libjpeg where INT32 is typedefed to long
|
|
|
|
and memory can be written to outside of the array. */
|
|
|
|
DEF_TEST(ImageDecoding_JpegOverwrite, r) {
|
|
|
|
SkString resourceDir = GetResourcePath();
|
|
|
|
SkString path = SkOSPath::Join(resourceDir.c_str(), "randPixels.jpg");
|
2015-01-21 20:09:53 +00:00
|
|
|
SkAutoTDelete<SkStreamAsset> stream(
|
2014-08-01 17:31:48 +00:00
|
|
|
SkStream::NewFromFile(path.c_str()));
|
|
|
|
if (!stream.get()) {
|
|
|
|
SkDebugf("\nPath '%s' missing.\n", path.c_str());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
|
|
|
|
if (NULL == decoder.get()) {
|
|
|
|
ERRORF(r, "\nSkImageDecoder::Factory failed.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SkAssertResult(stream->rewind());
|
|
|
|
|
|
|
|
static const uint16_t sentinal = 0xBEEF;
|
|
|
|
static const int pixelCount = 16;
|
|
|
|
SkAutoTMalloc<uint16_t> pixels(pixelCount + 1);
|
|
|
|
// pixels.get() should be 4-byte aligned.
|
|
|
|
// This is necessary to reproduce the bug.
|
|
|
|
|
|
|
|
pixels[pixelCount] = sentinal; // This value should not be changed.
|
|
|
|
|
|
|
|
SkAutoTUnref<SingleAllocator> allocator(
|
|
|
|
SkNEW_ARGS(SingleAllocator,
|
|
|
|
((void*)pixels.get(), sizeof(uint16_t) * pixelCount)));
|
|
|
|
decoder->setAllocator(allocator);
|
|
|
|
decoder->setSampleSize(2);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bool success = decoder->decode(stream, &bitmap, kRGB_565_SkColorType,
|
2014-10-22 19:07:00 +00:00
|
|
|
SkImageDecoder::kDecodePixels_Mode) != SkImageDecoder::kFailure;
|
2014-08-01 17:31:48 +00:00
|
|
|
REPORTER_ASSERT(r, success);
|
|
|
|
REPORTER_ASSERT(r, !allocator->ready()); // Decoder used correct memory
|
|
|
|
REPORTER_ASSERT(r, sentinal == pixels[pixelCount]);
|
|
|
|
}
|