| 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 "SkJpegCodec.h" | 9 #include "SkJpegCodec.h" |
| 10 #include "SkJpegDecoderMgr.h" | 10 #include "SkJpegDecoderMgr.h" |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 srcConfig = SkSwizzler::kRGB_565; | 343 srcConfig = SkSwizzler::kRGB_565; |
| 344 break; | 344 break; |
| 345 default: | 345 default: |
| 346 // This function should only be called if the colorType is suppo
rted by jpeg | 346 // This function should only be called if the colorType is suppo
rted by jpeg |
| 347 SkASSERT(false); | 347 SkASSERT(false); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti
ons)); | 351 fSwizzler.reset(SkSwizzler::CreateSwizzler(srcConfig, nullptr, dstInfo, opti
ons)); |
| 352 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); | 352 fStorage.reset(get_row_bytes(fDecoderMgr->dinfo())); |
| 353 fSrcRow = static_cast<uint8_t*>(fStorage.get()); | 353 fSrcRow = fStorage.get(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { | 356 SkSampler* SkJpegCodec::getSampler(bool createIfNecessary) { |
| 357 if (!createIfNecessary || fSwizzler) { | 357 if (!createIfNecessary || fSwizzler) { |
| 358 SkASSERT(!fSwizzler || (fSrcRow && static_cast<uint8_t*>(fStorage.get())
== fSrcRow)); | 358 SkASSERT(!fSwizzler || (fSrcRow && fStorage.get() == fSrcRow)); |
| 359 return fSwizzler; | 359 return fSwizzler; |
| 360 } | 360 } |
| 361 | 361 |
| 362 this->initializeSwizzler(this->dstInfo(), this->options()); | 362 this->initializeSwizzler(this->dstInfo(), this->options()); |
| 363 return fSwizzler; | 363 return fSwizzler; |
| 364 } | 364 } |
| 365 | 365 |
| 366 SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, | 366 SkCodec::Result SkJpegCodec::onStartScanlineDecode(const SkImageInfo& dstInfo, |
| 367 const Options& options, SkPMColor ctable[], int* ctableCount) { | 367 const Options& options, SkPMColor ctable[], int* ctableCount) { |
| 368 // Set the jump location for libjpeg errors | 368 // Set the jump location for libjpeg errors |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } else { | 426 } else { |
| 427 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | 427 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 return count; | 430 return count; |
| 431 } | 431 } |
| 432 | 432 |
| 433 #ifndef TURBO_HAS_SKIP | 433 #ifndef TURBO_HAS_SKIP |
| 434 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip. | 434 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip. |
| 435 static uint32_t jpeg_skip_scanlines(jpeg_decompress_struct* dinfo, int count) { | 435 static uint32_t jpeg_skip_scanlines(jpeg_decompress_struct* dinfo, int count) { |
| 436 SkAutoMalloc storage(get_row_bytes(dinfo)); | 436 SkAutoTMalloc<uint8_t> storage(get_row_bytes(dinfo)); |
| 437 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); | 437 uint8_t* storagePtr = storage.get(); |
| 438 for (int y = 0; y < count; y++) { | 438 for (int y = 0; y < count; y++) { |
| 439 if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) { | 439 if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) { |
| 440 return y; | 440 return y; |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 return count; | 443 return count; |
| 444 } | 444 } |
| 445 #endif | 445 #endif |
| 446 | 446 |
| 447 bool SkJpegCodec::onSkipScanlines(int count) { | 447 bool SkJpegCodec::onSkipScanlines(int count) { |
| 448 // Set the jump location for libjpeg errors | 448 // Set the jump location for libjpeg errors |
| 449 if (setjmp(fDecoderMgr->getJmpBuf())) { | 449 if (setjmp(fDecoderMgr->getJmpBuf())) { |
| 450 return fDecoderMgr->returnFalse("setjmp"); | 450 return fDecoderMgr->returnFalse("setjmp"); |
| 451 } | 451 } |
| 452 | 452 |
| 453 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 453 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
| 454 } | 454 } |
| OLD | NEW |