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" | |
10 #include "SkAndroidCodec.h" | 9 #include "SkAndroidCodec.h" |
11 #include "SkCodec.h" | 10 #include "SkCodec.h" |
12 #include "SkCodecImageGenerator.h" | 11 #include "SkCodecImageGenerator.h" |
13 #include "SkColorSpace.h" | 12 #include "SkColorSpace.h" |
14 #include "SkColorSpace_Base.h" | 13 #include "SkColorSpace_Base.h" |
15 #include "SkColorSpaceXform.h" | |
16 #include "SkCommonFlags.h" | 14 #include "SkCommonFlags.h" |
17 #include "SkData.h" | 15 #include "SkData.h" |
18 #include "SkDocument.h" | 16 #include "SkDocument.h" |
19 #include "SkError.h" | 17 #include "SkError.h" |
20 #include "SkImageGenerator.h" | 18 #include "SkImageGenerator.h" |
21 #include "SkImageGeneratorCG.h" | 19 #include "SkImageGeneratorCG.h" |
22 #include "SkImageGeneratorWIC.h" | 20 #include "SkImageGeneratorWIC.h" |
23 #include "SkMallocPixelRef.h" | 21 #include "SkMallocPixelRef.h" |
24 #include "SkMultiPictureDraw.h" | 22 #include "SkMultiPictureDraw.h" |
25 #include "SkNullCanvas.h" | 23 #include "SkNullCanvas.h" |
26 #include "SkOSFile.h" | 24 #include "SkOSFile.h" |
27 #include "SkOpts.h" | 25 #include "SkOpts.h" |
28 #include "SkPictureData.h" | 26 #include "SkPictureData.h" |
29 #include "SkPictureRecorder.h" | 27 #include "SkPictureRecorder.h" |
30 #include "SkRandom.h" | 28 #include "SkRandom.h" |
31 #include "SkRecordDraw.h" | 29 #include "SkRecordDraw.h" |
32 #include "SkRecorder.h" | 30 #include "SkRecorder.h" |
33 #include "SkSVGCanvas.h" | 31 #include "SkSVGCanvas.h" |
34 #include "SkStream.h" | 32 #include "SkStream.h" |
35 #include "SkTLogic.h" | 33 #include "SkTLogic.h" |
36 #include "SkXMLWriter.h" | 34 #include "SkXMLWriter.h" |
37 #include "SkSwizzler.h" | 35 #include "SkSwizzler.h" |
38 #include <functional> | 36 #include <functional> |
39 | 37 |
40 #if defined(SK_BUILD_FOR_WIN) | 38 #if defined(SK_BUILD_FOR_WIN) |
41 #include "SkAutoCoInitialize.h" | 39 #include "SkAutoCoInitialize.h" |
42 #endif | 40 #endif |
43 | 41 |
44 #include "qcms.h" | |
45 | |
46 DEFINE_bool(multiPage, false, "For document-type backends, render the source" | 42 DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
47 " into multiple pages"); | 43 " into multiple pages"); |
48 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); | 44 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); |
49 | 45 |
50 using sk_gpu_test::GrContextFactory; | 46 using sk_gpu_test::GrContextFactory; |
51 | 47 |
52 namespace DM { | 48 namespace DM { |
53 | 49 |
54 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 50 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
55 | 51 |
(...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 } | 844 } |
849 return codec->getInfo().dimensions(); | 845 return codec->getInfo().dimensions(); |
850 } | 846 } |
851 | 847 |
852 Name ImageGenSrc::name() const { | 848 Name ImageGenSrc::name() const { |
853 return SkOSPath::Basename(fPath.c_str()); | 849 return SkOSPath::Basename(fPath.c_str()); |
854 } | 850 } |
855 | 851 |
856 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 852 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
857 | 853 |
858 ColorCodecSrc::ColorCodecSrc(Path path, Mode mode) | 854 ColorCodecSrc::ColorCodecSrc(Path path, Mode mode, sk_sp<SkColorSpace> dstSpace) |
859 : fPath(path) | 855 : fPath(path) |
860 , fMode(mode) | 856 , fMode(mode) |
| 857 , fDstSpace(dstSpace) |
861 {} | 858 {} |
862 | 859 |
863 bool ColorCodecSrc::veto(SinkFlags flags) const { | 860 bool ColorCodecSrc::veto(SinkFlags flags) const { |
864 // Test to direct raster backends (8888 and 565). | 861 // Test to direct raster backends (8888 and 565). |
865 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; | 862 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDir
ect; |
866 } | 863 } |
867 | 864 |
| 865 static uint8_t clampFloatToByte(float v) { |
| 866 v = v * 255.0f; |
| 867 if (v > 255.0f) { |
| 868 return 255; |
| 869 } else if (v < 0.0f) { |
| 870 return 0; |
| 871 } else { |
| 872 return (uint8_t) (v + 0.5f); |
| 873 } |
| 874 } |
| 875 |
868 Error ColorCodecSrc::draw(SkCanvas* canvas) const { | 876 Error ColorCodecSrc::draw(SkCanvas* canvas) const { |
869 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { | 877 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) { |
870 return Error::Nonfatal("No need to test color correction to 565 backend.
"); | 878 return Error::Nonfatal("No need to test color correction to 565 backend.
"); |
871 } | 879 } |
872 | 880 |
873 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); | 881 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str())); |
874 if (!encoded) { | 882 if (!encoded) { |
875 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); | 883 return SkStringPrintf("Couldn't read %s.", fPath.c_str()); |
876 } | 884 } |
877 | 885 |
(...skipping 12 matching lines...) Expand all Loading... |
890 SkImageInfo decodeInfo = info; | 898 SkImageInfo decodeInfo = info; |
891 if (kBaseline_Mode != fMode) { | 899 if (kBaseline_Mode != fMode) { |
892 decodeInfo = decodeInfo.makeColorType(kRGBA_8888_SkColorType); | 900 decodeInfo = decodeInfo.makeColorType(kRGBA_8888_SkColorType); |
893 } | 901 } |
894 | 902 |
895 SkCodec::Result r = codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.
rowBytes()); | 903 SkCodec::Result r = codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.
rowBytes()); |
896 if (SkCodec::kSuccess != r) { | 904 if (SkCodec::kSuccess != r) { |
897 return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_st
r(), r); | 905 return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_st
r(), r); |
898 } | 906 } |
899 | 907 |
900 // Load the dst ICC profile. This particular dst is fairly similar to Adobe
RGB. | |
901 sk_sp<SkData> dstData = SkData::MakeFromFileName( | |
902 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); | |
903 if (!dstData) { | |
904 return "Cannot read monitor profile. Is the resource path set correctly
?"; | |
905 } | |
906 | |
907 switch (fMode) { | 908 switch (fMode) { |
908 case kBaseline_Mode: | 909 case kBaseline_Mode: |
909 canvas->drawBitmap(bitmap, 0, 0); | 910 canvas->drawBitmap(bitmap, 0, 0); |
910 break; | 911 break; |
911 case kDst_HPZR30w_Mode: { | 912 case kDst_HPZR30w_Mode: { |
912 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); | 913 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); |
913 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewICC(dstData->data(),
dstData->size()); | 914 if (!srcSpace) { |
914 SkASSERT(dstSpace); | 915 return SkStringPrintf("Cannot test color correction without a sr
c profile."); |
915 | 916 } else if (!as_CSB(srcSpace)->gammas()->isValues()) { |
916 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(sr
cSpace, dstSpace); | |
917 if (!xform) { | |
918 // FIXME (msarett): | 917 // FIXME (msarett): |
919 // I haven't implemented conversions for all of the images that
I've uploaded for | 918 // The conversion here doesn't cover all of the images that I've
uploaded for |
920 // testing. Once we support all of them, this should be a fatal
error. | 919 // testing. Once we support all of them, this should be a fatal
error. |
921 return Error::Nonfatal("Unimplemented color conversion."); | 920 return Error::Nonfatal("Unimplemented gamma conversion."); |
922 } | 921 } |
923 | 922 |
924 uint32_t* row = (uint32_t*) bitmap.getPixels(); | 923 // Build a matrix to transform to dst gamut. |
| 924 // srcToDst = inverse(dstToXYZ) * srcToXYZ |
| 925 const SkMatrix44& srcToXYZ = srcSpace->xyz(); |
| 926 const SkMatrix44& dstToXYZ = fDstSpace->xyz(); |
| 927 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); |
| 928 dstToXYZ.invert(&srcToDst); |
| 929 srcToDst.postConcat(srcToXYZ); |
| 930 |
925 for (int y = 0; y < info.height(); y++) { | 931 for (int y = 0; y < info.height(); y++) { |
926 xform->xform_RGBA_8888(row, row, info.width()); | 932 for (int x = 0; x < info.width(); x++) { |
927 row = SkTAddOffset<uint32_t>(row, bitmap.rowBytes()); | 933 // Extract floats. |
| 934 uint32_t* pixelPtr = (uint32_t*) bitmap.getAddr(x, y); |
| 935 float src[3]; |
| 936 src[0] = ((*pixelPtr >> 0) & 0xFF) / 255.0f; |
| 937 src[1] = ((*pixelPtr >> 8) & 0xFF) / 255.0f; |
| 938 src[2] = ((*pixelPtr >> 16) & 0xFF) / 255.0f; |
| 939 |
| 940 // Convert to linear. |
| 941 src[0] = pow(src[0], as_CSB(srcSpace)->gammas()->fRed.fValue
); |
| 942 src[1] = pow(src[1], as_CSB(srcSpace)->gammas()->fGreen.fVal
ue); |
| 943 src[2] = pow(src[2], as_CSB(srcSpace)->gammas()->fBlue.fValu
e); |
| 944 |
| 945 // Convert to dst gamut. |
| 946 float dst[3]; |
| 947 dst[0] = src[0]*srcToDst.getFloat(0, 0) + src[1]*srcToDst.ge
tFloat(1, 0) + |
| 948 src[2]*srcToDst.getFloat(2, 0) + srcToDst.getFloat(
3, 0); |
| 949 dst[1] = src[0]*srcToDst.getFloat(0, 1) + src[1]*srcToDst.ge
tFloat(1, 1) + |
| 950 src[2]*srcToDst.getFloat(2, 1) + srcToDst.getFloat(
3, 1); |
| 951 dst[2] = src[0]*srcToDst.getFloat(0, 2) + src[1]*srcToDst.ge
tFloat(1, 2) + |
| 952 src[2]*srcToDst.getFloat(2, 2) + srcToDst.getFloat(
3, 2); |
| 953 |
| 954 // Convert to dst gamma. |
| 955 dst[0] = pow(dst[0], 1.0f / as_CSB(fDstSpace)->gammas()->fRe
d.fValue); |
| 956 dst[1] = pow(dst[1], 1.0f / as_CSB(fDstSpace)->gammas()->fGr
een.fValue); |
| 957 dst[2] = pow(dst[2], 1.0f / as_CSB(fDstSpace)->gammas()->fBl
ue.fValue); |
| 958 |
| 959 *pixelPtr = SkPackARGB32NoCheck(((*pixelPtr >> 24) & 0xFF), |
| 960 clampFloatToByte(dst[0]), |
| 961 clampFloatToByte(dst[1]), |
| 962 clampFloatToByte(dst[2])); |
| 963 } |
928 } | 964 } |
929 | 965 |
930 canvas->drawBitmap(bitmap, 0, 0); | 966 canvas->drawBitmap(bitmap, 0, 0); |
931 break; | |
932 } | |
933 case kQCMS_HPZR30w_Mode: { | |
934 sk_sp<SkData> srcData = codec->getICCData(); | |
935 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | |
936 srcSpace(qcms_profile_from_memory(srcData->data(), srcData->
size())); | |
937 if (!srcSpace) { | |
938 return Error::Nonfatal(SkStringPrintf("QCMS cannot create profil
e for %s.\n", | |
939 fPath.c_str())); | |
940 } | |
941 | |
942 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | |
943 dstSpace(qcms_profile_from_memory(dstData->data(), dstData->
size())); | |
944 SkASSERT(dstSpace); | |
945 SkAutoTCallVProc<qcms_transform, qcms_transform_release> | |
946 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8,
dstSpace, | |
947 QCMS_DATA_RGBA_8, QCMS_INTE
NT_PERCEPTUAL)); | |
948 if (!transform) { | |
949 return SkStringPrintf("QCMS cannot create transform for %s.\n",
fPath.c_str()); | |
950 } | |
951 | |
952 #ifdef SK_PMCOLOR_IS_RGBA | |
953 qcms_output_type outType = QCMS_OUTPUT_RGBX; | |
954 #else | |
955 qcms_output_type outType = QCMS_OUTPUT_BGRX; | |
956 #endif | |
957 | |
958 // Perform color correction. | |
959 uint32_t* row = (uint32_t*) bitmap.getPixels(); | |
960 for (int y = 0; y < info.height(); y++) { | |
961 qcms_transform_data_type(transform, row, row, info.width(), outT
ype); | |
962 row = SkTAddOffset<uint32_t>(row, bitmap.rowBytes()); | |
963 } | |
964 | |
965 canvas->drawBitmap(bitmap, 0, 0); | |
966 break; | 967 break; |
967 } | 968 } |
968 default: | 969 default: |
969 SkASSERT(false); | 970 SkASSERT(false); |
970 return "Invalid fMode"; | 971 return "Invalid fMode"; |
971 } | 972 } |
972 return ""; | 973 return ""; |
973 } | 974 } |
974 | 975 |
975 SkISize ColorCodecSrc::size() const { | 976 SkISize ColorCodecSrc::size() const { |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 skr.visit(i, drawsAsSingletonPictures); | 1554 skr.visit(i, drawsAsSingletonPictures); |
1554 } | 1555 } |
1555 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1556 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
1556 | 1557 |
1557 canvas->drawPicture(macroPic); | 1558 canvas->drawPicture(macroPic); |
1558 return check_against_reference(bitmap, src, fSink); | 1559 return check_against_reference(bitmap, src, fSink); |
1559 }); | 1560 }); |
1560 } | 1561 } |
1561 | 1562 |
1562 } // namespace DM | 1563 } // namespace DM |
OLD | NEW |