| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "CrashHandler.h" | 8 #include "CrashHandler.h" |
| 9 #include "DMJsonWriter.h" | 9 #include "DMJsonWriter.h" |
| 10 #include "DMSrcSink.h" | 10 #include "DMSrcSink.h" |
| 11 #include "DMSrcSinkAndroid.h" | 11 #include "DMSrcSinkAndroid.h" |
| 12 #include "ProcStats.h" | 12 #include "ProcStats.h" |
| 13 #include "Resources.h" | 13 #include "Resources.h" |
| 14 #include "SkBBHFactory.h" | 14 #include "SkBBHFactory.h" |
| 15 #include "SkChecksum.h" | 15 #include "SkChecksum.h" |
| 16 #include "SkCodec.h" | 16 #include "SkCodec.h" |
| 17 #include "SkColorPriv.h" | 17 #include "SkColorPriv.h" |
| 18 #include "SkCommonFlags.h" | 18 #include "SkCommonFlags.h" |
| 19 #include "SkCommonFlagsConfig.h" | 19 #include "SkCommonFlagsConfig.h" |
| 20 #include "SkData.h" |
| 20 #include "SkFontMgr.h" | 21 #include "SkFontMgr.h" |
| 21 #include "SkGraphics.h" | 22 #include "SkGraphics.h" |
| 22 #include "SkHalf.h" | 23 #include "SkHalf.h" |
| 23 #include "SkMD5.h" | 24 #include "SkMD5.h" |
| 24 #include "SkMutex.h" | 25 #include "SkMutex.h" |
| 25 #include "SkOSFile.h" | 26 #include "SkOSFile.h" |
| 26 #include "SkPM4fPriv.h" | 27 #include "SkPM4fPriv.h" |
| 27 #include "SkSpinlock.h" | 28 #include "SkSpinlock.h" |
| 28 #include "SkTHash.h" | 29 #include "SkTHash.h" |
| 29 #include "SkTaskGroup.h" | 30 #include "SkTaskGroup.h" |
| 30 #include "SkThreadUtils.h" | 31 #include "SkThreadUtils.h" |
| 31 #include "Test.h" | 32 #include "Test.h" |
| 32 #include "Timer.h" | 33 #include "Timer.h" |
| 34 #include "picture_utils.h" |
| 33 #include "sk_tool_utils.h" | 35 #include "sk_tool_utils.h" |
| 34 | 36 |
| 35 #ifdef SK_PDF_IMAGE_STATS | 37 #ifdef SK_PDF_IMAGE_STATS |
| 36 extern void SkPDFImageDumpStats(); | 38 extern void SkPDFImageDumpStats(); |
| 37 #endif | 39 #endif |
| 38 | 40 |
| 39 #include "png.h" | 41 #include "png.h" |
| 40 | 42 |
| 41 #include <stdlib.h> | 43 #include <stdlib.h> |
| 42 | 44 |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 } | 919 } |
| 918 if (sink) { | 920 if (sink) { |
| 919 push_sink(config, sink); | 921 push_sink(config, sink); |
| 920 } | 922 } |
| 921 } | 923 } |
| 922 } | 924 } |
| 923 | 925 |
| 924 static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { | 926 static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 925 const int w = bitmap.width(), | 927 const int w = bitmap.width(), |
| 926 h = bitmap.height(); | 928 h = bitmap.height(); |
| 927 // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too). | |
| 928 // We leave the gamma of these bytes unspecified, to continue the status quo
, | |
| 929 // which we think generally is to interpret them as sRGB. | |
| 930 | 929 |
| 931 SkAutoTMalloc<uint32_t> rgba(w*h); | 930 sk_sp<SkData> encodedBitmap = sk_tools::encode_bitmap_for_png(bitmap); |
| 932 | 931 if (encodedBitmap.get() == nullptr) { |
| 933 if (bitmap. colorType() == kN32_SkColorType && | 932 return false; |
| 934 bitmap.profileType() == kSRGB_SkColorProfileType) { | |
| 935 // These are premul sRGB 8-bit pixels in SkPMColor order. | |
| 936 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there vi
a floats. | |
| 937 bitmap.lockPixels(); | |
| 938 auto px = (const uint32_t*)bitmap.getPixels(); | |
| 939 if (!px) { | |
| 940 return false; | |
| 941 } | |
| 942 for (int i = 0; i < w*h; i++) { | |
| 943 Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear float
s. | |
| 944 #if defined(SK_PMCOLOR_IS_BGRA) | |
| 945 fs = SkNx_shuffle<2,1,0,3>(fs); // Shuffle to RGBA, if not th
ere already. | |
| 946 #endif | |
| 947 float invA = 1.0f / fs[3]; | |
| 948 fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. | |
| 949 rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. | |
| 950 } | |
| 951 | |
| 952 } else if (bitmap.colorType() == kRGBA_F16_SkColorType) { | |
| 953 // These are premul linear half-float pixels in RGBA order. | |
| 954 // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there vi
a floats. | |
| 955 bitmap.lockPixels(); | |
| 956 auto px = (const uint64_t*)bitmap.getPixels(); | |
| 957 if (!px) { | |
| 958 return false; | |
| 959 } | |
| 960 for (int i = 0; i < w*h; i++) { | |
| 961 // Convert up to linear floats. | |
| 962 Sk4f fs(SkHalfToFloat(static_cast<SkHalf>(px[i] >> (0 * 16))), | |
| 963 SkHalfToFloat(static_cast<SkHalf>(px[i] >> (1 * 16))), | |
| 964 SkHalfToFloat(static_cast<SkHalf>(px[i] >> (2 * 16))), | |
| 965 SkHalfToFloat(static_cast<SkHalf>(px[i] >> (3 * 16)))); | |
| 966 fs = Sk4f::Max(0.0f, Sk4f::Min(fs, 1.0f)); // Clamp | |
| 967 float invA = 1.0f / fs[3]; | |
| 968 fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. | |
| 969 rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. | |
| 970 } | |
| 971 | |
| 972 | |
| 973 } else { | |
| 974 // We "should" gamma correct in here but we don't. | |
| 975 // We want Gold to show exactly what our clients are seeing, broken gamm
a. | |
| 976 | |
| 977 // Convert smaller formats up to premul linear 8-bit (in SkPMColor order
). | |
| 978 if (bitmap.colorType() != kN32_SkColorType) { | |
| 979 SkBitmap n32; | |
| 980 if (!bitmap.copyTo(&n32, kN32_SkColorType)) { | |
| 981 return false; | |
| 982 } | |
| 983 bitmap = n32; | |
| 984 } | |
| 985 | |
| 986 // Convert premul linear 8-bit to unpremul linear 8-bit RGBA. | |
| 987 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, | |
| 988 kUnpremul_SkAlphaType), | |
| 989 rgba, 4*w, 0,0)) { | |
| 990 return false; | |
| 991 } | |
| 992 } | 933 } |
| 934 uint32_t* rgba = static_cast<uint32_t*>(encodedBitmap.get()->writable_data()
); |
| 993 | 935 |
| 994 // We don't need bitmap anymore. Might as well drop our ref. | 936 // We don't need bitmap anymore. Might as well drop our ref. |
| 995 bitmap.reset(); | 937 bitmap.reset(); |
| 996 | 938 |
| 997 FILE* f = fopen(path, "wb"); | 939 FILE* f = fopen(path, "wb"); |
| 998 if (!f) { return false; } | 940 if (!f) { return false; } |
| 999 | 941 |
| 1000 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nu
llptr, nullptr); | 942 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nu
llptr, nullptr); |
| 1001 if (!png) { | 943 if (!png) { |
| 1002 fclose(f); | 944 fclose(f); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1029 text[1].text = (png_charp)description.c_str(); | 971 text[1].text = (png_charp)description.c_str(); |
| 1030 text[1].compression = PNG_TEXT_COMPRESSION_NONE; | 972 text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 1031 png_set_text(png, info, text, 2); | 973 png_set_text(png, info, text, 2); |
| 1032 | 974 |
| 1033 png_init_io(png, f); | 975 png_init_io(png, f); |
| 1034 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, | 976 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 1035 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, | 977 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 1036 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | 978 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 1037 png_write_info(png, info); | 979 png_write_info(png, info); |
| 1038 for (int j = 0; j < h; j++) { | 980 for (int j = 0; j < h; j++) { |
| 1039 png_bytep row = (png_bytep)(rgba.get() + w*j); | 981 png_bytep row = (png_bytep)(rgba + w*j); |
| 1040 png_write_rows(png, &row, 1); | 982 png_write_rows(png, &row, 1); |
| 1041 } | 983 } |
| 1042 png_write_end(png, info); | 984 png_write_end(png, info); |
| 1043 | 985 |
| 1044 png_destroy_write_struct(&png, &info); | 986 png_destroy_write_struct(&png, &info); |
| 1045 fclose(f); | 987 fclose(f); |
| 1046 return true; | 988 return true; |
| 1047 } | 989 } |
| 1048 | 990 |
| 1049 static bool match(const char* needle, const char* haystack) { | 991 static bool match(const char* needle, const char* haystack) { |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 #endif | 1411 #endif |
| 1470 } | 1412 } |
| 1471 } // namespace skiatest | 1413 } // namespace skiatest |
| 1472 | 1414 |
| 1473 #if !defined(SK_BUILD_FOR_IOS) | 1415 #if !defined(SK_BUILD_FOR_IOS) |
| 1474 int main(int argc, char** argv) { | 1416 int main(int argc, char** argv) { |
| 1475 SkCommandLineFlags::Parse(argc, argv); | 1417 SkCommandLineFlags::Parse(argc, argv); |
| 1476 return dm_main(); | 1418 return dm_main(); |
| 1477 } | 1419 } |
| 1478 #endif | 1420 #endif |
| OLD | NEW |