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