blob: b5a4c813bbcf11c6ba1bb6f3d63876f642eb6255 [file] [log] [blame]
msaretta5783ae2015-09-08 15:35:32 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkBitmapRegionDecoder_DEFINED
9#define SkBitmapRegionDecoder_DEFINED
10
11#include "SkBitmap.h"
msarettcb8d7192015-11-11 13:30:43 -080012#include "SkBRDAllocator.h"
Hal Canary1fcc4042016-11-30 17:07:59 -050013#include "SkEncodedImageFormat.h"
msaretta5783ae2015-09-08 15:35:32 -070014#include "SkStream.h"
15
16/*
17 * This class aims to provide an interface to test multiple implementations of
18 * SkBitmapRegionDecoder.
19 */
Derek Sollenberger2fbf1bc2017-09-20 15:51:08 -040020class SK_API SkBitmapRegionDecoder {
msaretta5783ae2015-09-08 15:35:32 -070021public:
22
23 enum Strategy {
msarett26ad17b2015-10-22 07:29:19 -070024 kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsetting
msaretta5783ae2015-09-08 15:35:32 -070025 };
26
27 /*
msarett26ad17b2015-10-22 07:29:19 -070028 * @param data Refs the data while this object exists, unrefs on destruction
msaretta5783ae2015-09-08 15:35:32 -070029 * @param strategy Strategy used for scaling and subsetting
msarett26ad17b2015-10-22 07:29:19 -070030 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
msaretta5783ae2015-09-08 15:35:32 -070031 */
reed42943c82016-09-12 12:01:44 -070032 static SkBitmapRegionDecoder* Create(sk_sp<SkData>, Strategy strategy);
msaretta5783ae2015-09-08 15:35:32 -070033
34 /*
msarett3f65e932015-10-27 13:12:59 -070035 * @param stream Takes ownership of the stream
36 * @param strategy Strategy used for scaling and subsetting
37 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure
38 */
msarett5cb48852015-11-06 08:56:32 -080039 static SkBitmapRegionDecoder* Create(
msarett3f65e932015-10-27 13:12:59 -070040 SkStreamRewindable* stream, Strategy strategy);
41
42 /*
msaretta5783ae2015-09-08 15:35:32 -070043 * Decode a scaled region of the encoded image stream
44 *
msarett35e5d1b2015-10-27 12:50:25 -070045 * @param bitmap Container for decoded pixels. It is assumed that the pixels
46 * are initially unallocated and will be allocated by this function.
47 * @param allocator Allocator for the pixels. If this is NULL, the default
48 * allocator (HeapAllocator) will be used.
49 * @param desiredSubset Subset of the original image to decode.
50 * @param sampleSize An integer downscaling factor for the decode.
51 * @param colorType Preferred output colorType.
52 * New implementations should return NULL if they do not support
53 * decoding to this color type.
54 * The old kOriginal_Strategy will decode to a default color type
55 * if this color type is unsupported.
56 * @param requireUnpremul If the image is not opaque, we will use this to determine the
57 * alpha type to use.
Matt Sarett68feef42017-04-11 09:51:32 -040058 * @param prefColorSpace If non-null and supported, this is the color space that we will
59 * decode into. Otherwise, we will choose a default.
msarett35e5d1b2015-10-27 12:50:25 -070060 *
msaretta5783ae2015-09-08 15:35:32 -070061 */
msarettcb8d7192015-11-11 13:30:43 -080062 virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
msarett35e5d1b2015-10-27 12:50:25 -070063 const SkIRect& desiredSubset, int sampleSize,
Matt Sarett68feef42017-04-11 09:51:32 -040064 SkColorType colorType, bool requireUnpremul,
65 sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
msaretta5783ae2015-09-08 15:35:32 -070066
Hal Canary1fcc4042016-11-30 17:07:59 -050067 virtual SkEncodedImageFormat getEncodedFormat() = 0;
msarett3f65e932015-10-27 13:12:59 -070068
Matt Sarett479366c2017-04-14 09:23:45 -040069 virtual SkColorType computeOutputColorType(SkColorType requestedColorType) = 0;
70
71 virtual sk_sp<SkColorSpace> computeOutputColorSpace(SkColorType outputColorType,
72 sk_sp<SkColorSpace> prefColorSpace = nullptr) = 0;
73
74
msaretta5783ae2015-09-08 15:35:32 -070075 int width() const { return fWidth; }
76 int height() const { return fHeight; }
77
msarett5cb48852015-11-06 08:56:32 -080078 virtual ~SkBitmapRegionDecoder() {}
msaretta5783ae2015-09-08 15:35:32 -070079
80protected:
81
msarett5cb48852015-11-06 08:56:32 -080082 SkBitmapRegionDecoder(int width, int height)
msaretta5783ae2015-09-08 15:35:32 -070083 : fWidth(width)
84 , fHeight(height)
85 {}
86
87private:
88 const int fWidth;
89 const int fHeight;
90};
91
92#endif