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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 } | 374 } |
375 | 375 |
376 // Move to the next row | 376 // Move to the next row |
377 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); | 377 dstRow = SkTAddOffset<JSAMPLE>(dstRow, dstRowBytes); |
378 } | 378 } |
379 | 379 |
380 return kSuccess; | 380 return kSuccess; |
381 } | 381 } |
382 | 382 |
383 void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options&
options) { | 383 void SkJpegCodec::initializeSwizzler(const SkImageInfo& dstInfo, const Options&
options) { |
384 SkSwizzler::SrcConfig srcConfig; | 384 SkSwizzler::SrcConfig srcConfig = SkSwizzler::kUnknown; |
385 switch (dstInfo.colorType()) { | 385 switch (dstInfo.colorType()) { |
386 case kGray_8_SkColorType: | 386 case kGray_8_SkColorType: |
387 srcConfig = SkSwizzler::kGray; | 387 srcConfig = SkSwizzler::kGray; |
388 break; | 388 break; |
389 case kRGBA_8888_SkColorType: | 389 case kRGBA_8888_SkColorType: |
390 srcConfig = SkSwizzler::kRGBX; | 390 srcConfig = SkSwizzler::kRGBX; |
391 break; | 391 break; |
392 case kBGRA_8888_SkColorType: | 392 case kBGRA_8888_SkColorType: |
393 srcConfig = SkSwizzler::kBGRX; | 393 srcConfig = SkSwizzler::kBGRX; |
394 break; | 394 break; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 fSwizzler->swizzle(dst, dstRow); | 480 fSwizzler->swizzle(dst, dstRow); |
481 dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); | 481 dst = SkTAddOffset<JSAMPLE>(dst, rowBytes); |
482 } else { | 482 } else { |
483 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); | 483 dstRow = SkTAddOffset<JSAMPLE>(dstRow, rowBytes); |
484 } | 484 } |
485 } | 485 } |
486 return count; | 486 return count; |
487 } | 487 } |
488 | 488 |
489 #ifndef TURBO_HAS_SKIP | 489 #ifndef TURBO_HAS_SKIP |
490 // TODO (msarett): Make this a member function and avoid reallocating the | 490 // TODO (msarett): Avoid reallocating the memory buffer on each call to skip. |
491 // memory buffer on each call to skip. | 491 static uint32_t jpeg_skip_scanlines(dinfo, count) { |
492 #define jpeg_skip_scanlines(dinfo, count) \ | 492 SkAutoMalloc storage(get_row_bytes(dinfo)); |
493 SkAutoMalloc storage(get_row_bytes(dinfo)); \ | 493 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); |
494 uint8_t* storagePtr = static_cast<uint8_t*>(storage.get()); \ | 494 for (int y = 0; y < count; y++) { |
495 for (int y = 0; y < count; y++) { \ | 495 if (1 != jpeg_read_scanlines(dinfo, &storagePtr, 1)) { |
496 jpeg_read_scanlines(dinfo, &storagePtr, 1); \ | 496 return y; |
| 497 } |
497 } | 498 } |
| 499 return count; |
| 500 } |
498 #endif | 501 #endif |
499 | 502 |
500 bool SkJpegCodec::onSkipScanlines(int count) { | 503 bool SkJpegCodec::onSkipScanlines(int count) { |
501 // Set the jump location for libjpeg errors | 504 // Set the jump location for libjpeg errors |
502 if (setjmp(fDecoderMgr->getJmpBuf())) { | 505 if (setjmp(fDecoderMgr->getJmpBuf())) { |
503 return fDecoderMgr->returnFalse("setjmp"); | 506 return fDecoderMgr->returnFalse("setjmp"); |
504 } | 507 } |
505 | 508 |
506 return count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); | 509 return (uint32_t) count == jpeg_skip_scanlines(fDecoderMgr->dinfo(), count); |
507 } | 510 } |
OLD | NEW |