Allow setting an SkColorSpace on SkAnimatedImage
Add a new constructor which merges the SkISize scaledSize with the SkImageInfo. This allows passing an SkColorSpace to the decode. Update the test to call the new API. Bug: b/123301872 Change-Id: I9fd89198e97ac9b8e6dc9fcfe89ed38913a0fe69 Reviewed-on: https://skia-review.googlesource.com/c/189303 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
This commit is contained in:
parent
9320d579e5
commit
8546335d2d
@ -22,6 +22,19 @@ class SkPicture;
|
||||
*/
|
||||
class SK_API SkAnimatedImage : public SkDrawable {
|
||||
public:
|
||||
/**
|
||||
* Create an SkAnimatedImage from the SkAndroidCodec.
|
||||
*
|
||||
* Returns null on failure to allocate pixels. On success, this will
|
||||
* decode the first frame.
|
||||
*
|
||||
* @param info Width and height may require scaling.
|
||||
* @param cropRect Rectangle to crop to after scaling.
|
||||
* @param postProcess Picture to apply after scaling and cropping.
|
||||
*/
|
||||
static sk_sp<SkAnimatedImage> Make(std::unique_ptr<SkAndroidCodec>,
|
||||
const SkImageInfo& info, SkIRect cropRect, sk_sp<SkPicture> postProcess);
|
||||
|
||||
/**
|
||||
* Create an SkAnimatedImage from the SkAndroidCodec.
|
||||
*
|
||||
|
@ -22,14 +22,24 @@ sk_sp<SkAnimatedImage> SkAnimatedImage::Make(std::unique_ptr<SkAndroidCodec> cod
|
||||
if (!codec) {
|
||||
return nullptr;
|
||||
}
|
||||
auto info = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height());
|
||||
return Make(std::move(codec), info, cropRect, std::move(postProcess));
|
||||
}
|
||||
|
||||
SkISize decodeSize = scaledSize;
|
||||
auto decodeInfo = codec->getInfo();
|
||||
if (codec->getEncodedFormat() == SkEncodedImageFormat::kWEBP
|
||||
&& scaledSize.width() < decodeInfo.width()
|
||||
&& scaledSize.height() < decodeInfo.height()) {
|
||||
// libwebp can decode to arbitrary smaller sizes.
|
||||
decodeInfo = decodeInfo.makeWH(decodeSize.width(), decodeSize.height());
|
||||
sk_sp<SkAnimatedImage> SkAnimatedImage::Make(std::unique_ptr<SkAndroidCodec> codec,
|
||||
const SkImageInfo& requestedInfo, SkIRect cropRect, sk_sp<SkPicture> postProcess) {
|
||||
if (!codec) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto scaledSize = requestedInfo.dimensions();
|
||||
auto decodeInfo = requestedInfo;
|
||||
if (codec->getEncodedFormat() != SkEncodedImageFormat::kWEBP
|
||||
|| scaledSize.width() >= decodeInfo.width()
|
||||
|| scaledSize.height() >= decodeInfo.height()) {
|
||||
// Only libwebp can decode to arbitrary smaller sizes.
|
||||
auto dims = codec->getInfo().dimensions();
|
||||
decodeInfo = decodeInfo.makeWH(dims.width(), dims.height());
|
||||
}
|
||||
|
||||
auto image = sk_sp<SkAnimatedImage>(new SkAnimatedImage(std::move(codec), scaledSize,
|
||||
|
@ -47,10 +47,10 @@ DEF_TEST(AnimatedImage_scaled, r) {
|
||||
}
|
||||
|
||||
// Force the drawable follow its special case that requires scaling.
|
||||
auto size = codec->getInfo().dimensions();
|
||||
size.set(size.width() - 5, size.height() - 5);
|
||||
auto rect = SkIRect::MakeSize(size);
|
||||
auto image = SkAnimatedImage::Make(std::move(codec), size, rect, nullptr);
|
||||
auto info = codec->getInfo();
|
||||
info = info.makeWH(info.width() - 5, info.height() - 5);
|
||||
auto rect = info.bounds();
|
||||
auto image = SkAnimatedImage::Make(std::move(codec), info, rect, nullptr);
|
||||
if (!image) {
|
||||
ERRORF(r, "Failed to create animated image for %s", file);
|
||||
return;
|
||||
@ -59,12 +59,12 @@ DEF_TEST(AnimatedImage_scaled, r) {
|
||||
// Clear a bitmap to non-transparent and draw to it. pixels that are transparent
|
||||
// in the image should not replace the original non-transparent color.
|
||||
SkBitmap bm;
|
||||
bm.allocPixels(SkImageInfo::MakeN32Premul(size.width(), size.height()));
|
||||
bm.allocPixels(SkImageInfo::MakeN32Premul(info.width(), info.height()));
|
||||
bm.eraseColor(SK_ColorBLUE);
|
||||
SkCanvas canvas(bm);
|
||||
image->draw(&canvas);
|
||||
for (int i = 0; i < size.width(); ++i)
|
||||
for (int j = 0; j < size.height(); ++j) {
|
||||
for (int i = 0; i < info.width(); ++i)
|
||||
for (int j = 0; j < info.height(); ++j) {
|
||||
if (*bm.getAddr32(i, j) == SK_ColorTRANSPARENT) {
|
||||
ERRORF(r, "Erased color underneath!");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user