OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 SkImageGenerator_DEFINED | 8 #ifndef SkImageGenerator_DEFINED |
9 #define SkImageGenerator_DEFINED | 9 #define SkImageGenerator_DEFINED |
10 | 10 |
11 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
| 12 #include "SkColor.h" |
12 | 13 |
13 class SkBitmap; | 14 class SkBitmap; |
14 class SkData; | 15 class SkData; |
15 class SkImageGenerator; | 16 class SkImageGenerator; |
16 | 17 |
17 /** | 18 /** |
18 * Takes ownership of SkImageGenerator. If this method fails for | 19 * Takes ownership of SkImageGenerator. If this method fails for |
19 * whatever reason, it will return false and immediatetely delete | 20 * whatever reason, it will return false and immediatetely delete |
20 * the generator. If it succeeds, it will modify destination | 21 * the generator. If it succeeds, it will modify destination |
21 * bitmap. | 22 * bitmap. |
(...skipping 24 matching lines...) Expand all Loading... |
46 * SkDiscardablePixelRef) to decode and re-decode an image as needed. | 47 * SkDiscardablePixelRef) to decode and re-decode an image as needed. |
47 */ | 48 */ |
48 class SK_API SkImageGenerator { | 49 class SK_API SkImageGenerator { |
49 public: | 50 public: |
50 /** | 51 /** |
51 * The PixelRef which takes ownership of this SkImageGenerator | 52 * The PixelRef which takes ownership of this SkImageGenerator |
52 * will call the image generator's destructor. | 53 * will call the image generator's destructor. |
53 */ | 54 */ |
54 virtual ~SkImageGenerator() { } | 55 virtual ~SkImageGenerator() { } |
55 | 56 |
| 57 #ifdef SK_SUPPORT_LEGACY_IMAGEGENERATORAPI |
| 58 virtual bool refEncodedData() { return this->onRefEncodedData(); } |
| 59 virtual bool getInfo(SkImageInfo* info) { return this->onGetInfo(info); } |
| 60 virtual bool getPixels(const SkImageInfo& info, void* pixels, size_t rowByte
s) { |
| 61 return this->onGetPixels(info, pixels, rowBytes, NULL, NULL); |
| 62 } |
| 63 #else |
56 /** | 64 /** |
57 * Return a ref to the encoded (i.e. compressed) representation, | 65 * Return a ref to the encoded (i.e. compressed) representation, |
58 * of this data. | 66 * of this data. |
59 * | 67 * |
60 * If non-NULL is returned, the caller is responsible for calling | 68 * If non-NULL is returned, the caller is responsible for calling |
61 * unref() on the data when it is finished. | 69 * unref() on the data when it is finished. |
62 */ | 70 */ |
63 virtual SkData* refEncodedData() { return NULL; } | 71 SkData* refEncodedData() { return this->onRefEncodedData(); } |
64 | 72 |
65 /** | 73 /** |
66 * Return some information about the image, allowing the owner of | 74 * Return some information about the image, allowing the owner of |
67 * this object to allocate pixels. | 75 * this object to allocate pixels. |
68 * | 76 * |
69 * Repeated calls to this function should give the same results, | 77 * Repeated calls to this function should give the same results, |
70 * allowing the PixelRef to be immutable. | 78 * allowing the PixelRef to be immutable. |
71 * | 79 * |
72 * @return false if anything goes wrong. | 80 * @return false if anything goes wrong. |
73 */ | 81 */ |
74 virtual bool getInfo(SkImageInfo* info) = 0; | 82 bool getInfo(SkImageInfo* info); |
75 | 83 |
76 /** | 84 /** |
77 * Decode into the given pixels, a block of memory of size at | 85 * Decode into the given pixels, a block of memory of size at |
78 * least (info.fHeight - 1) * rowBytes + (info.fWidth * | 86 * least (info.fHeight - 1) * rowBytes + (info.fWidth * |
79 * bytesPerPixel) | 87 * bytesPerPixel) |
80 * | 88 * |
81 * Repeated calls to this function should give the same results, | 89 * Repeated calls to this function should give the same results, |
82 * allowing the PixelRef to be immutable. | 90 * allowing the PixelRef to be immutable. |
83 * | 91 * |
84 * @param info A description of the format (config, size) | 92 * @param info A description of the format (config, size) |
85 * expected by the caller. This can simply be identical | 93 * expected by the caller. This can simply be identical |
86 * to the info returned by getInfo(). | 94 * to the info returned by getInfo(). |
87 * | 95 * |
88 * This contract also allows the caller to specify | 96 * This contract also allows the caller to specify |
89 * different output-configs, which the implementation can | 97 * different output-configs, which the implementation can |
90 * decide to support or not. | 98 * decide to support or not. |
91 * | 99 * |
| 100 * If info is kIndex8_SkColorType, then the caller must provide storage for
up to 256 |
| 101 * SkPMColor values in ctable. On success the generator must copy N colors
into that storage, |
| 102 * (where N is the logical number of table entries) and set ctableCount to
N. |
| 103 * |
| 104 * If info is not kIndex8_SkColorType, then the last two parameters may be
NULL. If ctableCount |
| 105 * is not null, it will be set to 0. |
| 106 * |
92 * @return false if anything goes wrong or if the image info is | 107 * @return false if anything goes wrong or if the image info is |
93 * unsupported. | 108 * unsupported. |
94 */ | 109 */ |
95 virtual bool getPixels(const SkImageInfo& info, | 110 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, |
96 void* pixels, | 111 SkPMColor ctable[], int* ctableCount); |
97 size_t rowBytes) = 0; | 112 |
| 113 /** |
| 114 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType. |
| 115 */ |
| 116 bool getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
| 117 #endif |
| 118 |
| 119 protected: |
| 120 virtual SkData* onRefEncodedData(); |
| 121 virtual bool onGetInfo(SkImageInfo* info); |
| 122 virtual bool onGetPixels(const SkImageInfo& info, |
| 123 void* pixels, size_t rowBytes, |
| 124 SkPMColor ctable[], int* ctableCount); |
98 }; | 125 }; |
99 | 126 |
100 #endif // SkImageGenerator_DEFINED | 127 #endif // SkImageGenerator_DEFINED |
OLD | NEW |