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 "SkCodecPriv.h" | 8 #include "SkCodecPriv.h" |
| 9 #include "SkScaledCodec.h" | 9 #include "SkScaledCodec.h" |
| 10 #include "SkStream.h" | 10 #include "SkStream.h" |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 } | 191 } |
| 192 if (sampleYPtr) { | 192 if (sampleYPtr) { |
| 193 *sampleYPtr = sampleY; | 193 *sampleYPtr = sampleY; |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 // TODO: Implement subsetting in onGetPixels which works when and when not sampl ing | 197 // TODO: Implement subsetting in onGetPixels which works when and when not sampl ing |
| 198 | 198 |
| 199 SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi d* dst, | 199 SkCodec::Result SkScaledCodec::onGetPixels(const SkImageInfo& requestedInfo, voi d* dst, |
| 200 size_t rowBytes, const Options& optio ns, | 200 size_t rowBytes, const Options& optio ns, |
| 201 SkPMColor ctable[], int* ctableCount) { | 201 SkPMColor ctable[], int* ctableCount, |
| 202 int* rowsDecoded) { | |
| 202 | 203 |
| 203 if (options.fSubset) { | 204 if (options.fSubset) { |
| 204 // Subsets are not supported. | 205 // Subsets are not supported. |
| 205 return kUnimplemented; | 206 return kUnimplemented; |
| 206 } | 207 } |
| 207 | 208 |
| 208 if (fCodec->dimensionsSupported(requestedInfo.dimensions())) { | 209 if (fCodec->dimensionsSupported(requestedInfo.dimensions())) { |
| 210 // Make sure that the parent class does not fill on an incomplete decode , since | |
| 211 // fCodec will take care of filling the uninitialized lines. | |
| 212 *rowsDecoded = requestedInfo.height(); | |
| 209 return fCodec->getPixels(requestedInfo, dst, rowBytes, &options, ctable, ctableCount); | 213 return fCodec->getPixels(requestedInfo, dst, rowBytes, &options, ctable, ctableCount); |
| 210 } | 214 } |
| 211 | 215 |
| 212 // scaling requested | 216 // scaling requested |
| 213 int sampleX; | 217 int sampleX; |
| 214 int sampleY; | 218 int sampleY; |
| 215 if (!scaling_supported(requestedInfo.dimensions(), fCodec->getInfo().dimensi ons(), | 219 if (!scaling_supported(requestedInfo.dimensions(), fCodec->getInfo().dimensi ons(), |
| 216 &sampleX, &sampleY)) { | 220 &sampleX, &sampleY)) { |
| 217 // onDimensionsSupported would have returned false, meaning we should ne ver reach here. | 221 // onDimensionsSupported would have returned false, meaning we should ne ver reach here. |
| 218 SkASSERT(false); | 222 SkASSERT(false); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 238 if (!sampler) { | 242 if (!sampler) { |
| 239 return kUnimplemented; | 243 return kUnimplemented; |
| 240 } | 244 } |
| 241 | 245 |
| 242 if (sampler->setSampleX(sampleX) != requestedInfo.width()) { | 246 if (sampler->setSampleX(sampleX) != requestedInfo.width()) { |
| 243 return kInvalidScale; | 247 return kInvalidScale; |
| 244 } | 248 } |
| 245 | 249 |
| 246 switch(fCodec->getScanlineOrder()) { | 250 switch(fCodec->getScanlineOrder()) { |
| 247 case SkCodec::kTopDown_SkScanlineOrder: { | 251 case SkCodec::kTopDown_SkScanlineOrder: { |
| 248 result = fCodec->skipScanlines(Y0); | 252 if (!fCodec->skipScanlines(Y0)) { |
| 249 if (kSuccess != result && kIncompleteInput != result) { | 253 *rowsDecoded = 0; |
| 250 return result; | 254 return kIncompleteInput; |
| 251 } | 255 } |
| 252 for (int y = 0; y < dstHeight; y++) { | 256 for (int y = 0; y < dstHeight; y++) { |
| 253 result = fCodec->getScanlines(dst, 1, rowBytes); | 257 if (1 != fCodec->getScanlines(dst, 1, rowBytes)) { |
| 254 if (kSuccess != result && kIncompleteInput != result) { | 258 // The failed call to getScanlines() will take care of |
| 255 return result; | 259 // filling the failed row, so we indicate that we have |
| 260 // decoded (y + 1) rows. | |
| 261 *rowsDecoded = y + 1; | |
| 262 return kIncompleteInput; | |
| 256 } | 263 } |
| 257 if (y < dstHeight - 1) { | 264 if (y < dstHeight - 1) { |
| 258 result = fCodec->skipScanlines(sampleY - 1); | 265 if (!fCodec->skipScanlines(sampleY - 1)) { |
| 259 if (kSuccess != result && kIncompleteInput != result) { | 266 *rowsDecoded = y + 1; |
| 260 return result; | 267 return kIncompleteInput; |
| 261 } | 268 } |
| 262 } | 269 } |
| 263 dst = SkTAddOffset<void>(dst, rowBytes); | 270 dst = SkTAddOffset<void>(dst, rowBytes); |
| 264 } | 271 } |
| 265 return result; | 272 return kSuccess; |
| 266 } | 273 } |
| 267 case SkCodec::kBottomUp_SkScanlineOrder: | 274 case SkCodec::kBottomUp_SkScanlineOrder: |
| 268 case SkCodec::kOutOfOrder_SkScanlineOrder: { | 275 case SkCodec::kOutOfOrder_SkScanlineOrder: { |
| 269 for (int y = 0; y < srcHeight; y++) { | 276 Result result = kSuccess; |
| 277 int y; | |
| 278 for (y = 0; y < srcHeight; y++) { | |
| 270 int srcY = fCodec->nextScanline(); | 279 int srcY = fCodec->nextScanline(); |
| 271 if (is_coord_necessary(srcY, sampleY, dstHeight)) { | 280 if (is_coord_necessary(srcY, sampleY, dstHeight)) { |
| 272 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co ord(srcY, sampleY)); | 281 void* dstPtr = SkTAddOffset<void>(dst, rowBytes * get_dst_co ord(srcY, sampleY)); |
| 273 result = fCodec->getScanlines(dstPtr, 1, rowBytes); | 282 if (1 != fCodec->getScanlines(dstPtr, 1, rowBytes)) { |
| 274 if (kSuccess != result && kIncompleteInput != result) { | 283 result = kIncompleteInput; |
| 275 return result; | 284 break; |
| 276 } | 285 } |
| 277 } else { | 286 } else { |
| 278 result = fCodec->skipScanlines(1); | 287 if (!fCodec->skipScanlines(1)) { |
| 279 if (kSuccess != result && kIncompleteInput != result) { | 288 result = kIncompleteInput; |
| 280 return result; | 289 break; |
| 281 } | 290 } |
| 282 } | 291 } |
| 283 } | 292 } |
| 293 | |
| 294 // We handle filling uninitialized memory here instead of in the par ent class. | |
| 295 // The parent class does not know that we are sampling. | |
| 296 if (kIncompleteInput == result) { | |
| 297 SkSampler* sampler = fCodec->getSampler(); | |
| 298 SkASSERT(nullptr != sampler); | |
| 299 const uint32_t fillValue = fCodec->getFillValue(requestedInfo.co lorType(), | |
| 300 requestedInfo.alphaType()); | |
| 301 for (; y < srcHeight; y++) { | |
| 302 int srcY = fCodec->outputScanline(y); | |
| 303 if (is_coord_necessary(srcY, sampleY, dstHeight)) { | |
| 304 void* dstRow = SkTAddOffset<void>(dst, | |
| 305 rowBytes * get_dst_coord(srcY, sampleY)); | |
| 306 sampler->fill(dstRow, requestedInfo.colorType(), 1, rowB ytes, fillValue, | |
| 307 options.fZeroInitialized); | |
| 308 } | |
| 309 } | |
| 310 *rowsDecoded = dstHeight; | |
| 311 } | |
| 284 return result; | 312 return result; |
| 285 } | 313 } |
| 286 case SkCodec::kNone_SkScanlineOrder: { | 314 case SkCodec::kNone_SkScanlineOrder: { |
| 287 SkAutoMalloc storage(srcHeight * rowBytes); | 315 SkAutoMalloc storage(srcHeight * rowBytes); |
| 288 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 316 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
| 289 result = fCodec->getScanlines(storagePtr, srcHeight, rowBytes); | 317 int scanlines = fCodec->getScanlines(storagePtr, srcHeight, rowBytes ); |
| 290 if (kSuccess != result && kIncompleteInput != result) { | |
| 291 return result; | |
| 292 } | |
| 293 storagePtr += Y0 * rowBytes; | 318 storagePtr += Y0 * rowBytes; |
| 294 for (int y = 0; y < dstHeight; y++) { | 319 scanlines -= Y0; |
| 320 int y = 0; | |
| 321 while (y < dstHeight && scanlines > 0) { | |
| 295 memcpy(dst, storagePtr, rowBytes); | 322 memcpy(dst, storagePtr, rowBytes); |
| 296 storagePtr += sampleY * rowBytes; | 323 storagePtr += sampleY * rowBytes; |
| 297 dst = SkTAddOffset<void>(dst, rowBytes); | 324 dst = SkTAddOffset<void>(dst, rowBytes); |
| 325 scanlines -= sampleY; | |
| 326 y++; | |
| 298 } | 327 } |
| 299 return result; | 328 if (y < dstHeight) { |
| 329 // fCodec has already handled filling uninitialized memory. | |
| 330 *rowsDecoded = dstHeight; | |
| 331 return kIncompleteInput; | |
| 332 } | |
| 333 return kSuccess; | |
| 300 } | 334 } |
| 301 default: | 335 default: |
| 302 SkASSERT(false); | 336 SkASSERT(false); |
| 303 return kUnimplemented; | 337 return kUnimplemented; |
| 304 } | 338 } |
| 305 } | 339 } |
| 340 | |
| 341 uint32_t SkScaledCodec::onGetFillValue(SkColorType colorType, SkAlphaType alphaT ype) const { | |
| 342 return fCodec->onGetFillValue(colorType, alphaType); | |
| 343 } | |
| 344 | |
| 345 SkCodec::SkScanlineOrder SkScaledCodec::onGetScanlineOrder() const { | |
| 346 return fCodec->onGetScanlineOrder(); | |
| 347 } | |
| 348 | |
| 349 SkSampler* SkScaledCodec::getSampler() { | |
|
scroggo
2015/10/07 16:04:24
Does anyone ever need to call this? It seems like
msarett
2015/10/07 17:40:41
Removed in Patch Set 11.
| |
| 350 return fCodec->getSampler(); | |
| 351 } | |
| OLD | NEW |