OLD | NEW |
| (Empty) |
1 /* | |
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" | |
12 #include "SkEncodedFormat.h" | |
13 #include "SkStream.h" | |
14 | |
15 /* | |
16 * This class aims to provide an interface to test multiple implementations of | |
17 * SkBitmapRegionDecoder. | |
18 */ | |
19 class SkBitmapRegionDecoder { | |
20 public: | |
21 | |
22 enum Strategy { | |
23 kCanvas_Strategy, // Draw to the canvas, uses SkCodec | |
24 kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsettin
g | |
25 }; | |
26 | |
27 /* | |
28 * @param data Refs the data while this object exists, unrefs on destruc
tion | |
29 * @param strategy Strategy used for scaling and subsetting | |
30 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on
failure | |
31 */ | |
32 static SkBitmapRegionDecoder* Create( | |
33 SkData* data, Strategy strategy); | |
34 | |
35 /* | |
36 * @param stream Takes ownership of the stream | |
37 * @param strategy Strategy used for scaling and subsetting | |
38 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on
failure | |
39 */ | |
40 static SkBitmapRegionDecoder* Create( | |
41 SkStreamRewindable* stream, Strategy strategy); | |
42 | |
43 /* | |
44 * Decode a scaled region of the encoded image stream | |
45 * | |
46 * @param bitmap Container for decoded pixels. It is assumed that
the pixels | |
47 * are initially unallocated and will be allocated by
this function. | |
48 * @param allocator Allocator for the pixels. If this is NULL, the de
fault | |
49 * allocator (HeapAllocator) will be used. | |
50 * @param desiredSubset Subset of the original image to decode. | |
51 * @param sampleSize An integer downscaling factor for the decode. | |
52 * @param colorType Preferred output colorType. | |
53 * New implementations should return NULL if they do
not support | |
54 * decoding to this color type. | |
55 * The old kOriginal_Strategy will decode to a defaul
t color type | |
56 * if this color type is unsupported. | |
57 * @param requireUnpremul If the image is not opaque, we will use this to de
termine the | |
58 * alpha type to use. | |
59 * | |
60 */ | |
61 virtual bool decodeRegion(SkBitmap* bitmap, SkBitmap::Allocator* allocator, | |
62 const SkIRect& desiredSubset, int sampleSize, | |
63 SkColorType colorType, bool requireUnpremul) = 0; | |
64 /* | |
65 * @param Requested destination color type | |
66 * @return true if we support the requested color type and false otherwise | |
67 */ | |
68 virtual bool conversionSupported(SkColorType colorType) = 0; | |
69 | |
70 virtual SkEncodedFormat getEncodedFormat() = 0; | |
71 | |
72 int width() const { return fWidth; } | |
73 int height() const { return fHeight; } | |
74 | |
75 virtual ~SkBitmapRegionDecoder() {} | |
76 | |
77 protected: | |
78 | |
79 SkBitmapRegionDecoder(int width, int height) | |
80 : fWidth(width) | |
81 , fHeight(height) | |
82 {} | |
83 | |
84 private: | |
85 const int fWidth; | |
86 const int fHeight; | |
87 }; | |
88 | |
89 #endif | |
OLD | NEW |