| 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 SkScanlineDecoder_DEFINED | 8 #ifndef SkScanlineDecoder_DEFINED |
| 9 #define SkScanlineDecoder_DEFINED | 9 #define SkScanlineDecoder_DEFINED |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 /** | 39 /** |
| 40 * Clean up after reading/skipping scanlines. | 40 * Clean up after reading/skipping scanlines. |
| 41 * | 41 * |
| 42 * It is possible that not all scanlines will have been read/skipped. In | 42 * It is possible that not all scanlines will have been read/skipped. In |
| 43 * fact, in the case of subset decodes, it is likely that there will be | 43 * fact, in the case of subset decodes, it is likely that there will be |
| 44 * scanlines at the bottom of the image that have been ignored. | 44 * scanlines at the bottom of the image that have been ignored. |
| 45 */ | 45 */ |
| 46 virtual ~SkScanlineDecoder() {} | 46 virtual ~SkScanlineDecoder() {} |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * Return a size that approximately supports the desired scale factor. | |
| 50 * The codec may not be able to scale efficiently to the exact scale | |
| 51 * factor requested, so return a size that approximates that scale. | |
| 52 * The returned value is the codec's suggestion for the closest valid | |
| 53 * scale that it can natively support | |
| 54 * FIXME: share this with SkCodec | |
| 55 */ | |
| 56 SkISize getScaledDimensions(float desiredScale) { | |
| 57 return this->onGetScaledDimensions(desiredScale); | |
| 58 } | |
| 59 | |
| 60 /** | |
| 61 * Returns the default info, corresponding to the encoded data. | 49 * Returns the default info, corresponding to the encoded data. |
| 62 */ | 50 */ |
| 63 const SkImageInfo& getInfo() { return fSrcInfo; } | 51 const SkImageInfo& getInfo() { return fSrcInfo; } |
| 64 | 52 |
| 65 /** | 53 /** |
| 66 * Initialize on the first scanline, with the specified options. | 54 * Initialize on the first scanline, with the specified options. |
| 67 * | 55 * |
| 68 * This must be called in order to call getScanlnies or skipScanlines. If | 56 * This must be called in order to call getScanlnies or skipScanlines. If |
| 69 * it has been called before, this will require rewinding the stream. | 57 * it has been called before, this will require rewinding the stream. |
| 70 * | 58 * |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 * of the encoded data, but then never use any colors which have alpha | 128 * of the encoded data, but then never use any colors which have alpha |
| 141 * less than 100%. This function can be called *after* decoding to | 129 * less than 100%. This function can be called *after* decoding to |
| 142 * determine if such an image truly had alpha. Calling it before decoding | 130 * determine if such an image truly had alpha. Calling it before decoding |
| 143 * is undefined. | 131 * is undefined. |
| 144 * FIXME: see skbug.com/3582. | 132 * FIXME: see skbug.com/3582. |
| 145 */ | 133 */ |
| 146 bool reallyHasAlpha() const { | 134 bool reallyHasAlpha() const { |
| 147 return this->onReallyHasAlpha(); | 135 return this->onReallyHasAlpha(); |
| 148 } | 136 } |
| 149 | 137 |
| 150 /** | |
| 151 * Format of the encoded data. | |
| 152 */ | |
| 153 SkEncodedFormat getEncodedFormat() const { return this->onGetEncodedFormat()
; } | |
| 154 | |
| 155 /** | |
| 156 * returns true if the image must be scaled, in the y direction, after readi
ng, not during. | |
| 157 * To scale afterwards, we first decode every line and then sample the lines
we want afterwards. | |
| 158 * An example is interlaced pngs, where calling getScanlines once (regardles
s of the count | |
| 159 * used) needs to read the entire image, therefore it is inefficient to call | |
| 160 * getScanlines more than once. Instead, it should only ever be called with
all the | |
| 161 * rows needed. | |
| 162 */ | |
| 163 bool requiresPostYSampling() { | |
| 164 return this->onRequiresPostYSampling(); | |
| 165 } | |
| 166 | |
| 167 protected: | 138 protected: |
| 168 SkScanlineDecoder(const SkImageInfo& srcInfo) | 139 SkScanlineDecoder(const SkImageInfo& srcInfo) |
| 169 : fSrcInfo(srcInfo) | 140 : fSrcInfo(srcInfo) |
| 170 , fDstInfo() | 141 , fDstInfo() |
| 171 , fCurrScanline(0) {} | 142 , fCurrScanline(0) {} |
| 172 | 143 |
| 173 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { | |
| 174 // By default, scaling is not supported. | |
| 175 return this->getInfo().dimensions(); | |
| 176 } | |
| 177 | |
| 178 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | |
| 179 | |
| 180 virtual bool onReallyHasAlpha() const { return false; } | 144 virtual bool onReallyHasAlpha() const { return false; } |
| 181 | 145 |
| 182 /** | |
| 183 * returns true if the image type is hard to sample and must be scaled after
reading, not during | |
| 184 * An example is interlaced pngs, where the entire image must be read for ea
ch decode | |
| 185 */ | |
| 186 virtual bool onRequiresPostYSampling() { return false; } | |
| 187 | |
| 188 const SkImageInfo& dstInfo() const { return fDstInfo; } | 146 const SkImageInfo& dstInfo() const { return fDstInfo; } |
| 189 | 147 |
| 190 private: | 148 private: |
| 191 const SkImageInfo fSrcInfo; | 149 const SkImageInfo fSrcInfo; |
| 192 SkImageInfo fDstInfo; | 150 SkImageInfo fDstInfo; |
| 193 int fCurrScanline; | 151 int fCurrScanline; |
| 194 | 152 |
| 195 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, | 153 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, |
| 196 const SkCodec::Options& options, | 154 const SkCodec::Options& options, |
| 197 SkPMColor ctable[], int* ctableCount) = 0; | 155 SkPMColor ctable[], int* ctableCount) = 0; |
| 198 | 156 |
| 199 // Naive default version just calls onGetScanlines on temp memory. | 157 // Naive default version just calls onGetScanlines on temp memory. |
| 200 virtual SkCodec::Result onSkipScanlines(int countLines) { | 158 virtual SkCodec::Result onSkipScanlines(int countLines) { |
| 201 SkAutoMalloc storage(fDstInfo.minRowBytes()); | 159 SkAutoMalloc storage(fDstInfo.minRowBytes()); |
| 202 // Note that we pass 0 to rowBytes so we continue to use the same memory
. | 160 // Note that we pass 0 to rowBytes so we continue to use the same memory
. |
| 203 // Also note that while getScanlines checks that rowBytes is big enough, | 161 // Also note that while getScanlines checks that rowBytes is big enough, |
| 204 // onGetScanlines bypasses that check. | 162 // onGetScanlines bypasses that check. |
| 205 // Calling the virtual method also means we do not double count | 163 // Calling the virtual method also means we do not double count |
| 206 // countLines. | 164 // countLines. |
| 207 return this->onGetScanlines(storage.get(), countLines, 0); | 165 return this->onGetScanlines(storage.get(), countLines, 0); |
| 208 } | 166 } |
| 209 | 167 |
| 210 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, | 168 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, |
| 211 size_t rowBytes) = 0; | 169 size_t rowBytes) = 0; |
| 212 | 170 |
| 213 }; | 171 }; |
| 214 #endif // SkScanlineDecoder_DEFINED | 172 #endif // SkScanlineDecoder_DEFINED |
| OLD | NEW |