| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 <string> | 8 #include <string> |
| 9 #include <tuple> | 9 #include <tuple> |
| 10 #include <vector> | 10 #include <vector> |
| 11 #include "Resources.h" | 11 #include "Resources.h" |
| 12 #include "SkCpu.h" | 12 #include "SkCpu.h" |
| 13 #include "SkImage.h" | 13 #include "SkImage.h" |
| 14 #include "SkImage_Base.h" | 14 #include "SkImage_Base.h" |
| 15 #include "SkOpts.h" | 15 #include "SkOpts.h" |
| 16 #include "SkPM4fPriv.h" | 16 #include "SkPM4fPriv.h" |
| 17 #include "SkNx.h" | 17 #include "SkNx.h" |
| 18 #include "Test.h" | 18 #include "Test.h" |
| 19 | 19 |
| 20 typedef void (*Blender)(uint32_t* dst, const uint32_t* const srcStart, int ndst,
const int nsrc); | 20 typedef void (*Blender)(uint32_t* dst, const uint32_t* const srcStart, int ndst,
const int nsrc); |
| 21 | 21 |
| 22 static inline void srcover_srgb_srgb_1(uint32_t* dst, uint32_t src) { |
| 23 auto d = Sk4f_fromS32(*dst), |
| 24 s = Sk4f_fromS32( src); |
| 25 *dst = Sk4f_toS32(s + d * (1.0f - s[3])); |
| 26 } |
| 27 |
| 22 static void brute_force_srcover_srgb_srgb( | 28 static void brute_force_srcover_srgb_srgb( |
| 23 uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) { | 29 uint32_t* dst, const uint32_t* const src, int ndst, const int nsrc) { |
| 24 while (ndst > 0) { | 30 while (ndst > 0) { |
| 25 int n = SkTMin(ndst, nsrc); | 31 int n = SkTMin(ndst, nsrc); |
| 26 | 32 |
| 27 for (int i = 0; i < n; i++) { | 33 for (int i = 0; i < n; i++) { |
| 28 srcover_blend_srgb8888_srgb_1(dst++, srgb_to_linear(to_4f(src[i]))); | 34 srcover_srgb_srgb_1(dst++, src[i]); |
| 29 } | 35 } |
| 30 ndst -= n; | 36 ndst -= n; |
| 31 } | 37 } |
| 32 } | 38 } |
| 33 | 39 |
| 34 static SkString mismatch_message(std::string resourceName, int x, int y, | 40 static SkString mismatch_message(std::string resourceName, int x, int y, |
| 35 uint32_t src, uint32_t good, uint32_t bad) { | 41 uint32_t src, uint32_t good, uint32_t bad) { |
| 36 return SkStringPrintf( | 42 return SkStringPrintf( |
| 37 "%s - missmatch at %d, %d src: %08x good: %08x bad: %08x", | 43 "%s - missmatch at %d, %d src: %08x good: %08x bad: %08x", |
| 38 resourceName.c_str(), x, y, src, good, bad); | 44 resourceName.c_str(), x, y, src, good, bad); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co
lorType()); | 62 SkASSERTF(pixmap.colorType() == kN32_SkColorType, "colorType: %d", pixmap.co
lorType()); |
| 57 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType); | 63 SkASSERT(pixmap.alphaType() != kUnpremul_SkAlphaType); |
| 58 const uint32_t* src = pixmap.addr32(); | 64 const uint32_t* src = pixmap.addr32(); |
| 59 const int width = pixmap.rowBytesAsPixels(); | 65 const int width = pixmap.rowBytesAsPixels(); |
| 60 SkASSERT(width > 0); | 66 SkASSERT(width > 0); |
| 61 SkASSERT(width < 4000); | 67 SkASSERT(width < 4000); |
| 62 SkAutoTArray<uint32_t> correctDst(width); | 68 SkAutoTArray<uint32_t> correctDst(width); |
| 63 SkAutoTArray<uint32_t> testDst(width); | 69 SkAutoTArray<uint32_t> testDst(width); |
| 64 | 70 |
| 65 for (int y = 0; y < pixmap.height(); y++) { | 71 for (int y = 0; y < pixmap.height(); y++) { |
| 72 // TODO: zero is not the most interesting dst to test srcover... |
| 66 sk_bzero(correctDst.get(), width * sizeof(uint32_t)); | 73 sk_bzero(correctDst.get(), width * sizeof(uint32_t)); |
| 67 sk_bzero(testDst.get(), width * sizeof(uint32_t)); | 74 sk_bzero(testDst.get(), width * sizeof(uint32_t)); |
| 68 brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width); | 75 brute_force_srcover_srgb_srgb(correctDst.get(), src, width, width); |
| 69 SkOpts:: srcover_srgb_srgb( testDst.get(), src, width, width); | 76 SkOpts:: srcover_srgb_srgb( testDst.get(), src, width, width); |
| 70 for (int x = 0; x < width; x++) { | 77 for (int x = 0; x < width; x++) { |
| 71 REPORTER_ASSERT_MESSAGE( | 78 REPORTER_ASSERT_MESSAGE( |
| 72 reporter, correctDst[x] == testDst[x], | 79 reporter, correctDst[x] == testDst[x], |
| 73 mismatch_message(resourceName, x, y, src[x], correctDst[x], test
Dst[x])); | 80 mismatch_message(resourceName, x, y, src[x], correctDst[x], test
Dst[x])); |
| 74 if (correctDst[x] != testDst[x]) break; | 81 if (correctDst[x] != testDst[x]) break; |
| 75 } | 82 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 DEF_TEST(SkBlend_optsSqrtCheck, reporter) { | 97 DEF_TEST(SkBlend_optsSqrtCheck, reporter) { |
| 91 for (int c = 0; c < 256; c++) { | 98 for (int c = 0; c < 256; c++) { |
| 92 Sk4f i{(float)c}; | 99 Sk4f i{(float)c}; |
| 93 Sk4f ii = i * i; | 100 Sk4f ii = i * i; |
| 94 Sk4f s = ii.sqrt() + 0.5f; | 101 Sk4f s = ii.sqrt() + 0.5f; |
| 95 Sk4f sf = s.floor(); | 102 Sk4f sf = s.floor(); |
| 96 REPORTER_ASSERT_MESSAGE( | 103 REPORTER_ASSERT_MESSAGE( |
| 97 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0])
); | 104 reporter, i[0] == sf[0], SkStringPrintf("i: %f, s: %f", i[0], sf[0])
); |
| 98 } | 105 } |
| 99 } | 106 } |
| OLD | NEW |