| 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 int y; |
| 233 for (y = 0; y < nativeSize.height(); y++) { |
| 234 int srcY = fCodec->nextScanline(); |
| 235 if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
| 236 void* pixelPtr = SkTAddOffset<void>(pixels, |
| 237 rowBytes * get_dst_coord(srcY, sampleY)); |
| 238 if (1 != fCodec->getScanlines(pixelPtr, 1, rowBytes)) { |
| 239 break; |
| 240 } |
| 241 } else { |
| 242 if (!fCodec->skipScanlines(1)) { |
| 243 break; |
| 244 } |
| 245 } |
| 246 } |
| 247 |
| 248 if (nativeSize.height() == y) { |
| 249 return SkCodec::kSuccess; |
| 250 } |
| 251 |
| 252 // We handle filling uninitialized memory here instead of using fCod
ec. |
| 253 // fCodec does not know that we are sampling. |
| 254 const uint32_t fillValue = fCodec->getFillValue(info.colorType(), in
fo.alphaType()); |
| 255 const SkImageInfo fillInfo = info.makeWH(info.width(), 1); |
| 256 for (; y < nativeSize.height(); y++) { |
| 257 int srcY = fCodec->outputScanline(y); |
| 258 if (!is_coord_necessary(srcY, sampleY, dstHeight)) { |
| 259 continue; |
| 260 } |
| 261 |
| 262 void* rowPtr = SkTAddOffset<void>(pixels, rowBytes * get_dst_coo
rd(srcY, sampleY)); |
| 263 SkSampler::Fill(fillInfo, rowPtr, rowBytes, fillValue, options.f
ZeroInitialized); |
| 264 } |
| 265 return SkCodec::kIncompleteInput; |
| 266 } |
| 229 case SkCodec::kNone_SkScanlineOrder: { | 267 case SkCodec::kNone_SkScanlineOrder: { |
| 230 const int linesNeeded = subsetHeight - samplingOffsetY; | 268 const int linesNeeded = subsetHeight - samplingOffsetY; |
| 231 SkAutoMalloc storage(linesNeeded * rowBytes); | 269 SkAutoMalloc storage(linesNeeded * rowBytes); |
| 232 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 270 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 233 | 271 |
| 234 if (!fCodec->skipScanlines(startY)) { | 272 if (!fCodec->skipScanlines(startY)) { |
| 235 fCodec->fillIncompleteImage(info, pixels, rowBytes, options.fZer
oInitialized, | 273 fCodec->fillIncompleteImage(info, pixels, rowBytes, options.fZer
oInitialized, |
| 236 dstHeight, 0); | 274 dstHeight, 0); |
| 237 return SkCodec::kIncompleteInput; | 275 return SkCodec::kIncompleteInput; |
| 238 } | 276 } |
| 239 int scanlines = fCodec->getScanlines(storagePtr, linesNeeded, rowByt
es); | 277 int scanlines = fCodec->getScanlines(storagePtr, linesNeeded, rowByt
es); |
| 240 | 278 |
| 241 for (int y = 0; y < dstHeight; y++) { | 279 for (int y = 0; y < dstHeight; y++) { |
| 242 memcpy(pixels, storagePtr, info.minRowBytes()); | 280 memcpy(pixels, storagePtr, info.minRowBytes()); |
| 243 storagePtr += sampleY * rowBytes; | 281 storagePtr += sampleY * rowBytes; |
| 244 pixels = SkTAddOffset<void>(pixels, rowBytes); | 282 pixels = SkTAddOffset<void>(pixels, rowBytes); |
| 245 } | 283 } |
| 246 | 284 |
| 247 if (scanlines < dstHeight) { | 285 if (scanlines < dstHeight) { |
| 248 // fCodec has already handled filling uninitialized memory. | 286 // fCodec has already handled filling uninitialized memory. |
| 249 return SkCodec::kIncompleteInput; | 287 return SkCodec::kIncompleteInput; |
| 250 } | 288 } |
| 251 return SkCodec::kSuccess; | 289 return SkCodec::kSuccess; |
| 252 } | 290 } |
| 253 default: | 291 default: |
| 254 SkASSERT(false); | 292 SkASSERT(false); |
| 255 return SkCodec::kUnimplemented; | 293 return SkCodec::kUnimplemented; |
| 256 } | 294 } |
| 257 } | 295 } |
| OLD | NEW |