| 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 "SkEncodedFormat.h" |
| 11 #include "SkImageGenerator.h" | 12 #include "SkImageGenerator.h" |
| 12 #include "SkImageInfo.h" | 13 #include "SkImageInfo.h" |
| 13 #include "SkSize.h" | 14 #include "SkSize.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
| 16 #include "SkTypes.h" | 17 #include "SkTypes.h" |
| 17 | 18 |
| 18 class SkData; | 19 class SkData; |
| 19 | 20 |
| 20 /** | 21 /** |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 * Return a size that approximately supports the desired scale factor. | 44 * Return a size that approximately supports the desired scale factor. |
| 44 * The codec may not be able to scale efficiently to the exact scale | 45 * The codec may not be able to scale efficiently to the exact scale |
| 45 * factor requested, so return a size that approximates that scale. | 46 * factor requested, so return a size that approximates that scale. |
| 46 * | 47 * |
| 47 * FIXME: Move to SkImageGenerator? | 48 * FIXME: Move to SkImageGenerator? |
| 48 */ | 49 */ |
| 49 SkISize getScaledDimensions(float desiredScale) const { | 50 SkISize getScaledDimensions(float desiredScale) const { |
| 50 return this->onGetScaledDimensions(desiredScale); | 51 return this->onGetScaledDimensions(desiredScale); |
| 51 } | 52 } |
| 52 | 53 |
| 54 /** |
| 55 * Format of the encoded data. |
| 56 */ |
| 57 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } |
| 58 |
| 53 protected: | 59 protected: |
| 54 SkCodec(const SkImageInfo&, SkStream*); | 60 SkCodec(const SkImageInfo&, SkStream*); |
| 55 | 61 |
| 56 /** | 62 /** |
| 57 * The SkAlphaType is a conservative answer. i.e. it is possible that it | 63 * The SkAlphaType is a conservative answer. i.e. it is possible that it |
| 58 * initially returns a non-opaque answer, but completing the decode | 64 * initially returns a non-opaque answer, but completing the decode |
| 59 * reveals that the image is actually opaque. | 65 * reveals that the image is actually opaque. |
| 60 */ | 66 */ |
| 61 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO | 67 #ifdef SK_SUPPORT_LEGACY_BOOL_ONGETINFO |
| 62 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { | 68 bool onGetInfo(SkImageInfo* info) SK_OVERRIDE { |
| 63 *info = fInfo; | 69 *info = fInfo; |
| 64 return true; | 70 return true; |
| 65 } | 71 } |
| 66 #endif | 72 #endif |
| 67 | 73 |
| 68 // Helper for subclasses. | 74 // Helper for subclasses. |
| 69 const SkImageInfo& getOriginalInfo() { return fInfo; } | 75 const SkImageInfo& getOriginalInfo() { return fInfo; } |
| 70 | 76 |
| 71 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { | 77 virtual SkISize onGetScaledDimensions(float /* desiredScale */) const { |
| 72 // By default, scaling is not supported. | 78 // By default, scaling is not supported. |
| 73 return fInfo.dimensions(); | 79 return fInfo.dimensions(); |
| 74 } | 80 } |
| 75 | 81 |
| 82 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
| 83 |
| 76 /** | 84 /** |
| 77 * If the stream was previously read, attempt to rewind. | 85 * If the stream was previously read, attempt to rewind. |
| 78 * @returns: | 86 * @returns: |
| 79 * true | 87 * true |
| 80 * - if the stream needed to be rewound, and the rewind | 88 * - if the stream needed to be rewound, and the rewind |
| 81 * succeeded. | 89 * succeeded. |
| 82 * - if the stream did not need to be rewound. | 90 * - if the stream did not need to be rewound. |
| 83 * false | 91 * false |
| 84 * - if the stream needed to be rewound, and rewind failed. | 92 * - if the stream needed to be rewound, and rewind failed. |
| 85 * Subclasses MUST call this function before reading the stream (e.g. in | 93 * Subclasses MUST call this function before reading the stream (e.g. in |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 } | 106 } |
| 99 | 107 |
| 100 private: | 108 private: |
| 101 const SkImageInfo fInfo; | 109 const SkImageInfo fInfo; |
| 102 SkAutoTDelete<SkStream> fStream; | 110 SkAutoTDelete<SkStream> fStream; |
| 103 bool fNeedsRewind; | 111 bool fNeedsRewind; |
| 104 | 112 |
| 105 typedef SkImageGenerator INHERITED; | 113 typedef SkImageGenerator INHERITED; |
| 106 }; | 114 }; |
| 107 #endif // SkCodec_DEFINED | 115 #endif // SkCodec_DEFINED |
| OLD | NEW |