| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 */ | 48 */ |
| 49 const SkImageInfo& getInfo() const { return fSrcInfo; } | 49 const SkImageInfo& getInfo() const { return fSrcInfo; } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * Return a size that approximately supports the desired scale factor. | 52 * Return a size that approximately supports the desired scale factor. |
| 53 * The codec may not be able to scale efficiently to the exact scale | 53 * The codec may not be able to scale efficiently to the exact scale |
| 54 * factor requested, so return a size that approximates that scale. | 54 * factor requested, so return a size that approximates that scale. |
| 55 * The returned value is the codec's suggestion for the closest valid | 55 * The returned value is the codec's suggestion for the closest valid |
| 56 * scale that it can natively support | 56 * scale that it can natively support |
| 57 */ | 57 */ |
| 58 SkISize getScaledDimensions(float desiredScale) const { | 58 SkISize getScaledDimensions(float desiredScale) const; |
| 59 // Negative and zero scales are errors. | |
| 60 SkASSERT(desiredScale > 0.0f); | |
| 61 if (desiredScale <= 0.0f) { | |
| 62 return SkISize::Make(0, 0); | |
| 63 } | |
| 64 | |
| 65 // Upscaling is not supported. Return the original size if the client | |
| 66 // requests an upscale. | |
| 67 if (desiredScale >= 1.0f) { | |
| 68 return this->getInfo().dimensions(); | |
| 69 } | |
| 70 return this->onGetScaledDimensions(desiredScale); | |
| 71 } | |
| 72 | 59 |
| 73 /** | 60 /** |
| 74 * Return (via desiredSubset) a subset which can decoded from this codec, | 61 * Return (via desiredSubset) a subset which can decoded from this codec, |
| 75 * or false if this codec cannot decode subsets or anything similar to | 62 * or false if this codec cannot decode subsets or anything similar to |
| 76 * desiredSubset. | 63 * desiredSubset. |
| 77 * | 64 * |
| 78 * @param desiredSubset In/out parameter. As input, a desired subset of | 65 * @param desiredSubset In/out parameter. As input, a desired subset of |
| 79 * the original bounds (as specified by getInfo). If true is returned, | 66 * the original bounds (as specified by getInfo). If true is returned, |
| 80 * desiredSubset may have been modified to a subset which is | 67 * desiredSubset may have been modified to a subset which is |
| 81 * supported. Although a particular change may have been made to | 68 * supported. Although a particular change may have been made to |
| 82 * desiredSubset to create something supported, it is possible other | 69 * desiredSubset to create something supported, it is possible other |
| 83 * changes could result in a valid subset. | 70 * changes could result in a valid subset. |
| 84 * If false is returned, desiredSubset's value is undefined. | 71 * If false is returned, desiredSubset's value is undefined. |
| 85 * @return true if this codec supports decoding desiredSubset (as | 72 * @return true if this codec supports decoding desiredSubset (as |
| 86 * returned, potentially modified) | 73 * returned, potentially modified) |
| 87 */ | 74 */ |
| 88 bool getValidSubset(SkIRect* desiredSubset) const { | 75 bool getValidSubset(SkIRect* desiredSubset) const; |
| 89 return this->onGetValidSubset(desiredSubset); | |
| 90 } | |
| 91 | 76 |
| 92 /** | 77 /** |
| 93 * Format of the encoded data. | 78 * Format of the encoded data. |
| 94 */ | 79 */ |
| 95 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } | 80 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } |
| 96 | 81 |
| 97 /** | 82 /** |
| 98 * Used to describe the result of a call to getPixels(). | 83 * Used to describe the result of a call to getPixels(). |
| 99 * | 84 * |
| 100 * Result is the union of possible results from subclasses. | 85 * Result is the union of possible results from subclasses. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 * @param ctable A pointer to a color table. When dstInfo.colorType() is | 237 * @param ctable A pointer to a color table. When dstInfo.colorType() is |
| 253 * kIndex8, this should be non-NULL and have enough storage for 256 | 238 * kIndex8, this should be non-NULL and have enough storage for 256 |
| 254 * colors. The color table will be populated after decoding the palett
e. | 239 * colors. The color table will be populated after decoding the palett
e. |
| 255 * @param ctableCount A pointer to the size of the color table. When | 240 * @param ctableCount A pointer to the size of the color table. When |
| 256 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will | 241 * dstInfo.colorType() is kIndex8, this should be non-NULL. It will |
| 257 * be modified to the true size of the color table (<= 256) after | 242 * be modified to the true size of the color table (<= 256) after |
| 258 * decoding the palette. | 243 * decoding the palette. |
| 259 * @return Enum representing success or reason for failure. | 244 * @return Enum representing success or reason for failure. |
| 260 */ | 245 */ |
| 261 Result startScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Option
s* options, | 246 Result startScanlineDecode(const SkImageInfo& dstInfo, const SkCodec::Option
s* options, |
| 262 SkPMColor ctable[], int* ctableCount); | 247 SkPMColor ctable[], int* ctableCount); |
| 263 | 248 |
| 264 /** | 249 /** |
| 265 * Simplified version of startScanlineDecode() that asserts that info is NO
T | 250 * Simplified version of startScanlineDecode() that asserts that info is NO
T |
| 266 * kIndex8_SkColorType and uses the default Options. | 251 * kIndex8_SkColorType and uses the default options. |
| 267 */ | 252 */ |
| 268 Result startScanlineDecode(const SkImageInfo& dstInfo); | 253 Result startScanlineDecode(const SkImageInfo& dstInfo); |
| 269 | 254 |
| 270 /** | 255 /** |
| 271 * Write the next countLines scanlines into dst. | 256 * Write the next countLines scanlines into dst. |
| 272 * | 257 * |
| 273 * Not valid to call before calling startScanlineDecode(). | 258 * Not valid to call before calling startScanlineDecode(). |
| 274 * | 259 * |
| 275 * @param dst Must be non-null, and large enough to hold countLines | 260 * @param dst Must be non-null, and large enough to hold countLines |
| 276 * scanlines of size rowBytes. | 261 * scanlines of size rowBytes. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 int outputScanline(int inputScanline) const; | 376 int outputScanline(int inputScanline) const; |
| 392 | 377 |
| 393 protected: | 378 protected: |
| 394 SkCodec(const SkImageInfo&, SkStream*); | 379 SkCodec(const SkImageInfo&, SkStream*); |
| 395 | 380 |
| 396 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 381 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { |
| 397 // By default, scaling is not supported. | 382 // By default, scaling is not supported. |
| 398 return this->getInfo().dimensions(); | 383 return this->getInfo().dimensions(); |
| 399 } | 384 } |
| 400 | 385 |
| 386 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { |
| 387 // By default, subsets are not supported. |
| 388 return false; |
| 389 } |
| 390 |
| 401 // FIXME: What to do about subsets?? | 391 // FIXME: What to do about subsets?? |
| 402 /** | 392 /** |
| 403 * Subclasses should override if they support dimensions other than the | 393 * Subclasses should override if they support dimensions other than the |
| 404 * srcInfo's. | 394 * srcInfo's. |
| 405 */ | 395 */ |
| 406 virtual bool onDimensionsSupported(const SkISize&) { | 396 virtual bool onDimensionsSupported(const SkISize&) { |
| 407 return false; | 397 return false; |
| 408 } | 398 } |
| 409 | 399 |
| 410 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 400 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
| 411 | 401 |
| 412 /** | 402 /** |
| 413 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion | 403 * @param rowsDecoded When the encoded image stream is incomplete, this func
tion |
| 414 * will return kIncompleteInput and rowsDecoded will be s
et to | 404 * will return kIncompleteInput and rowsDecoded will be s
et to |
| 415 * the number of scanlines that were successfully decoded
. | 405 * the number of scanlines that were successfully decoded
. |
| 416 * This will allow getPixels() to fill the uninitialized
memory. | 406 * This will allow getPixels() to fill the uninitialized
memory. |
| 417 */ | 407 */ |
| 418 virtual Result onGetPixels(const SkImageInfo& info, | 408 virtual Result onGetPixels(const SkImageInfo& info, |
| 419 void* pixels, size_t rowBytes, const Options&, | 409 void* pixels, size_t rowBytes, const Options&, |
| 420 SkPMColor ctable[], int* ctableCount, | 410 SkPMColor ctable[], int* ctableCount, |
| 421 int* rowsDecoded) = 0; | 411 int* rowsDecoded) = 0; |
| 422 | 412 |
| 423 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | |
| 424 // By default, subsets are not supported. | |
| 425 return false; | |
| 426 } | |
| 427 | |
| 428 virtual bool onReallyHasAlpha() const { return false; } | 413 virtual bool onReallyHasAlpha() const { return false; } |
| 429 | 414 |
| 430 /** | 415 /** |
| 431 * If the stream was previously read, attempt to rewind. | 416 * If the stream was previously read, attempt to rewind. |
| 432 * | 417 * |
| 433 * If the stream needed to be rewound, call onRewind. | 418 * If the stream needed to be rewound, call onRewind. |
| 434 * @returns true if the codec is at the right position and can be used. | 419 * @returns true if the codec is at the right position and can be used. |
| 435 * false if there was a failure to rewind. | 420 * false if there was a failure to rewind. |
| 436 * | 421 * |
| 437 * This is called by getPixels() and start(). Subclasses may call if they | 422 * This is called by getPixels() and start(). Subclasses may call if they |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 * May create a sampler, if one is not currently being used. Otherwise, doe
s | 556 * May create a sampler, if one is not currently being used. Otherwise, doe
s |
| 572 * not affect ownership. | 557 * not affect ownership. |
| 573 * | 558 * |
| 574 * Only valid during scanline decoding. | 559 * Only valid during scanline decoding. |
| 575 */ | 560 */ |
| 576 virtual SkSampler* getSampler(bool createIfNecessary) { return nullptr; } | 561 virtual SkSampler* getSampler(bool createIfNecessary) { return nullptr; } |
| 577 | 562 |
| 578 friend class SkScaledCodec; | 563 friend class SkScaledCodec; |
| 579 }; | 564 }; |
| 580 #endif // SkCodec_DEFINED | 565 #endif // SkCodec_DEFINED |
| OLD | NEW |