2015-09-08 22:35:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBitmapRegionSampler.h"
|
2015-10-12 17:24:38 +00:00
|
|
|
#include "SkCodecPriv.h"
|
2015-09-08 22:35:32 +00:00
|
|
|
|
|
|
|
SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
|
|
|
|
int height)
|
|
|
|
: INHERITED(width, height)
|
|
|
|
, fDecoder(decoder)
|
|
|
|
{}
|
|
|
|
|
2015-10-27 19:50:25 +00:00
|
|
|
bool SkBitmapRegionSampler::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
|
|
|
|
const SkIRect& desiredSubset, int sampleSize, SkColorType colorType, bool requireUnpremul) {
|
2015-09-08 22:35:32 +00:00
|
|
|
fDecoder->setDitherImage(true);
|
|
|
|
fDecoder->setPreferQualityOverSpeed(false);
|
|
|
|
fDecoder->setRequireUnpremultipliedColors(false);
|
|
|
|
fDecoder->setSampleSize(sampleSize);
|
2015-10-27 19:50:25 +00:00
|
|
|
fDecoder->setAllocator(allocator);
|
2015-09-08 22:35:32 +00:00
|
|
|
|
|
|
|
// kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder
|
2015-10-27 19:50:25 +00:00
|
|
|
if (kGray_8_SkColorType == colorType) {
|
|
|
|
colorType = kAlpha_8_SkColorType;
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 19:50:25 +00:00
|
|
|
bool result = fDecoder->decodeSubset(bitmap, desiredSubset, colorType);
|
|
|
|
fDecoder->setAllocator(nullptr);
|
|
|
|
return result;
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|