OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkBitmapRegionDecoder_DEFINED | 8 #ifndef SkBitmapRegionDecoder_DEFINED |
9 #define SkBitmapRegionDecoder_DEFINED | 9 #define SkBitmapRegionDecoder_DEFINED |
10 | 10 |
11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
12 #include "SkStream.h" | 12 #include "SkStream.h" |
13 | 13 |
14 /* | 14 /* |
15 * This class aims to provide an interface to test multiple implementations of | 15 * This class aims to provide an interface to test multiple implementations of |
16 * SkBitmapRegionDecoder. | 16 * SkBitmapRegionDecoder. |
17 */ | 17 */ |
18 class SkBitmapRegionDecoderInterface { | 18 class SkBitmapRegionDecoderInterface { |
19 public: | 19 public: |
20 | 20 |
21 enum Strategy { | 21 enum Strategy { |
22 kCanvas_Strategy, // Draw to the canvas, uses SkCodec | 22 kCanvas_Strategy, // Draw to the canvas, uses SkCodec |
23 kOriginal_Strategy, // Sampling, uses SkImageDecoder | 23 kOriginal_Strategy, // Sampling, uses SkImageDecoder |
24 kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsettin g | 24 kAndroidCodec_Strategy, // Uses SkAndroidCodec for scaling and subsettin g |
25 }; | 25 }; |
26 | 26 |
27 /* | 27 /* |
28 * Defines the relationship of the requested subset to the original image. | |
29 */ | |
30 enum SubsetType { | |
31 kFullyInside_SubsetType, | |
32 kPartiallyInside_SubsetType, | |
33 kOutside_SubsetType, | |
34 }; | |
35 | |
36 /* | |
28 * @param data Refs the data while this object exists, unrefs on destruc tion | 37 * @param data Refs the data while this object exists, unrefs on destruc tion |
29 * @param strategy Strategy used for scaling and subsetting | 38 * @param strategy Strategy used for scaling and subsetting |
30 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure | 39 * @return Tries to create an SkBitmapRegionDecoder, returns NULL on failure |
31 */ | 40 */ |
32 static SkBitmapRegionDecoderInterface* CreateBitmapRegionDecoder( | 41 static SkBitmapRegionDecoderInterface* CreateBitmapRegionDecoder( |
33 SkData* data, Strategy strategy); | 42 SkData* data, Strategy strategy); |
34 | 43 |
35 /* | 44 /* |
36 * Decode a scaled region of the encoded image stream | 45 * Must be called before decodeRegion(). Processes the subset, sample size, |
46 * color type, and alpha type for the decode. Reports the output image info . | |
37 * | 47 * |
38 * @param start_x X-coordinate of upper-left corner of region. | 48 * CAVEAT: |
39 * This coordinate is unscaled, relative to the original d imensions. | 49 * kOriginal_Strategy performs the initial set-up, pixel allocation, and |
40 * @param start_y Y-coordinate of upper-left corner of region. | 50 * subset decode all in one step. For kOriginal_Strategy, this function |
41 * This coordinate is unscaled, relative to the original d imensions. | 51 * will not set outInfo, since it will allocate its own pixels later |
42 * @param width Width of the region to decode. | 52 * in decodeRegion(). |
43 * This distance is unscaled, relative to the original dim ensions. | 53 * |
44 * @param height Height of the region to decode. | 54 * @param desiredSubset Subset of the original image to decode. |
45 * This distance is unscaled, relative to the original dim ensions. | 55 * @param sampleSize Downscale factor. |
46 * @param sampleSize An integer downscaling factor for the decode. | 56 * @param colorType Color type to decode to. |
47 * @param colorType Preferred output colorType. | 57 * @param requireUnpremul If the image is not opaque, we will use this to |
48 * New implementations should return NULL if they do not s upport | 58 * determine the alpha type to use. |
49 * decoding to this color type. | 59 * @param outInfo Output parameter used to indicate the properties |
50 * The old kOriginal_Strategy will decode to a default col or type | 60 * of the output. |
51 * if this color type is unsupported. | 61 * |
52 * @return Pointer to a bitmap of the decoded region on success, N ULL on | 62 * @return true if the desiredSubset intersects at least part of the image |
scroggo
2015/10/27 15:00:51
Should this return a SubsetType?
| |
53 * failure. | 63 * and we support the conversion to the requested color type. |
64 * false otherwise. | |
54 */ | 65 */ |
55 virtual SkBitmap* decodeRegion(int start_x, int start_y, int width, | 66 virtual bool prepareRegion(const SkIRect& desiredSubset, int sampleSize, |
56 int height, int sampleSize, | 67 SkColorType colorType, bool requireUnpremul, SkImageInfo* outInfo) = 0; |
57 SkColorType colorType) = 0; | 68 |
58 /* | 69 /* |
59 * @param Requested destination color type | 70 * Must be called after prepareRegion(), decodes the subset requested in |
60 * @return true if we support the requested color type and false otherwise | 71 * prepareRegion() into the provided bitmap. |
72 * | |
73 * CAVEAT: | |
74 * kOriginal_Strategy performs the initial set-up, pixel allocation, and | |
75 * subset decode all in one step. This means that decodeRegion() may | |
76 * fail due to invalid parameters passed to prepareRegion() (ex: invalid | |
77 * subset, invalid color type, etc). | |
78 * Also, kOriginal_Strategy will allocate its own pixels on the input | |
79 * bitmap, while the other strategies expect that the pixels will already | |
80 * be allocated. | |
81 * | |
82 * @param bitmap Must be large enough to contain the requested subset. | |
scroggo
2015/10/27 15:00:51
I find this comment confusing. I guess you're sayi
| |
83 * Unless we are using kOriginal_Strategy, the pixels | |
84 * must already be allocated. | |
85 * | |
86 * @return true on success, false on failure. | |
61 */ | 87 */ |
62 virtual bool conversionSupported(SkColorType colorType) = 0; | 88 virtual bool decodeRegion(SkBitmap& bitmap) = 0; |
scroggo
2015/10/27 15:00:50
Typically we use a pointer if we are going to modi
| |
63 | 89 |
64 int width() const { return fWidth; } | 90 int width() const { return fWidth; } |
65 int height() const { return fHeight; } | 91 int height() const { return fHeight; } |
66 | 92 |
67 virtual ~SkBitmapRegionDecoderInterface() {} | 93 virtual ~SkBitmapRegionDecoderInterface() {} |
68 | 94 |
69 protected: | 95 protected: |
70 | 96 |
71 SkBitmapRegionDecoderInterface(int width, int height) | 97 SkBitmapRegionDecoderInterface(int width, int height) |
72 : fWidth(width) | 98 : fWidth(width) |
73 , fHeight(height) | 99 , fHeight(height) |
74 {} | 100 {} |
75 | 101 |
76 private: | 102 private: |
77 const int fWidth; | 103 const int fWidth; |
78 const int fHeight; | 104 const int fHeight; |
79 }; | 105 }; |
80 | 106 |
81 #endif | 107 #endif |
OLD | NEW |