Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(926)

Side by Side Diff: src/codec/SkCodec_libpng.cpp

Issue 1061713007: Adding png scanline decoding to kIndex8 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Added simpler version of getScanlineDecoder Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« include/codec/SkCodec.h ('K') | « src/codec/SkCodec_libpng.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_libpng.h" 8 #include "SkCodec_libpng.h"
9 #include "SkCodecPriv.h" 9 #include "SkCodecPriv.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkColorTable.h" 11 #include "SkColorTable.h"
12 #include "SkBitmap.h" 12 #include "SkBitmap.h"
13 #include "SkMath.h" 13 #include "SkMath.h"
14 #include "SkScanlineDecoder.h" 14 #include "SkScanlineDecoder.h"
15 #include "SkSize.h" 15 #include "SkSize.h"
16 #include "SkStream.h" 16 #include "SkStream.h"
17 #include "SkSwizzler.h" 17 #include "SkSwizzler.h"
18 #include "SkUtils.h"
19 18
20 /////////////////////////////////////////////////////////////////////////////// 19 ///////////////////////////////////////////////////////////////////////////////
21 // Helper macros 20 // Helper macros
22 /////////////////////////////////////////////////////////////////////////////// 21 ///////////////////////////////////////////////////////////////////////////////
23 22
24 #ifndef png_jmpbuf 23 #ifndef png_jmpbuf
25 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) 24 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
26 #endif 25 #endif
27 26
28 /* These were dropped in libpng >= 1.4 */ 27 /* These were dropped in libpng >= 1.4 */
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 case kN32_SkColorType: 421 case kN32_SkColorType:
423 return true; 422 return true;
424 default: 423 default:
425 return dst.colorType() == src.colorType(); 424 return dst.colorType() == src.colorType();
426 } 425 }
427 } 426 }
428 427
429 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, 428 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
430 void* dst, size_t rowBytes, 429 void* dst, size_t rowBytes,
431 const Options& options, 430 const Options& options,
431 SkPMColor ctable[],
432 int* ctableCount) { 432 int* ctableCount) {
433 // FIXME: Could we use the return value of setjmp to specify the type of 433 // FIXME: Could we use the return value of setjmp to specify the type of
434 // error? 434 // error?
435 if (setjmp(png_jmpbuf(fPng_ptr))) { 435 if (setjmp(png_jmpbuf(fPng_ptr))) {
436 SkCodecPrintf("setjmp long jump!\n"); 436 SkCodecPrintf("setjmp long jump!\n");
437 return kInvalidInput; 437 return kInvalidInput;
438 } 438 }
439 439
440 // FIXME: We already retrieved this information. Store it in SkPngCodec? 440 // FIXME: We already retrieved this information. Store it in SkPngCodec?
441 png_uint_32 origWidth, origHeight; 441 png_uint_32 origWidth, origHeight;
(...skipping 15 matching lines...) Expand all
457 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) { 457 } else if (kAlpha_8_SkColorType == requestedInfo.colorType()) {
458 // Note: we check the destination, since otherwise we would have 458 // Note: we check the destination, since otherwise we would have
459 // told png to upscale. 459 // told png to upscale.
460 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType); 460 SkASSERT(PNG_COLOR_TYPE_GRAY == pngColorType);
461 fSrcConfig = SkSwizzler::kGray; 461 fSrcConfig = SkSwizzler::kGray;
462 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { 462 } else if (this->getInfo().alphaType() == kOpaque_SkAlphaType) {
463 fSrcConfig = SkSwizzler::kRGBX; 463 fSrcConfig = SkSwizzler::kRGBX;
464 } else { 464 } else {
465 fSrcConfig = SkSwizzler::kRGBA; 465 fSrcConfig = SkSwizzler::kRGBA;
466 } 466 }
467
468 // Copy the color table to the client if they request kIndex8 mode
469 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount);
470
471 // Create the swizzler. SkPngCodec retains ownership of the color table.
467 const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL; 472 const SkPMColor* colors = fColorTable ? fColorTable->readColors() : NULL;
468 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo , 473 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo ,
469 dst, rowBytes, options.fZeroInitialized)); 474 dst, rowBytes, options.fZeroInitialized));
470 if (!fSwizzler) { 475 if (!fSwizzler) {
471 // FIXME: CreateSwizzler could fail for another reason. 476 // FIXME: CreateSwizzler could fail for another reason.
472 return kUnimplemented; 477 return kUnimplemented;
473 } 478 }
474 479
475 // FIXME: Here is where we should likely insert some of the modifications 480 // FIXME: Here is where we should likely insert some of the modifications
476 // made in the factory. 481 // made in the factory.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 if (!this->handleRewind()) { 518 if (!this->handleRewind()) {
514 return kCouldNotRewind; 519 return kCouldNotRewind;
515 } 520 }
516 if (requestedInfo.dimensions() != this->getInfo().dimensions()) { 521 if (requestedInfo.dimensions() != this->getInfo().dimensions()) {
517 return kInvalidScale; 522 return kInvalidScale;
518 } 523 }
519 if (!conversion_possible(requestedInfo, this->getInfo())) { 524 if (!conversion_possible(requestedInfo, this->getInfo())) {
520 return kInvalidConversion; 525 return kInvalidConversion;
521 } 526 }
522 527
523 // Note that ctableCount will be modified if there is a color table 528 // Note that ctable and ctableCount may be modified if there is a color tabl e
524 const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes, 529 const Result result = this->initializeSwizzler(requestedInfo, dst, rowBytes,
525 options, ctableCount); 530 options, ctable, ctableCount) ;
526
527 // Copy the color table to the client if necessary
528 if (kIndex_8_SkColorType == requestedInfo.colorType()) {
529 SkASSERT(NULL != ctable);
530 SkASSERT(NULL != ctableCount);
531 SkASSERT(NULL != fColorTable.get());
532 sk_memcpy32(ctable, fColorTable->readColors(), *ctableCount);
533 }
534 531
535 if (result != kSuccess) { 532 if (result != kSuccess) {
536 return result; 533 return result;
537 } 534 }
538 535
539 // FIXME: Could we use the return value of setjmp to specify the type of 536 // FIXME: Could we use the return value of setjmp to specify the type of
540 // error? 537 // error?
541 if (setjmp(png_jmpbuf(fPng_ptr))) { 538 if (setjmp(png_jmpbuf(fPng_ptr))) {
542 SkCodecPrintf("setjmp long jump!\n"); 539 SkCodecPrintf("setjmp long jump!\n");
543 return kInvalidInput; 540 return kInvalidInput;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 638
642 private: 639 private:
643 SkPngCodec* fCodec; // Unowned. 640 SkPngCodec* fCodec; // Unowned.
644 bool fHasAlpha; 641 bool fHasAlpha;
645 SkAutoMalloc fStorage; 642 SkAutoMalloc fStorage;
646 uint8_t* fSrcRow; 643 uint8_t* fSrcRow;
647 644
648 typedef SkScanlineDecoder INHERITED; 645 typedef SkScanlineDecoder INHERITED;
649 }; 646 };
650 647
651 SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo) { 648 SkScanlineDecoder* SkPngCodec::onGetScanlineDecoder(const SkImageInfo& dstInfo,
649 const Options& options, SkPMColor ctable[], int* ctableCount) {
652 if (!this->handleRewind()) { 650 if (!this->handleRewind()) {
653 return NULL; 651 return NULL;
654 } 652 }
655 653
656 // Check to see if scaling was requested. 654 // Check to see if scaling was requested.
657 if (dstInfo.dimensions() != this->getInfo().dimensions()) { 655 if (dstInfo.dimensions() != this->getInfo().dimensions()) {
658 return NULL; 656 return NULL;
659 } 657 }
660 658
661 if (!conversion_possible(dstInfo, this->getInfo())) { 659 if (!conversion_possible(dstInfo, this->getInfo())) {
662 SkCodecPrintf("no conversion possible\n"); 660 SkCodecPrintf("no conversion possible\n");
663 return NULL; 661 return NULL;
664 } 662 }
665 663
666 // Note: We set dst to NULL since we do not know it yet. rowBytes is not nee ded, 664 // Note: We set dst to NULL since we do not know it yet. rowBytes is not nee ded,
667 // since we'll be manually updating the dstRow, but the SkSwizzler requires it to 665 // since we'll be manually updating the dstRow, but the SkSwizzler requires it to
668 // be at least dstInfo.minRowBytes. 666 // be at least dstInfo.minRowBytes.
669 Options opts; 667 if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), options, ctable,
670 // FIXME: Pass this in to getScanlineDecoder? 668 ctableCount) != kSuccess) {
671 opts.fZeroInitialized = kNo_ZeroInitialized;
672 // FIXME: onGetScanlineDecoder does not currently have a way to get color ta ble information
673 // for a kIndex8 decoder.
674 if (this->initializeSwizzler(dstInfo, NULL, dstInfo.minRowBytes(), opts, NUL L) != kSuccess) {
675 SkCodecPrintf("failed to initialize the swizzler.\n"); 669 SkCodecPrintf("failed to initialize the swizzler.\n");
676 return NULL; 670 return NULL;
677 } 671 }
678 672
679 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES); 673 SkASSERT(fNumberPasses != INVALID_NUMBER_PASSES);
680 if (fNumberPasses > 1) { 674 if (fNumberPasses > 1) {
681 // We cannot efficiently do scanline decoding. 675 // We cannot efficiently do scanline decoding.
682 return NULL; 676 return NULL;
683 } 677 }
684 678
685 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this)); 679 return SkNEW_ARGS(SkPngScanlineDecoder, (dstInfo, this));
686 } 680 }
687 681
OLDNEW
« include/codec/SkCodec.h ('K') | « src/codec/SkCodec_libpng.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698