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 "../private/SkTemplates.h" | 11 #include "../private/SkTemplates.h" |
12 #include "SkColor.h" | 12 #include "SkColor.h" |
13 #include "SkEncodedFormat.h" | 13 #include "SkEncodedFormat.h" |
14 #include "SkImageInfo.h" | 14 #include "SkImageInfo.h" |
15 #include "SkSize.h" | 15 #include "SkSize.h" |
16 #include "SkStream.h" | 16 #include "SkStream.h" |
17 #include "SkTypes.h" | 17 #include "SkTypes.h" |
18 | 18 |
19 class SkData; | 19 class SkData; |
| 20 class SkSampler; |
20 | 21 |
21 /** | 22 /** |
22 * Abstraction layer directly on top of an image codec. | 23 * Abstraction layer directly on top of an image codec. |
23 */ | 24 */ |
24 class SkCodec : SkNoncopyable { | 25 class SkCodec : SkNoncopyable { |
25 public: | 26 public: |
26 /** | 27 /** |
27 * If this stream represents an encoded image that we know how to decode, | 28 * If this stream represents an encoded image that we know how to decode, |
28 * return an SkCodec that can decode it. Otherwise return NULL. | 29 * return an SkCodec that can decode it. Otherwise return NULL. |
29 * | 30 * |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 376 } |
376 | 377 |
377 protected: | 378 protected: |
378 SkCodec(const SkImageInfo&, SkStream*); | 379 SkCodec(const SkImageInfo&, SkStream*); |
379 | 380 |
380 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 381 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { |
381 // By default, scaling is not supported. | 382 // By default, scaling is not supported. |
382 return this->getInfo().dimensions(); | 383 return this->getInfo().dimensions(); |
383 } | 384 } |
384 | 385 |
| 386 // FIXME: What to do about subsets?? |
| 387 /** |
| 388 * Subclasses should override if they support dimensions other than the |
| 389 * srcInfo's. |
| 390 */ |
| 391 virtual bool onDimensionsSupported(const SkISize&) { |
| 392 return false; |
| 393 } |
| 394 |
385 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 395 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
386 | 396 |
387 virtual Result onGetPixels(const SkImageInfo& info, | 397 virtual Result onGetPixels(const SkImageInfo& info, |
388 void* pixels, size_t rowBytes, const Options&, | 398 void* pixels, size_t rowBytes, const Options&, |
389 SkPMColor ctable[], int* ctableCount) = 0; | 399 SkPMColor ctable[], int* ctableCount) = 0; |
390 | 400 |
391 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { | 401 virtual bool onGetValidSubset(SkIRect* /* desiredSubset */) const { |
392 // By default, subsets are not supported. | 402 // By default, subsets are not supported. |
393 return false; | 403 return false; |
394 } | 404 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 458 |
449 private: | 459 private: |
450 const SkImageInfo fSrcInfo; | 460 const SkImageInfo fSrcInfo; |
451 SkAutoTDelete<SkStream> fStream; | 461 SkAutoTDelete<SkStream> fStream; |
452 bool fNeedsRewind; | 462 bool fNeedsRewind; |
453 // These fields are only meaningful during scanline decodes. | 463 // These fields are only meaningful during scanline decodes. |
454 SkImageInfo fDstInfo; | 464 SkImageInfo fDstInfo; |
455 SkCodec::Options fOptions; | 465 SkCodec::Options fOptions; |
456 int fCurrScanline; | 466 int fCurrScanline; |
457 | 467 |
| 468 /** |
| 469 * Return whether these dimensions are supported as a scale. |
| 470 * |
| 471 * The codec may choose to cache the information about scale and subset. |
| 472 * Either way, the same information will be passed to onGetPixels/onStart |
| 473 * on success. |
| 474 * |
| 475 * This must return true for a size returned from getScaledDimensions. |
| 476 */ |
| 477 bool dimensionsSupported(const SkISize& dim) { |
| 478 return dim == fSrcInfo.dimensions() || this->onDimensionsSupported(dim); |
| 479 } |
| 480 |
458 // Methods for scanline decoding. | 481 // Methods for scanline decoding. |
459 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& dstInfo, | 482 virtual SkCodec::Result onStartScanlineDecode(const SkImageInfo& dstInfo, |
460 const SkCodec::Options& options, SkPMColor ctable[], int* ctableCoun
t) { | 483 const SkCodec::Options& options, SkPMColor ctable[], int* ctableCoun
t) { |
461 return kUnimplemented; | 484 return kUnimplemented; |
462 } | 485 } |
463 | 486 |
464 // Naive default version just calls onGetScanlines on temp memory. | 487 // Naive default version just calls onGetScanlines on temp memory. |
465 virtual SkCodec::Result onSkipScanlines(int countLines) { | 488 virtual SkCodec::Result onSkipScanlines(int countLines) { |
466 SkAutoMalloc storage(fDstInfo.minRowBytes()); | 489 SkAutoMalloc storage(fDstInfo.minRowBytes()); |
467 // Note that we pass 0 to rowBytes so we continue to use the same memory
. | 490 // Note that we pass 0 to rowBytes so we continue to use the same memory
. |
468 // Also note that while getScanlines checks that rowBytes is big enough, | 491 // Also note that while getScanlines checks that rowBytes is big enough, |
469 // onGetScanlines bypasses that check. | 492 // onGetScanlines bypasses that check. |
470 // Calling the virtual method also means we do not double count | 493 // Calling the virtual method also means we do not double count |
471 // countLines. | 494 // countLines. |
472 return this->onGetScanlines(storage.get(), countLines, 0); | 495 return this->onGetScanlines(storage.get(), countLines, 0); |
473 } | 496 } |
474 | 497 |
475 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, | 498 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, |
476 size_t rowBytes) { | 499 size_t rowBytes) { |
477 return kUnimplemented; | 500 return kUnimplemented; |
478 } | 501 } |
479 | 502 |
| 503 /** |
| 504 * Return an object which will allow forcing scanline decodes to sample in
X. |
| 505 * |
| 506 * May create a sampler, if one is not currently being used. Otherwise, doe
s |
| 507 * not affect ownership. |
| 508 * |
| 509 * Only valid during scanline decoding. |
| 510 */ |
| 511 virtual SkSampler* getSampler() { return nullptr; } |
| 512 |
| 513 // Needed to call getSampler and dimensionsSupported. |
| 514 friend class SkScaledCodec; |
480 }; | 515 }; |
481 #endif // SkCodec_DEFINED | 516 #endif // SkCodec_DEFINED |
OLD | NEW |