blob: 660aa0aefc98641c9161f0fc36a09f686053a7b6 [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 */
msarett5cb48852015-11-06 08:56:32 -080020class 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.
58 *
msaretta5783ae2015-09-08 15:35:32 -070059 */
msarettcb8d7192015-11-11 13:30:43 -080060 virtual bool decodeRegion(SkBitmap* bitmap, SkBRDAllocator* allocator,
msarett35e5d1b2015-10-27 12:50:25 -070061 const SkIRect& desiredSubset, int sampleSize,
62 SkColorType colorType, bool requireUnpremul) = 0;
msarett04965c62015-10-12 10:24:38 -070063 /*
64 * @param Requested destination color type
65 * @return true if we support the requested color type and false otherwise
66 */
67 virtual bool conversionSupported(SkColorType colorType) = 0;
msaretta5783ae2015-09-08 15:35:32 -070068
Hal Canary1fcc4042016-11-30 17:07:59 -050069 virtual SkEncodedImageFormat getEncodedFormat() = 0;
msarett3f65e932015-10-27 13:12:59 -070070
msaretta5783ae2015-09-08 15:35:32 -070071 int width() const { return fWidth; }
72 int height() const { return fHeight; }
73
msarett5cb48852015-11-06 08:56:32 -080074 virtual ~SkBitmapRegionDecoder() {}
msaretta5783ae2015-09-08 15:35:32 -070075
76protected:
77
msarett5cb48852015-11-06 08:56:32 -080078 SkBitmapRegionDecoder(int width, int height)
msaretta5783ae2015-09-08 15:35:32 -070079 : fWidth(width)
80 , fHeight(height)
81 {}
82
83private:
84 const int fWidth;
85 const int fHeight;
86};
87
88#endif