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 #include "SkCodec.h" | 8 #include "SkCodec.h" |
| 9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
| 10 #include "SkMath.h" | 10 #include "SkMath.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 if (!fCodec->skipScanlines(sampleY - 1)) { | 219 if (!fCodec->skipScanlines(sampleY - 1)) { |
| 220 fCodec->fillIncompleteImage(info, pixels, rowBytes, | 220 fCodec->fillIncompleteImage(info, pixels, rowBytes, |
| 221 options.fZeroInitialized, dstHeight, y + 1); | 221 options.fZeroInitialized, dstHeight, y + 1); |
| 222 return SkCodec::kIncompleteInput; | 222 return SkCodec::kIncompleteInput; |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 pixelPtr = SkTAddOffset<void>(pixelPtr, rowBytes); | 225 pixelPtr = SkTAddOffset<void>(pixelPtr, rowBytes); |
| 226 } | 226 } |
| 227 return SkCodec::kSuccess; | 227 return SkCodec::kSuccess; |
| 228 } | 228 } |
| 229 case SkCodec::kBottomUp_SkScanlineOrder: { | |
| 230 // Note that this mode does not support subsetting. | |
| 231 SkASSERT(0 == subsetY && nativeSize.height() == subsetHeight); | |
| 232 SkCodec::Result result = SkCodec::kSuccess; | |
| 233 int y; | |
| 234 for (y = 0; y < nativeSize.height(); y++) { | |
| 235 int srcY = fCodec->nextScanline(); | |
| 236 if (is_coord_necessary(srcY, sampleY, dstHeight)) { | |
| 237 void* pixelPtr = SkTAddOffset<void>(pixels, | |
| 238 rowBytes * get_dst_coord(srcY, sampleY)); | |
| 239 if (1 != fCodec->getScanlines(pixelPtr, 1, rowBytes)) { | |
| 240 result = SkCodec::kIncompleteInput; | |
|
scroggo
2015/11/17 15:33:17
This might be 6 of one, half a dozen of the other,
msarett
2015/11/17 16:06:24
I think this approach makes things a little cleare
| |
| 241 break; | |
| 242 } | |
| 243 } else { | |
| 244 if (!fCodec->skipScanlines(1)) { | |
| 245 result = SkCodec::kIncompleteInput; | |
| 246 break; | |
| 247 } | |
| 248 } | |
| 249 } | |
| 250 | |
| 251 // We handle filling uninitialized memory here instead of using fCod ec. | |
| 252 // fCodec does not know that we are sampling. | |
| 253 if (SkCodec::kIncompleteInput == result) { | |
| 254 const uint32_t fillValue = fCodec->getFillValue(info.colorType() , | |
| 255 info.alphaType()); | |
| 256 for (; y < nativeSize.height(); y++) { | |
| 257 int srcY = fCodec->outputScanline(y); | |
| 258 if (is_coord_necessary(srcY, sampleY, dstHeight)) { | |
| 259 void* pixelPtr = SkTAddOffset<void>(pixels, | |
| 260 rowBytes * get_dst_coord(srcY, sampleY)); | |
| 261 SkSampler::Fill(info.makeWH(info.width(), 1), pixelPtr, rowBytes, fillValue, | |
| 262 options.fZeroInitialized); | |
| 263 } | |
| 264 } | |
| 265 } | |
| 266 return result; | |
| 267 } | |
| 229 case SkCodec::kNone_SkScanlineOrder: { | 268 case SkCodec::kNone_SkScanlineOrder: { |
| 230 const int linesNeeded = subsetHeight - samplingOffsetY; | 269 const int linesNeeded = subsetHeight - samplingOffsetY; |
| 231 SkAutoMalloc storage(linesNeeded * rowBytes); | 270 SkAutoMalloc storage(linesNeeded * rowBytes); |
| 232 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 271 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 233 | 272 |
| 234 if (!fCodec->skipScanlines(startY)) { | 273 if (!fCodec->skipScanlines(startY)) { |
| 235 fCodec->fillIncompleteImage(info, pixels, rowBytes, options.fZer oInitialized, | 274 fCodec->fillIncompleteImage(info, pixels, rowBytes, options.fZer oInitialized, |
| 236 dstHeight, 0); | 275 dstHeight, 0); |
| 237 return SkCodec::kIncompleteInput; | 276 return SkCodec::kIncompleteInput; |
| 238 } | 277 } |
| 239 int scanlines = fCodec->getScanlines(storagePtr, linesNeeded, rowByt es); | 278 int scanlines = fCodec->getScanlines(storagePtr, linesNeeded, rowByt es); |
| 240 | 279 |
| 241 for (int y = 0; y < dstHeight; y++) { | 280 for (int y = 0; y < dstHeight; y++) { |
| 242 memcpy(pixels, storagePtr, info.minRowBytes()); | 281 memcpy(pixels, storagePtr, info.minRowBytes()); |
| 243 storagePtr += sampleY * rowBytes; | 282 storagePtr += sampleY * rowBytes; |
| 244 pixels = SkTAddOffset<void>(pixels, rowBytes); | 283 pixels = SkTAddOffset<void>(pixels, rowBytes); |
| 245 } | 284 } |
| 246 | 285 |
| 247 if (scanlines < dstHeight) { | 286 if (scanlines < dstHeight) { |
| 248 // fCodec has already handled filling uninitialized memory. | 287 // fCodec has already handled filling uninitialized memory. |
| 249 return SkCodec::kIncompleteInput; | 288 return SkCodec::kIncompleteInput; |
| 250 } | 289 } |
| 251 return SkCodec::kSuccess; | 290 return SkCodec::kSuccess; |
| 252 } | 291 } |
| 253 default: | 292 default: |
| 254 SkASSERT(false); | 293 SkASSERT(false); |
| 255 return SkCodec::kUnimplemented; | 294 return SkCodec::kUnimplemented; |
| 256 } | 295 } |
| 257 } | 296 } |
| OLD | NEW |