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