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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkBitmapRegionDecoder_DEFINED
|
|
|
|
#define SkBitmapRegionDecoder_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/android/SkBRDAllocator.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkEncodedImageFormat.h"
|
|
|
|
#include "include/core/SkStream.h"
|
2015-09-08 22:35:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This class aims to provide an interface to test multiple implementations of
|
|
|
|
* SkBitmapRegionDecoder.
|
|
|
|
*/
|
2017-09-20 19:51:08 +00:00
|
|
|
class SK_API SkBitmapRegionDecoder {
|
2015-09-08 22:35:32 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
enum Strategy {
|
2015-10-22 14:29:19 +00:00
|
|
|
kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsetting
|
2015-09-08 22:35:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2015-10-22 14:29:19 +00:00
|
|
|
* @param data Refs the data while this object exists, unrefs on destruction
|
2015-09-08 22:35:32 +00:00
|
|
|
* @param strategy Strategy used for scaling and subsetting
|
2015-10-22 14:29:19 +00:00
|
|
|
* @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
|
2015-09-08 22:35:32 +00:00
|
|
|
*/
|
2016-09-12 19:01:44 +00:00
|
|
|
static SkBitmapRegionDecoder* Create(sk_sp<SkData>, Strategy strategy);
|
2015-09-08 22:35:32 +00:00
|
|
|
|
2015-10-27 20:12:59 +00:00
|
|
|
/*
|
|
|
|
* @param stream Takes ownership of the stream
|
|
|
|
* @param strategy Strategy used for scaling and subsetting
|
|
|
|
* @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
|
|
|
|
*/
|
2015-11-06 16:56:32 +00:00
|
|
|
static SkBitmapRegionDecoder* Create(
|
2015-10-27 20:12:59 +00:00
|
|
|
SkStreamRewindable* stream, Strategy strategy);
|
|
|
|
|
2015-09-08 22:35:32 +00:00
|
|
|
/*
|
|
|
|
* Decode a scaled region of the encoded image stream
|
|
|
|
*
|
2015-10-27 19:50:25 +00:00
|
|
|
* @param bitmap Container for decoded pixels. It is assumed that the pixels
|
|
|
|
* are initially unallocated and will be allocated by this function.
|
|
|
|
* @param allocator Allocator for the pixels. If this is NULL, the default
|
|
|
|
* allocator (HeapAllocator) will be used.
|
|
|
|
* @param desiredSubset Subset of the original image to decode.
|
|
|
|
* @param sampleSize An integer downscaling factor for the decode.
|
|
|
|
* @param colorType Preferred output colorType.
|
|
|
|
* New implementations should return NULL if they do not support
|
|
|
|
* decoding to this color type.
|
|
|
|
* The old kOriginal_Strategy will decode to a default color type
|
|
|
|
* 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.
|
2017-04-11 13:51:32 +00:00
|
|
|
* @param prefColorSpace If non-null and supported, this is the color space that we will
|
|
|
|
* decode into. Otherwise, we will choose a default.
|
2015-10-27 19:50:25 +00:00
|
|
|
*
|
2015-09-08 22:35:32 +00:00
|
|
|
*/
|
2015-11-11 21:30:43 +00:00
|
|
|
virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
|
2015-10-27 19:50:25 +00:00
|
|
|
const SkIRect& desiredSubset, int sampleSize,
|
2017-04-11 13:51:32 +00:00
|
|
|
SkColorType colorType, bool requireUnpremul,
|
|
|
|
sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
|
2015-09-08 22:35:32 +00:00
|
|
|
|
2016-11-30 22:07:59 +00:00
|
|
|
virtual SkEncodedImageFormat getEncodedFormat() = 0;
|
2015-10-27 20:12:59 +00:00
|
|
|
|
2017-04-14 13:23:45 +00:00
|
|
|
virtual SkColorType computeOutputColorType(SkColorType requestedColorType) = 0;
|
|
|
|
|
|
|
|
virtual sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
|
|
|
|
sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
|
|
|
|
|
|
|
|
|
2015-09-08 22:35:32 +00:00
|
|
|
int width() const { return fWidth; }
|
|
|
|
int height() const { return fHeight; }
|
|
|
|
|
2015-11-06 16:56:32 +00:00
|
|
|
virtual ~SkBitmapRegionDecoder() {}
|
2015-09-08 22:35:32 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-11-06 16:56:32 +00:00
|
|
|
SkBitmapRegionDecoder(int width, int height)
|
2015-09-08 22:35:32 +00:00
|
|
|
: fWidth(width)
|
|
|
|
, fHeight(height)
|
|
|
|
{}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const int fWidth;
|
|
|
|
const int fHeight;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|