skia2/tools/SkBitmapRegionSampler.cpp
msarett 35e5d1b449 Refactor SkBitmapRegionDecoderInterface for Android
The result SkBitmap, the pixel allocator, and the alpha
preference need to be communicated from the client to
the region decoder.

BUG=skia:

Review URL: https://codereview.chromium.org/1418093006
2015-10-27 12:50:25 -07:00

34 lines
1.1 KiB
C++

/*
* 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"
#include "SkCodecPriv.h"
SkBitmapRegionSampler::SkBitmapRegionSampler(SkImageDecoder* decoder, int width,
int height)
: INHERITED(width, height)
, fDecoder(decoder)
{}
bool SkBitmapRegionSampler::decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator,
const SkIRect& desiredSubset, int sampleSize, SkColorType colorType, bool requireUnpremul) {
fDecoder->setDitherImage(true);
fDecoder->setPreferQualityOverSpeed(false);
fDecoder->setRequireUnpremultipliedColors(false);
fDecoder->setSampleSize(sampleSize);
fDecoder->setAllocator(allocator);
// kAlpha8 is the legacy representation of kGray8 used by SkImageDecoder
if (kGray_8_SkColorType == colorType) {
colorType = kAlpha_8_SkColorType;
}
bool result = fDecoder->decodeSubset(bitmap, desiredSubset, colorType);
fDecoder->setAllocator(nullptr);
return result;
}