Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 /** | 93 /** |
| 94 * Write the next countLines scanlines into dst. | 94 * Write the next countLines scanlines into dst. |
| 95 * | 95 * |
| 96 * Not valid to call before calling start(). | 96 * Not valid to call before calling start(). |
| 97 * | 97 * |
| 98 * @param dst Must be non-null, and large enough to hold countLines | 98 * @param dst Must be non-null, and large enough to hold countLines |
| 99 * scanlines of size rowBytes. | 99 * scanlines of size rowBytes. |
| 100 * @param countLines Number of lines to write. | 100 * @param countLines Number of lines to write. |
| 101 * @param rowBytes Number of bytes per row. Must be large enough to hold | 101 * @param rowBytes Number of bytes per row. Must be large enough to hold |
| 102 * a scanline based on the SkImageInfo used to create this object. | 102 * a scanline based on the SkImageInfo used to create this object. |
| 103 * @return the number of lines successfully decoded | |
| 103 */ | 104 */ |
| 104 SkCodec::Result getScanlines(void* dst, int countLines, size_t rowBytes) { | 105 uint32_t getScanlines(void* dst, int countLines, size_t rowBytes) { |
| 105 SkASSERT(!fDstInfo.isEmpty()); | 106 SkASSERT(!fDstInfo.isEmpty()); |
| 106 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 | 107 if ((rowBytes < fDstInfo.minRowBytes() && countLines > 1 ) || countLines <= 0 |
| 107 || fCurrScanline + countLines > fDstInfo.height()) { | 108 || fCurrScanline + countLines > fDstInfo.height()) { |
| 108 return SkCodec::kInvalidParameters; | 109 return SkCodec::kInvalidParameters; |
| 109 } | 110 } |
| 110 const SkCodec::Result result = this->onGetScanlines(dst, countLines, row Bytes); | 111 uint32_t decodedLines = this->onGetScanlines(dst, countLines, rowBytes); |
| 111 fCurrScanline += countLines; | 112 fCurrScanline += decodedLines; |
| 112 return result; | 113 return decodedLines; |
| 113 } | 114 } |
| 114 | 115 |
| 115 /** | 116 /** |
| 116 * Skip count scanlines. | 117 * Skip count scanlines. |
| 117 * | 118 * |
| 118 * Not valid to call before calling start(). | 119 * Not valid to call before calling start(). |
| 119 * | 120 * |
| 120 * The default version just calls onGetScanlines and discards the dst. | 121 * The default version just calls onGetScanlines and discards the dst. |
| 121 * NOTE: If skipped lines are the only lines with alpha, this default | 122 * NOTE: If skipped lines are the only lines with alpha, this default |
| 122 * will make reallyHasAlpha return true, when it could have returned | 123 * will make reallyHasAlpha return true, when it could have returned |
| 123 * false. | 124 * false. |
| 125 * | |
| 126 * @return the number of lines successfully skipped | |
|
scroggo
2015/09/22 18:02:48
Is this useful to know? It seems like skipping par
msarett
2015/09/23 13:22:40
Um no this isn't useful. I'm making this return a
scroggo
2015/09/25 15:55:05
I think they should return the same value. If you
msarett
2015/10/01 12:44:51
Will change, I thought returning different values
scroggo
2015/10/01 14:48:31
In general, I think it's better to report failures
msarett
2015/10/01 18:14:12
Gotcha. For now, I'm happy with it as is.
| |
| 124 */ | 127 */ |
| 125 SkCodec::Result skipScanlines(int countLines) { | 128 uint32_t skipScanlines(int countLines) { |
| 126 SkASSERT(!fDstInfo.isEmpty()); | 129 SkASSERT(!fDstInfo.isEmpty()); |
| 127 if (fCurrScanline + countLines > fDstInfo.height()) { | 130 if (fCurrScanline + countLines > fDstInfo.height()) { |
| 128 // Arguably, we could just skip the scanlines which are remaining, | 131 // Arguably, we could just skip the scanlines which are remaining, |
| 129 // and return kSuccess. We choose to return invalid so the client | 132 // and return kSuccess. We choose to return invalid so the client |
| 130 // can catch their bug. | 133 // can catch their bug. |
| 131 return SkCodec::kInvalidParameters; | 134 return SkCodec::kInvalidParameters; |
| 132 } | 135 } |
| 133 const SkCodec::Result result = this->onSkipScanlines(countLines); | 136 uint32_t skippedLines = this->onSkipScanlines(countLines); |
| 134 fCurrScanline += countLines; | 137 fCurrScanline += skippedLines; |
| 135 return result; | 138 return skippedLines; |
| 136 } | 139 } |
| 137 | 140 |
| 138 /** | 141 /** |
| 139 * Some images may initially report that they have alpha due to the format | 142 * Some images may initially report that they have alpha due to the format |
| 140 * of the encoded data, but then never use any colors which have alpha | 143 * 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 | 144 * less than 100%. This function can be called *after* decoding to |
| 142 * determine if such an image truly had alpha. Calling it before decoding | 145 * determine if such an image truly had alpha. Calling it before decoding |
| 143 * is undefined. | 146 * is undefined. |
| 144 * FIXME: see skbug.com/3582. | 147 * FIXME: see skbug.com/3582. |
| 145 */ | 148 */ |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 kNone_SkScanlineOrder, | 216 kNone_SkScanlineOrder, |
| 214 }; | 217 }; |
| 215 | 218 |
| 216 /** | 219 /** |
| 217 * An enum representing the order in which scanlines will be returned by | 220 * An enum representing the order in which scanlines will be returned by |
| 218 * the scanline decoder. | 221 * the scanline decoder. |
| 219 */ | 222 */ |
| 220 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } | 223 SkScanlineOrder getScanlineOrder() const { return this->onGetScanlineOrder() ; } |
| 221 | 224 |
| 222 /** | 225 /** |
| 223 * Returns the y-coordinate of the next row to be returned by the scanline | 226 * Returns the y-coordinate of the next dst row to be returned by the scanl ine |
| 224 * decoder. This will be overridden in the case of | 227 * decoder. This will be overridden in the case of |
| 225 * kOutOfOrder_SkScanlineOrder and should be unnecessary in the case of | 228 * kOutOfOrder_SkScanlineOrder or kBottomUp_SkScanlineOrder, and should be |
| 226 * kNone_SkScanlineOrder. | 229 * unnecessary in the case of kNone_SkScanlineOrder. |
| 227 */ | 230 */ |
| 228 int getY() const { | 231 int getY() const { |
| 229 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder()); | 232 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder()); |
| 230 return this->onGetY(); | 233 return this->onGetY(fCurrScanline); |
|
scroggo
2015/09/22 18:02:48
Could this function be non-virtual, and just depen
msarett
2015/09/23 13:22:40
Yes I think so! Will do.
The one thing that may
| |
| 234 } | |
| 235 | |
| 236 /** | |
| 237 * Returns the y-coordinate of the decoded row that corresponds to the | |
| 238 * input encoded y-coordinate. This will be overridden in the case of | |
| 239 * kOutOfOrder_SkScanlineOrder or kBottomUp_SkScanlineOrder, and should be | |
| 240 * unnecessary in the case of kNone_SkScanlineOrder. | |
| 241 */ | |
| 242 int getY(int encodedY) const { | |
|
scroggo
2015/09/22 18:02:48
I find the name encodedY confusing. Maybe srcY? I'
msarett
2015/09/23 13:22:40
In order to Fill() for kOutOfOrder images, we need
| |
| 243 SkASSERT(kNone_SkScanlineOrder != this->getScanlineOrder()); | |
| 244 return this->onGetY(encodedY); | |
| 245 } | |
| 246 | |
| 247 uint32_t getFillValue(const SkImageInfo& dstInfo) const { | |
| 248 return fCodec->getFillValue(dstInfo); | |
|
scroggo
2015/09/22 18:02:48
This stuff will become cleaner once I merge codec
msarett
2015/09/23 13:22:40
:)
| |
| 249 } | |
| 250 | |
| 251 void* getFillDst(void* dstStart, size_t rowBytes, uint32_t decodedScanlines) const { | |
| 252 return fCodec->getFillDst(dstStart, rowBytes, decodedScanlines); | |
| 231 } | 253 } |
| 232 | 254 |
| 233 protected: | 255 protected: |
| 234 SkScanlineDecoder(const SkImageInfo& srcInfo) | 256 SkScanlineDecoder(SkCodec* codec, const SkImageInfo& srcInfo) |
| 235 : fSrcInfo(srcInfo) | 257 : fCodec(codec) |
| 258 , fSrcInfo(srcInfo) | |
| 236 , fDstInfo() | 259 , fDstInfo() |
| 237 , fOptions() | 260 , fOptions() |
| 238 , fCurrScanline(0) {} | 261 , fCurrScanline(0) {} |
| 239 | 262 |
| 240 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { | 263 virtual SkISize onGetScaledDimensions(float /* desiredScale */) { |
| 241 // By default, scaling is not supported. | 264 // By default, scaling is not supported. |
| 242 return this->getInfo().dimensions(); | 265 return this->getInfo().dimensions(); |
| 243 } | 266 } |
| 244 | 267 |
| 245 virtual SkEncodedFormat onGetEncodedFormat() const = 0; | 268 virtual SkEncodedFormat onGetEncodedFormat() const = 0; |
| 246 | 269 |
| 247 virtual bool onReallyHasAlpha() const { return false; } | 270 virtual bool onReallyHasAlpha() const { return false; } |
| 248 | 271 |
| 249 /** | 272 /** |
| 250 * Most images types will be kTopDown and will not need to override this fu nction. | 273 * Most images types will be kTopDown and will not need to override this fu nction. |
| 251 */ | 274 */ |
| 252 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; } | 275 virtual SkScanlineOrder onGetScanlineOrder() const { return kTopDown_SkScanl ineOrder; } |
| 253 | 276 |
| 254 /** | 277 /** |
| 255 * Most images will be kTopDown and will not need to override this function . | 278 * Most images will be kTopDown and will not need to override this function . |
| 256 */ | 279 */ |
| 257 virtual int onGetY() const { return fCurrScanline; } | 280 virtual int onGetY(int encodedY) const { return encodedY; } |
| 258 | 281 |
| 259 const SkImageInfo& dstInfo() const { return fDstInfo; } | 282 const SkImageInfo& dstInfo() const { return fDstInfo; } |
| 260 | 283 |
| 261 const SkCodec::Options& options() const { return fOptions; } | 284 const SkCodec::Options& options() const { return fOptions; } |
| 262 | 285 |
| 263 private: | 286 private: |
| 264 const SkImageInfo fSrcInfo; | 287 SkAutoTDelete<SkCodec> fCodec; |
| 265 SkImageInfo fDstInfo; | 288 const SkImageInfo fSrcInfo; |
| 266 SkCodec::Options fOptions; | 289 SkImageInfo fDstInfo; |
| 267 int fCurrScanline; | 290 SkCodec::Options fOptions; |
| 291 int fCurrScanline; | |
| 268 | 292 |
| 269 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, | 293 virtual SkCodec::Result onStart(const SkImageInfo& dstInfo, |
| 270 const SkCodec::Options& options, | 294 const SkCodec::Options& options, |
| 271 SkPMColor ctable[], int* ctableCount) = 0; | 295 SkPMColor ctable[], int* ctableCount) = 0; |
| 272 | 296 |
| 273 // Naive default version just calls onGetScanlines on temp memory. | 297 // Naive default version just calls onGetScanlines on temp memory. |
| 274 virtual SkCodec::Result onSkipScanlines(int countLines) { | 298 virtual uint32_t onSkipScanlines(int countLines) { |
| 275 SkAutoMalloc storage(fDstInfo.minRowBytes()); | 299 SkAutoMalloc storage(fDstInfo.minRowBytes()); |
| 276 // Note that we pass 0 to rowBytes so we continue to use the same memory . | 300 // Note that we pass 0 to rowBytes so we continue to use the same memory . |
| 277 // Also note that while getScanlines checks that rowBytes is big enough, | 301 // Also note that while getScanlines checks that rowBytes is big enough, |
| 278 // onGetScanlines bypasses that check. | 302 // onGetScanlines bypasses that check. |
| 279 // Calling the virtual method also means we do not double count | 303 // Calling the virtual method also means we do not double count |
| 280 // countLines. | 304 // countLines. |
| 281 return this->onGetScanlines(storage.get(), countLines, 0); | 305 return this->onGetScanlines(storage.get(), countLines, 0); |
| 282 } | 306 } |
| 283 | 307 |
| 284 virtual SkCodec::Result onGetScanlines(void* dst, int countLines, | 308 virtual uint32_t onGetScanlines(void* dst, int countLines, size_t rowBytes) = 0; |
| 285 size_t rowBytes) = 0; | |
| 286 | 309 |
| 287 }; | 310 }; |
| 288 #endif // SkScanlineDecoder_DEFINED | 311 #endif // SkScanlineDecoder_DEFINED |
| OLD | NEW |