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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkCodecPriv.h" | 9 #include "SkCodecPriv.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 if (setjmp(png_jmpbuf(fPng_ptr))) { | 811 if (setjmp(png_jmpbuf(fPng_ptr))) { |
812 SkCodecPrintf("Failed on png_read_update_info.\n"); | 812 SkCodecPrintf("Failed on png_read_update_info.\n"); |
813 return false; | 813 return false; |
814 } | 814 } |
815 png_read_update_info(fPng_ptr, fInfo_ptr); | 815 png_read_update_info(fPng_ptr, fInfo_ptr); |
816 | 816 |
817 // It's important to reset fColorXform to nullptr. We don't do this on rewi
nding | 817 // It's important to reset fColorXform to nullptr. We don't do this on rewi
nding |
818 // because the interlaced scanline decoder may need to rewind. | 818 // because the interlaced scanline decoder may need to rewind. |
819 fColorXform = nullptr; | 819 fColorXform = nullptr; |
820 SkImageInfo swizzlerInfo = dstInfo; | 820 SkImageInfo swizzlerInfo = dstInfo; |
| 821 Options swizzlerOptions = options; |
821 bool needsColorXform = needs_color_xform(dstInfo, this->getInfo()); | 822 bool needsColorXform = needs_color_xform(dstInfo, this->getInfo()); |
822 if (needsColorXform) { | 823 if (needsColorXform) { |
823 switch (dstInfo.colorType()) { | 824 switch (dstInfo.colorType()) { |
824 case kRGBA_8888_SkColorType: | 825 case kRGBA_8888_SkColorType: |
825 case kBGRA_8888_SkColorType: | 826 case kBGRA_8888_SkColorType: |
826 case kRGBA_F16_SkColorType: | 827 case kRGBA_F16_SkColorType: |
827 swizzlerInfo = swizzlerInfo.makeColorType(kRGBA_8888_SkColorType
); | 828 swizzlerInfo = swizzlerInfo.makeColorType(kRGBA_8888_SkColorType
); |
828 if (kPremul_SkAlphaType == dstInfo.alphaType()) { | 829 if (kPremul_SkAlphaType == dstInfo.alphaType()) { |
829 swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaT
ype); | 830 swizzlerInfo = swizzlerInfo.makeAlphaType(kUnpremul_SkAlphaT
ype); |
830 } | 831 } |
831 break; | 832 break; |
832 case kIndex_8_SkColorType: | 833 case kIndex_8_SkColorType: |
833 break; | 834 break; |
834 default: | 835 default: |
835 return false; | 836 return false; |
836 } | 837 } |
837 | 838 |
838 fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpac
e()), | 839 fColorXform = SkColorSpaceXform::New(sk_ref_sp(this->getInfo().colorSpac
e()), |
839 sk_ref_sp(dstInfo.colorSpace())); | 840 sk_ref_sp(dstInfo.colorSpace())); |
840 | 841 |
841 if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) { | 842 if (!fColorXform && kRGBA_F16_SkColorType == dstInfo.colorType()) { |
842 return false; | 843 return false; |
843 } | 844 } |
| 845 |
| 846 // When there is a color xform, we swizzle into temporary memory, which
is not |
| 847 // zero initialized. |
| 848 // FIXME (msarett): |
| 849 // Is this a problem? |
| 850 swizzlerOptions.fZeroInitialized = kNo_ZeroInitialized; |
844 } | 851 } |
845 | 852 |
846 if (SkEncodedInfo::kPalette_Color == this->getEncodedInfo().color()) { | 853 if (SkEncodedInfo::kPalette_Color == this->getEncodedInfo().color()) { |
847 if (!this->createColorTable(dstInfo, ctableCount)) { | 854 if (!this->createColorTable(dstInfo, ctableCount)) { |
848 return false; | 855 return false; |
849 } | 856 } |
850 } | 857 } |
851 | 858 |
852 // Copy the color table to the client if they request kIndex8 mode | 859 // Copy the color table to the client if they request kIndex8 mode |
853 copy_color_table(swizzlerInfo, fColorTable, ctable, ctableCount); | 860 copy_color_table(swizzlerInfo, fColorTable, ctable, ctableCount); |
854 | 861 |
855 // Create the swizzler. SkPngCodec retains ownership of the color table. | 862 // Create the swizzler. SkPngCodec retains ownership of the color table. |
856 const SkPMColor* colors = get_color_ptr(fColorTable.get()); | 863 const SkPMColor* colors = get_color_ptr(fColorTable.get()); |
857 fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colors, s
wizzlerInfo, | 864 fSwizzler.reset(SkSwizzler::CreateSwizzler(this->getEncodedInfo(), colors, s
wizzlerInfo, |
858 options)); | 865 swizzlerOptions)); |
859 SkASSERT(fSwizzler); | 866 SkASSERT(fSwizzler); |
860 return true; | 867 return true; |
861 } | 868 } |
862 | 869 |
863 bool SkPngCodec::onRewind() { | 870 bool SkPngCodec::onRewind() { |
864 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header | 871 // This sets fPng_ptr and fInfo_ptr to nullptr. If read_header |
865 // succeeds, they will be repopulated, and if it fails, they will | 872 // succeeds, they will be repopulated, and if it fails, they will |
866 // remain nullptr. Any future accesses to fPng_ptr and fInfo_ptr will | 873 // remain nullptr. Any future accesses to fPng_ptr and fInfo_ptr will |
867 // come through this function which will rewind and again attempt | 874 // come through this function which will rewind and again attempt |
868 // to reinitialize them. | 875 // to reinitialize them. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 SkCodec* outCodec; | 924 SkCodec* outCodec; |
918 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { | 925 if (read_header(stream, chunkReader, &outCodec, nullptr, nullptr)) { |
919 // Codec has taken ownership of the stream. | 926 // Codec has taken ownership of the stream. |
920 SkASSERT(outCodec); | 927 SkASSERT(outCodec); |
921 streamDeleter.release(); | 928 streamDeleter.release(); |
922 return outCodec; | 929 return outCodec; |
923 } | 930 } |
924 | 931 |
925 return nullptr; | 932 return nullptr; |
926 } | 933 } |
OLD | NEW |