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 "DMSrcSink.h" | 8 #include "DMSrcSink.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkAndroidCodec.h" | 10 #include "SkAndroidCodec.h" |
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 } | 827 } |
828 return codec->getInfo().dimensions(); | 828 return codec->getInfo().dimensions(); |
829 } | 829 } |
830 | 830 |
831 Name ImageGenSrc::name() const { | 831 Name ImageGenSrc::name() const { |
832 return SkOSPath::Basename(fPath.c_str()); | 832 return SkOSPath::Basename(fPath.c_str()); |
833 } | 833 } |
834 | 834 |
835 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 835 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
836 | 836 |
837 ColorCodecSrc::ColorCodecSrc(Path path, Mode mode) | 837 ColorCodecSrc::ColorCodecSrc(Path path, Mode mode, SkColorType colorType) |
838 : fPath(path) | 838 : fPath(path) |
839 , fMode(mode) | 839 , fMode(mode) |
| 840 , fColorType(colorType) |
840 {} | 841 {} |
841 | 842 |
842 bool ColorCodecSrc::veto(SinkFlags flags) const { | 843 bool ColorCodecSrc::veto(SinkFlags flags) const { |
843 // Test to direct raster backends (8888 and 565). | 844 // Test to direct raster backends (8888 and 565). |
844 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; | 845 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; |
845 } | 846 } |
846 | 847 |
847 Error ColorCodecSrc::draw(SkCanvas* canvas) const { | 848 Error ColorCodecSrc::draw(SkCanvas* canvas) const { |
848 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | 849 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
849 return Error::Nonfatal("No need to test color correction to 565 backend.
"); | 850 return Error::Nonfatal("No need to test color correction to 565 backend.
"); |
850 } | 851 } |
851 | 852 |
| 853 if (nullptr == canvas->imageInfo().colorSpace() && kRGBA_F16_SkColorType ==
fColorType) { |
| 854 return Error::Nonfatal("F16 does not draw in legacy mode."); |
| 855 } |
| 856 |
852 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 857 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
853 if (!encoded) { | 858 if (!encoded) { |
854 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 859 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
855 } | 860 } |
856 | 861 |
857 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 862 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
858 if (nullptr == codec.get()) { | 863 if (nullptr == codec.get()) { |
859 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); | 864 return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str()); |
860 } | 865 } |
861 | 866 |
862 SkImageInfo info = codec->getInfo().makeColorType(kN32_SkColorType); | 867 SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
863 SkBitmap bitmap; | 868 SkBitmap bitmap; |
864 if (!bitmap.tryAllocPixels(info)) { | 869 if (!bitmap.tryAllocPixels(info)) { |
865 return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(), | 870 return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(), |
866 info.width(), info.height()); | 871 info.width(), info.height()); |
867 } | 872 } |
868 | 873 |
869 SkImageInfo decodeInfo = info; | 874 SkImageInfo decodeInfo = info; |
870 if (kBaseline_Mode != fMode) { | 875 size_t srcRowBytes = sizeof(SkPMColor) * info.width(); |
| 876 SkAutoMalloc src(srcRowBytes * info.height()); |
| 877 void* srcPixels = src.get(); |
| 878 if (kBaseline_Mode == fMode) { |
| 879 srcPixels = bitmap.getPixels(); |
| 880 } else { |
871 decodeInfo = decodeInfo.makeColorType(kRGBA_8888_SkColorType); | 881 decodeInfo = decodeInfo.makeColorType(kRGBA_8888_SkColorType); |
872 } | 882 } |
873 | 883 |
874 SkCodec::Result r = codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.
rowBytes()); | 884 SkCodec::Result r = codec->getPixels(decodeInfo, srcPixels, srcRowBytes); |
875 if (SkCodec::kSuccess != r) { | 885 if (SkCodec::kSuccess != r) { |
876 return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_st
r(), r); | 886 return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_st
r(), r); |
877 } | 887 } |
878 | 888 |
879 // Load the dst ICC profile. This particular dst is fairly similar to Adobe
RGB. | 889 // Load the dst ICC profile. This particular dst is fairly similar to Adobe
RGB. |
880 sk_sp<SkData> dstData = SkData::MakeFromFileName( | 890 sk_sp<SkData> dstData = SkData::MakeFromFileName( |
881 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); | 891 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); |
882 if (!dstData) { | 892 if (!dstData) { |
883 return "Cannot read monitor profile. Is the resource path set correctly
?"; | 893 return "Cannot read monitor profile. Is the resource path set correctly
?"; |
884 } | 894 } |
885 | 895 |
886 switch (fMode) { | 896 switch (fMode) { |
887 case kBaseline_Mode: | 897 case kBaseline_Mode: |
888 canvas->drawBitmap(bitmap, 0, 0); | 898 canvas->drawBitmap(bitmap, 0, 0); |
889 break; | 899 break; |
890 case kDst_sRGB_Mode: | 900 case kDst_sRGB_Mode: |
891 case kDst_HPZR30w_Mode: { | 901 case kDst_HPZR30w_Mode: { |
892 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); | 902 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); |
893 sk_sp<SkColorSpace> dstSpace = (kDst_sRGB_Mode == fMode) ? | 903 sk_sp<SkColorSpace> dstSpace = (kDst_sRGB_Mode == fMode) ? |
894 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : | 904 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : |
895 SkColorSpace::NewICC(dstData->data(), dstData->size()); | 905 SkColorSpace::NewICC(dstData->data(), dstData->size()); |
896 SkASSERT(dstSpace); | 906 SkASSERT(dstSpace); |
897 | 907 |
898 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(sr
cSpace, dstSpace); | 908 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(sr
cSpace, dstSpace); |
899 if (!xform) { | 909 if (!xform) { |
900 return "Unimplemented color conversion."; | 910 return "Unimplemented color conversion."; |
901 } | 911 } |
902 | 912 |
903 uint32_t* row = (uint32_t*) bitmap.getPixels(); | 913 if (kN32_SkColorType == fColorType) { |
904 for (int y = 0; y < info.height(); y++) { | 914 uint32_t* srcRow = (uint32_t*) srcPixels; |
905 xform->xform_RGB1_8888(row, row, info.width()); | 915 uint32_t* dstRow = (uint32_t*) bitmap.getPixels(); |
906 row = SkTAddOffset<uint32_t>(row, bitmap.rowBytes()); | 916 for (int y = 0; y < info.height(); y++) { |
| 917 xform->applyTo8888(dstRow, srcRow, info.width()); |
| 918 srcRow = SkTAddOffset<uint32_t>(srcRow, srcRowBytes); |
| 919 dstRow = SkTAddOffset<uint32_t>(dstRow, bitmap.rowBytes()); |
| 920 } |
| 921 } else { |
| 922 SkASSERT(kRGBA_F16_SkColorType == fColorType); |
| 923 |
| 924 uint32_t* srcRow = (uint32_t*) srcPixels; |
| 925 uint64_t* dstRow = (uint64_t*) bitmap.getPixels(); |
| 926 for (int y = 0; y < info.height(); y++) { |
| 927 xform->applyToF16(dstRow, srcRow, info.width()); |
| 928 srcRow = SkTAddOffset<uint32_t>(srcRow, srcRowBytes); |
| 929 dstRow = SkTAddOffset<uint64_t>(dstRow, bitmap.rowBytes()); |
| 930 } |
907 } | 931 } |
908 | 932 |
909 canvas->drawBitmap(bitmap, 0, 0); | 933 canvas->drawBitmap(bitmap, 0, 0); |
910 break; | 934 break; |
911 } | 935 } |
912 #if defined(SK_TEST_QCMS) | 936 #if defined(SK_TEST_QCMS) |
913 case kQCMS_HPZR30w_Mode: { | 937 case kQCMS_HPZR30w_Mode: { |
914 sk_sp<SkData> srcData = codec->getICCData(); | 938 sk_sp<SkData> srcData = codec->getICCData(); |
915 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | 939 SkAutoTCallVProc<qcms_profile, qcms_profile_release> |
916 srcSpace(qcms_profile_from_memory(srcData->data(), srcData->
size())); | 940 srcSpace(qcms_profile_from_memory(srcData->data(), srcData->
size())); |
(...skipping 16 matching lines...) Expand all Loading... |
933 return SkStringPrintf("QCMS cannot create transform for %s.\n",
fPath.c_str()); | 957 return SkStringPrintf("QCMS cannot create transform for %s.\n",
fPath.c_str()); |
934 } | 958 } |
935 | 959 |
936 #ifdef SK_PMCOLOR_IS_RGBA | 960 #ifdef SK_PMCOLOR_IS_RGBA |
937 qcms_output_type outType = QCMS_OUTPUT_RGBX; | 961 qcms_output_type outType = QCMS_OUTPUT_RGBX; |
938 #else | 962 #else |
939 qcms_output_type outType = QCMS_OUTPUT_BGRX; | 963 qcms_output_type outType = QCMS_OUTPUT_BGRX; |
940 #endif | 964 #endif |
941 | 965 |
942 // Perform color correction. | 966 // Perform color correction. |
943 uint32_t* row = (uint32_t*) bitmap.getPixels(); | 967 uint32_t* srcRow = (uint32_t*) srcPixels; |
| 968 uint32_t* dstRow = (uint32_t*) bitmap.getPixels(); |
944 for (int y = 0; y < info.height(); y++) { | 969 for (int y = 0; y < info.height(); y++) { |
945 qcms_transform_data_type(transform, row, row, info.width(), outT
ype); | 970 qcms_transform_data_type(transform, srcRow, dstRow, info.width()
, outType); |
946 row = SkTAddOffset<uint32_t>(row, bitmap.rowBytes()); | 971 srcRow = SkTAddOffset<uint32_t>(srcRow, srcRowBytes); |
| 972 dstRow = SkTAddOffset<uint32_t>(dstRow, bitmap.rowBytes()); |
947 } | 973 } |
948 | 974 |
949 canvas->drawBitmap(bitmap, 0, 0); | 975 canvas->drawBitmap(bitmap, 0, 0); |
950 break; | 976 break; |
951 } | 977 } |
952 #endif | 978 #endif |
953 default: | 979 default: |
954 SkASSERT(false); | 980 SkASSERT(false); |
955 return "Invalid fMode"; | 981 return "Invalid fMode"; |
956 } | 982 } |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 skr.visit(i, drawsAsSingletonPictures); | 1580 skr.visit(i, drawsAsSingletonPictures); |
1555 } | 1581 } |
1556 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1582 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
1557 | 1583 |
1558 canvas->drawPicture(macroPic); | 1584 canvas->drawPicture(macroPic); |
1559 return check_against_reference(bitmap, src, fSink); | 1585 return check_against_reference(bitmap, src, fSink); |
1560 }); | 1586 }); |
1561 } | 1587 } |
1562 | 1588 |
1563 } // namespace DM | 1589 } // namespace DM |
OLD | NEW |