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

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

Issue 1573943002: sketch hooking into PNG_FILTER_OPTIMIZATIONS (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: dont bother with Up Created 4 years, 11 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
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 "SkCodecPriv.h" 8 #include "SkCodecPriv.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkColorTable.h" 10 #include "SkColorTable.h"
11 #include "SkBitmap.h" 11 #include "SkBitmap.h"
12 #include "SkMath.h" 12 #include "SkMath.h"
13 #include "SkPngCodec.h" 13 #include "SkPngCodec.h"
14 #include "SkPngFilters.h"
14 #include "SkSize.h" 15 #include "SkSize.h"
15 #include "SkStream.h" 16 #include "SkStream.h"
16 #include "SkSwizzler.h" 17 #include "SkSwizzler.h"
17 #include "SkTemplates.h" 18 #include "SkTemplates.h"
18 19
20 #if defined(__SSE2__)
21 #include "pngstruct.h"
22
23 extern "C" void sk_png_init_filter_functions_sse2(png_structp png, unsigned int bpp) {
24 if (bpp == 4) {
25 png->read_filter[PNG_FILTER_VALUE_SUB -1] = sk_sub4_sse2;
26 png->read_filter[PNG_FILTER_VALUE_AVG -1] = sk_avg4_sse2;
27 png->read_filter[PNG_FILTER_VALUE_PAETH-1] = sk_paeth4_sse2;
28 }
29 }
30 #endif
31
19 /////////////////////////////////////////////////////////////////////////////// 32 ///////////////////////////////////////////////////////////////////////////////
20 // Helper macros 33 // Helper macros
21 /////////////////////////////////////////////////////////////////////////////// 34 ///////////////////////////////////////////////////////////////////////////////
22 35
23 #ifndef png_jmpbuf 36 #ifndef png_jmpbuf
24 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) 37 # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
25 #endif 38 #endif
26 39
27 /* These were dropped in libpng >= 1.4 */ 40 /* These were dropped in libpng >= 1.4 */
28 #ifndef png_infopp_NULL 41 #ifndef png_infopp_NULL
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 png_set_tRNS_to_alpha(png_ptr); 337 png_set_tRNS_to_alpha(png_ptr);
325 png_set_gray_to_rgb(png_ptr); 338 png_set_gray_to_rgb(png_ptr);
326 skColorType = kN32_SkColorType; 339 skColorType = kN32_SkColorType;
327 skAlphaType = kUnpremul_SkAlphaType; 340 skAlphaType = kUnpremul_SkAlphaType;
328 } else { 341 } else {
329 skColorType = kGray_8_SkColorType; 342 skColorType = kGray_8_SkColorType;
330 skAlphaType = kOpaque_SkAlphaType; 343 skAlphaType = kOpaque_SkAlphaType;
331 } 344 }
332 break; 345 break;
333 case PNG_COLOR_TYPE_GRAY_ALPHA: 346 case PNG_COLOR_TYPE_GRAY_ALPHA:
334 //FIXME: support gray with alpha as a color type 347 //FIXME: support gray with alpha as a color type
335 //convert to RGBA 348 //convert to RGBA
336 png_set_gray_to_rgb(png_ptr); 349 png_set_gray_to_rgb(png_ptr);
337 skColorType = kN32_SkColorType; 350 skColorType = kN32_SkColorType;
338 skAlphaType = kUnpremul_SkAlphaType; 351 skAlphaType = kUnpremul_SkAlphaType;
339 break; 352 break;
340 case PNG_COLOR_TYPE_RGBA: 353 case PNG_COLOR_TYPE_RGBA:
341 skColorType = kN32_SkColorType; 354 skColorType = kN32_SkColorType;
342 skAlphaType = kUnpremul_SkAlphaType; 355 skAlphaType = kUnpremul_SkAlphaType;
343 break; 356 break;
344 default: 357 default:
345 //all the color types have been covered above 358 //all the color types have been covered above
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo, 412 SkCodec::Result SkPngCodec::initializeSwizzler(const SkImageInfo& requestedInfo,
400 const Options& options, 413 const Options& options,
401 SkPMColor ctable[], 414 SkPMColor ctable[],
402 int* ctableCount) { 415 int* ctableCount) {
403 // FIXME: Could we use the return value of setjmp to specify the type of 416 // FIXME: Could we use the return value of setjmp to specify the type of
404 // error? 417 // error?
405 if (setjmp(png_jmpbuf(fPng_ptr))) { 418 if (setjmp(png_jmpbuf(fPng_ptr))) {
406 SkCodecPrintf("setjmp long jump!\n"); 419 SkCodecPrintf("setjmp long jump!\n");
407 return kInvalidInput; 420 return kInvalidInput;
408 } 421 }
409 png_read_update_info(fPng_ptr, fInfo_ptr); 422 png_read_update_info(fPng_ptr, fInfo_ptr);
410 423
411 //srcColorType was determined in read_header() which determined png color ty pe 424 //srcColorType was determined in read_header() which determined png color ty pe
412 const SkColorType srcColorType = this->getInfo().colorType(); 425 const SkColorType srcColorType = this->getInfo().colorType();
413 426
414 switch (srcColorType) { 427 switch (srcColorType) {
415 case kIndex_8_SkColorType: 428 case kIndex_8_SkColorType:
416 //decode palette to Skia format 429 //decode palette to Skia format
417 fSrcConfig = SkSwizzler::kIndex; 430 fSrcConfig = SkSwizzler::kIndex;
418 if (!this->decodePalette(kPremul_SkAlphaType == requestedInfo.alphaT ype(), 431 if (!this->decodePalette(kPremul_SkAlphaType == requestedInfo.alphaT ype(),
419 ctableCount)) { 432 ctableCount)) {
420 return kInvalidInput; 433 return kInvalidInput;
421 } 434 }
422 break; 435 break;
423 case kGray_8_SkColorType: 436 case kGray_8_SkColorType:
424 fSrcConfig = SkSwizzler::kGray; 437 fSrcConfig = SkSwizzler::kGray;
425 break; 438 break;
426 case kN32_SkColorType: 439 case kN32_SkColorType:
427 if (this->getInfo().alphaType() == kOpaque_SkAlphaType) { 440 if (this->getInfo().alphaType() == kOpaque_SkAlphaType) {
428 fSrcConfig = SkSwizzler::kRGB; 441 fSrcConfig = SkSwizzler::kRGB;
429 } else { 442 } else {
430 fSrcConfig = SkSwizzler::kRGBA; 443 fSrcConfig = SkSwizzler::kRGBA;
431 } 444 }
432 break; 445 break;
433 default: 446 default:
434 //would have exited before now if the colorType was supported by png 447 //would have exited before now if the colorType was supported by png
435 SkASSERT(false); 448 SkASSERT(false);
436 } 449 }
437 450
438 // Copy the color table to the client if they request kIndex8 mode 451 // Copy the color table to the client if they request kIndex8 mode
439 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount); 452 copy_color_table(requestedInfo, fColorTable, ctable, ctableCount);
440 453
441 // Create the swizzler. SkPngCodec retains ownership of the color table. 454 // Create the swizzler. SkPngCodec retains ownership of the color table.
442 const SkPMColor* colors = get_color_ptr(fColorTable.get()); 455 const SkPMColor* colors = get_color_ptr(fColorTable.get());
443 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo , options)); 456 fSwizzler.reset(SkSwizzler::CreateSwizzler(fSrcConfig, colors, requestedInfo , options));
444 if (!fSwizzler) { 457 if (!fSwizzler) {
445 // FIXME: CreateSwizzler could fail for another reason. 458 // FIXME: CreateSwizzler could fail for another reason.
446 return kUnimplemented; 459 return kUnimplemented;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 630
618 return row; 631 return row;
619 } 632 }
620 633
621 bool onSkipScanlines(int count) override { 634 bool onSkipScanlines(int count) override {
622 // Assume that an error in libpng indicates an incomplete input. 635 // Assume that an error in libpng indicates an incomplete input.
623 if (setjmp(png_jmpbuf(this->png_ptr()))) { 636 if (setjmp(png_jmpbuf(this->png_ptr()))) {
624 SkCodecPrintf("setjmp long jump!\n"); 637 SkCodecPrintf("setjmp long jump!\n");
625 return false; 638 return false;
626 } 639 }
627 //there is a potential tradeoff of memory vs speed created by putting th is in a loop. 640 //there is a potential tradeoff of memory vs speed created by putting th is in a loop.
628 //calling png_read_rows in a loop is insignificantly slower than calling it once with count 641 //calling png_read_rows in a loop is insignificantly slower than calling it once with count
629 //as png_read_rows has it's own loop which calls png_read_row count time s. 642 //as png_read_rows has it's own loop which calls png_read_row count time s.
630 for (int row = 0; row < count; row++) { 643 for (int row = 0; row < count; row++) {
631 png_read_rows(this->png_ptr(), &fSrcRow, png_bytepp_NULL, 1); 644 png_read_rows(this->png_ptr(), &fSrcRow, png_bytepp_NULL, 1);
632 } 645 }
633 return true; 646 return true;
634 } 647 }
635 648
636 private: 649 private:
637 SkAutoTMalloc<uint8_t> fStorage; 650 SkAutoTMalloc<uint8_t> fStorage;
638 uint8_t* fSrcRow; 651 uint8_t* fSrcRow;
(...skipping 10 matching lines...) Expand all
649 : INHERITED(srcInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, n umberPasses) 662 : INHERITED(srcInfo, stream, chunkReader, png_ptr, info_ptr, bitDepth, n umberPasses)
650 , fHeight(-1) 663 , fHeight(-1)
651 , fCanSkipRewind(false) 664 , fCanSkipRewind(false)
652 { 665 {
653 SkASSERT(numberPasses != 1); 666 SkASSERT(numberPasses != 1);
654 } 667 }
655 668
656 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti ons, 669 Result onStartScanlineDecode(const SkImageInfo& dstInfo, const Options& opti ons,
657 SkPMColor ctable[], int* ctableCount) override { 670 SkPMColor ctable[], int* ctableCount) override {
658 if (!conversion_possible(dstInfo, this->getInfo())) { 671 if (!conversion_possible(dstInfo, this->getInfo())) {
659 return kInvalidConversion; 672 return kInvalidConversion;
660 } 673 }
661 674
662 const Result result = this->initializeSwizzler(dstInfo, options, ctable, 675 const Result result = this->initializeSwizzler(dstInfo, options, ctable,
663 ctableCount); 676 ctableCount);
664 if (result != kSuccess) { 677 if (result != kSuccess) {
665 return result; 678 return result;
666 } 679 }
667 680
668 fHeight = dstInfo.height(); 681 fHeight = dstInfo.height();
669 // FIXME: This need not be called on a second call to onStartScanlineDec ode. 682 // FIXME: This need not be called on a second call to onStartScanlineDec ode.
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 } 791 }
779 792
780 if (1 == numberPasses) { 793 if (1 == numberPasses) {
781 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader, 794 return new SkPngScanlineDecoder(imageInfo, streamDeleter.detach(), chunk Reader,
782 png_ptr, info_ptr, bitDepth); 795 png_ptr, info_ptr, bitDepth);
783 } 796 }
784 797
785 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader, 798 return new SkPngInterlacedScanlineDecoder(imageInfo, streamDeleter.detach(), chunkReader,
786 png_ptr, info_ptr, bitDepth, numbe rPasses); 799 png_ptr, info_ptr, bitDepth, numbe rPasses);
787 } 800 }
OLDNEW
« no previous file with comments | « gyp/codec.gyp ('k') | src/codec/SkPngFilters.h » ('j') | src/codec/SkPngFilters.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698