case kFullImage_Mode: {
SkBitmap bitmap;
if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, width, height),
- fSampleSize, colorType, false)) {
+ fSampleSize, colorType, false, SkColorSpace::MakeSRGB())) {
return "Cannot decode (full) region.";
}
alpha8_to_gray8(&bitmap);
const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2;
SkBitmap bitmap;
if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(decodeLeft,
- decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false)) {
+ decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false,
+ SkColorSpace::MakeSRGB())) {
return "Cannot decode region.";
}
* if this color type is unsupported.
* @param requireUnpremul If the image is not opaque, we will use this to determine the
* alpha type to use.
+ * @param prefColorSpace If non-null and supported, this is the color space that we will
+ * decode into. Otherwise, we will choose a default.
*
*/
virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize,
- SkColorType colorType, bool requireUnpremul) = 0;
+ SkColorType colorType, bool requireUnpremul,
+ sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
/*
* @param Requested destination color type
* @return true if we support the requested color type and false otherwise
SkAlphaType computeOutputAlphaType(bool requestedUnpremul);
/**
- * @param outputColorType Color type that the client will decode to
+ * @param outputColorType Color type that the client will decode to.
+ * @param prefColorSpace Preferred color space to decode to.
+ * This may not return |prefColorSpace| for a couple reasons.
+ * (1) Android Principles: 565 must be sRGB, F16 must be
+ * linear sRGB, transfer function must be parametric.
+ * (2) Codec Limitations: F16 requires a linear color space.
*
* Returns the appropriate color space to decode to.
*/
- sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType);
+ sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
+ sk_sp<SkColorSpace> prefColorSpace = nullptr);
/**
* Returns the dimensions of the scaled output image, for an input
bool SkBitmapRegionCodec::decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize, SkColorType prefColorType,
- bool requireUnpremul) {
+ bool requireUnpremul, sk_sp<SkColorSpace> prefColorSpace) {
// Fix the input sampleSize if necessary.
if (sampleSize < 1) {
// Create the image info for the decode
SkColorType dstColorType = fCodec->computeOutputColorType(prefColorType);
SkAlphaType dstAlphaType = fCodec->computeOutputAlphaType(requireUnpremul);
- sk_sp<SkColorSpace> dstColorSpace = fCodec->computeOutputColorSpace(dstColorType);
+ sk_sp<SkColorSpace> dstColorSpace = fCodec->computeOutputColorSpace(dstColorType,
+ prefColorSpace);
SkImageInfo decodeInfo = SkImageInfo::Make(scaledSize.width(), scaledSize.height(),
dstColorType, dstAlphaType, dstColorSpace);
bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
const SkIRect& desiredSubset, int sampleSize,
- SkColorType colorType, bool requireUnpremul) override;
+ SkColorType colorType, bool requireUnpremul,
+ sk_sp<SkColorSpace> prefColorSpace) override;
bool conversionSupported(SkColorType colorType) override;
return requestedUnpremul ? kUnpremul_SkAlphaType : kPremul_SkAlphaType;
}
-sk_sp<SkColorSpace> SkAndroidCodec::computeOutputColorSpace(SkColorType outputColorType) {
+sk_sp<SkColorSpace> SkAndroidCodec::computeOutputColorSpace(SkColorType outputColorType,
+ sk_sp<SkColorSpace> prefColorSpace) {
switch (outputColorType) {
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
case kIndex_8_SkColorType: {
- SkColorSpace* encodedSpace = fCodec->getInfo().colorSpace();
+ // If |prefColorSpace| is supported, choose it.
SkColorSpaceTransferFn fn;
+ if (prefColorSpace && prefColorSpace->isNumericalTransferFn(&fn)) {
+ return prefColorSpace;
+ }
+
+ SkColorSpace* encodedSpace = fCodec->getInfo().colorSpace();
if (encodedSpace->isNumericalTransferFn(&fn)) {
// Leave the pixels in the encoded color space. Color space conversion
// will be handled after decode time.
return SkColorSpace::MakeSRGB();
}
case kRGBA_F16_SkColorType:
+ // Note that |prefColorSpace| is ignored, F16 is always linear sRGB.
return SkColorSpace::MakeSRGBLinear();
case kRGB_565_SkColorType:
+ // Note that |prefColorSpace| is ignored, 565 is always sRGB.
return SkColorSpace::MakeSRGB();
default:
// Color correction not supported for kGray.