| 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 SkCodec_DEFINED | 8 #ifndef SkCodec_DEFINED |
| 9 #define SkCodec_DEFINED | 9 #define SkCodec_DEFINED |
| 10 | 10 |
| 11 #include "SkColor.h" | 11 #include "SkColor.h" |
| 12 #include "SkEncodedFormat.h" | 12 #include "SkEncodedFormat.h" |
| 13 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
| 14 #include "SkSize.h" | 14 #include "SkSize.h" |
| 15 #include "SkStream.h" | 15 #include "SkStream.h" |
| 16 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
| 17 #include "SkTypes.h" | 17 #include "SkTypes.h" |
| 18 | 18 |
| 19 class SkData; | 19 class SkData; |
| 20 class SkScanlineDecoder; | |
| 21 | 20 |
| 22 /** | 21 /** |
| 23 * Abstraction layer directly on top of an image codec. | 22 * Abstraction layer directly on top of an image codec. |
| 24 */ | 23 */ |
| 25 class SkCodec : SkNoncopyable { | 24 class SkCodec : SkNoncopyable { |
| 26 public: | 25 public: |
| 27 /** | 26 /** |
| 28 * If this stream represents an encoded image that we know how to decode, | 27 * If this stream represents an encoded image that we know how to decode, |
| 29 * return an SkCodec that can decode it. Otherwise return NULL. | 28 * return an SkCodec that can decode it. Otherwise return NULL. |
| 30 * | 29 * |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, | 194 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, con
st Options*, |
| 196 SkPMColor ctable[], int* ctableCount); | 195 SkPMColor ctable[], int* ctableCount); |
| 197 | 196 |
| 198 /** | 197 /** |
| 199 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and | 198 * Simplified version of getPixels() that asserts that info is NOT kIndex8_
SkColorType and |
| 200 * uses the default Options. | 199 * uses the default Options. |
| 201 */ | 200 */ |
| 202 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); | 201 Result getPixels(const SkImageInfo& info, void* pixels, size_t rowBytes); |
| 203 | 202 |
| 204 /** | 203 /** |
| 205 * Create a new object which can be used to decode individual scanlines. | |
| 206 * | |
| 207 * The returned object has its own state, independent of the SkCodec, or an
y | |
| 208 * previously spawned SkScanlineDecoders. At creation, it will be ready to | |
| 209 * return the first scanline. | |
| 210 * | |
| 211 * @param dstInfo Info of the destination. If the dimensions do not match | |
| 212 * those of getInfo, this implies a scale. | |
| 213 * @param options Contains decoding options, including if memory is zero | |
| 214 * initialized. | |
| 215 * @param ctable A pointer to a color table. When dstInfo.colorType() is | |
| 216 * kIndex8, this should be non-NULL and have enough storage for 256 | |
| 217 * colors. The color table will be populated after decoding the palett
e. | |
| 218 * @param ctableCount A pointer to the size of the color table. When | |
| 219 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will | |
| 220 * be modified to the true size of the color table (<= 256) after | |
| 221 * decoding the palette. | |
| 222 * @return New SkScanlineDecoder, or NULL on failure. | |
| 223 * | |
| 224 * NOTE: This requires duplicating the SkStream. | |
| 225 */ | |
| 226 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo, const Opti
ons* options, | |
| 227 SkPMColor ctable[], int* ctableCount); | |
| 228 | |
| 229 /** | |
| 230 * Simplified version of getScanlineDecoder() that asserts that info is NOT | |
| 231 * kIndex8_SkColorType and uses the default Options. | |
| 232 */ | |
| 233 SkScanlineDecoder* getScanlineDecoder(const SkImageInfo& dstInfo); | |
| 234 | |
| 235 /** | |
| 236 * Some images may initially report that they have alpha due to the format | 204 * Some images may initially report that they have alpha due to the format |
| 237 * of the encoded data, but then never use any colors which have alpha | 205 * of the encoded data, but then never use any colors which have alpha |
| 238 * less than 100%. This function can be called *after* decoding to | 206 * less than 100%. This function can be called *after* decoding to |
| 239 * determine if such an image truly had alpha. Calling it before decoding | 207 * determine if such an image truly had alpha. Calling it before decoding |
| 240 * is undefined. | 208 * is undefined. |
| 241 * FIXME: see skbug.com/3582. | 209 * FIXME: see skbug.com/3582. |
| 242 */ | 210 */ |
| 243 bool reallyHasAlpha() const { | 211 bool reallyHasAlpha() const { |
| 244 return this->onReallyHasAlpha(); | 212 return this->onReallyHasAlpha(); |
| 245 } | 213 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 256 | 224 |
| 257 virtual Result onGetPixels(const SkImageInfo& info, | 225 virtual Result onGetPixels(const SkImageInfo& info, |
| 258 void* pixels, size_t rowBytes, const Options&, | 226 void* pixels, size_t rowBytes, const Options&, |
| 259 SkPMColor ctable[], int* ctableCount) = 0; | 227 SkPMColor ctable[], int* ctableCount) = 0; |
| 260 | 228 |
| 261 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 229 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { |
| 262 // By default, subsets are not supported. | 230 // By default, subsets are not supported. |
| 263 return false; | 231 return false; |
| 264 } | 232 } |
| 265 | 233 |
| 266 /** | |
| 267 * Override if your codec supports scanline decoding. | |
| 268 * | |
| 269 * @param dstInfo Info of the destination. If the dimensions do not match | |
| 270 * those of getInfo, this implies a scale. | |
| 271 * @param options Contains decoding options, including if memory is zero | |
| 272 * initialized. | |
| 273 * @param ctable A pointer to a color table. When dstInfo.colorType() is | |
| 274 * kIndex8, this should be non-NULL and have enough storage for 256 | |
| 275 * colors. The color table will be populated after decoding the palett
e. | |
| 276 * @param ctableCount A pointer to the size of the color table. When | |
| 277 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will | |
| 278 * be modified to the true size of the color table (<= 256) after | |
| 279 * decoding the palette. | |
| 280 * @return New SkScanlineDecoder on success, NULL otherwise. The caller is | |
| 281 * responsible for deleting the returned object. | |
| 282 */ | |
| 283 virtual SkScanlineDecoder* onGetScanlineDecoder(const SkImageInfo& dstInfo, | |
| 284 const Options& options, | |
| 285 SkPMColor ctable[], | |
| 286 int* ctableCount) { | |
| 287 return NULL; | |
| 288 } | |
| 289 | |
| 290 virtual bool onReallyHasAlpha() const { return false; } | 234 virtual bool onReallyHasAlpha() const { return false; } |
| 291 | 235 |
| 292 enum RewindState { | 236 enum RewindState { |
| 293 kRewound_RewindState, | 237 kRewound_RewindState, |
| 294 kNoRewindNecessary_RewindState, | 238 kNoRewindNecessary_RewindState, |
| 295 kCouldNotRewind_RewindState | 239 kCouldNotRewind_RewindState |
| 296 }; | 240 }; |
| 297 /** | 241 /** |
| 298 * If the stream was previously read, attempt to rewind. | 242 * If the stream was previously read, attempt to rewind. |
| 299 * @returns: | 243 * @returns: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 316 SkStream* stream() { | 260 SkStream* stream() { |
| 317 return fStream.get(); | 261 return fStream.get(); |
| 318 } | 262 } |
| 319 | 263 |
| 320 private: | 264 private: |
| 321 const SkImageInfo fInfo; | 265 const SkImageInfo fInfo; |
| 322 SkAutoTDelete<SkStream> fStream; | 266 SkAutoTDelete<SkStream> fStream; |
| 323 bool fNeedsRewind; | 267 bool fNeedsRewind; |
| 324 }; | 268 }; |
| 325 #endif // SkCodec_DEFINED | 269 #endif // SkCodec_DEFINED |
| OLD | NEW |