Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: src/core/SkPM4fPriv.h

Issue 1642703003: starter procs for blending with pm4f (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: int to float Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkColorPriv.h"
9 #include "SkNx.h"
10
11 static inline float get_alpha(const Sk4f& f4) {
12 return f4.kth<SkPM4f::A>();
13 }
14
15 static inline Sk4f set_alpha(const Sk4f& f4, float alpha) {
16 static_assert(3 == SkPM4f::A, "");
17 return Sk4f(f4.kth<0>(), f4.kth<1>(), f4.kth<2>(), alpha);
18 }
19
20 static inline uint32_t to_4b(const Sk4f& f4) {
21 uint32_t b4;
22 SkNx_cast<uint8_t>(f4).store((uint8_t*)&b4);
23 return b4;
24 }
25
26 static inline Sk4f to_4f(uint32_t b4) {
27 return SkNx_cast<float>(Sk4b::Load((const uint8_t*)&b4));
28 }
29
30 static inline Sk4f s2l(const Sk4f& s4) {
mtklein 2016/01/29 15:23:00 Had to think about what these were for a second.
reed1 2016/01/29 22:35:27 Done.
31 return set_alpha(s4 * s4, get_alpha(s4));
32 }
33
34 static inline Sk4f l2s(const Sk4f& l4) {
35 return set_alpha(l4.rsqrt1() * l4, get_alpha(l4));
36 }
37
38 //////////////////////////////////////////////////////////////////////////////// ///////////////////
39
40 static inline Sk4f Sk4f_fromL32(uint32_t src) {
41 return to_4f(src) * Sk4f(1.0f/255);
42 }
43
44 static inline Sk4f Sk4f_fromS32(uint32_t src) {
45 return s2l(to_4f(src) * Sk4f(1.0f/255));
46 }
47
48 static inline uint32_t Sk4f_toL32(const Sk4f& x4) {
49 return to_4b(x4 * Sk4f(255) + Sk4f(0.5f));
50 }
51
52 static inline uint32_t Sk4f_toS32(const Sk4f& x4) {
53 return to_4b(l2s(x4) * Sk4f(255) + Sk4f(0.5f));
54 }
55
56 //////////////////////////////////////////////////////////////////////////////// ///////////////////
57
58 static Sk4f unit_to_l255_round(const SkPM4f& pm4) {
mtklein 2016/01/29 15:23:00 I think this might be clearer if we start first wi
reed1 2016/01/29 22:35:27 Agree, this is definitely a worktable of experimen
59 return Sk4f::Load(pm4.fVec) * Sk4f(255) + Sk4f(0.5f);
60 }
61
62 static Sk4f unit_to_s255_round(const SkPM4f& pm4) {
63 return l2s(Sk4f::Load(pm4.fVec)) * Sk4f(255) + Sk4f(0.5f);
64 }
65
66 static inline void SkPM4f_l32_src_mode(SkPMColor dst[], const SkPM4f src[], int count) {
67 for (int i = 0; i < (count >> 2); ++i) {
mtklein 2016/01/29 15:23:00 This looks right to me, but in my experience I've
68 SkASSERT(src[0].isUnit());
69 SkASSERT(src[1].isUnit());
70 SkASSERT(src[2].isUnit());
71 SkASSERT(src[3].isUnit());
72 Sk4f_ToBytes((uint8_t*)dst,
73 unit_to_l255_round(src[0]), unit_to_l255_round(src[1]),
74 unit_to_l255_round(src[2]), unit_to_l255_round(src[3]));
75 src += 4;
76 dst += 4;
77 }
78 count &= 3;
79 for (int i = 0; i < count; ++i) {
80 SkASSERT(src[i].isUnit());
81 SkNx_cast<uint8_t>(unit_to_l255_round(src[i])).store((uint8_t*)&dst[i]);
82 }
83 }
84
85 static inline void SkPM4f_l32_srcover_mode(SkPMColor dst[], const SkPM4f src[], int count) {
86 for (int i = 0; i < count; ++i) {
87 SkASSERT(src[i].isUnit());
88 Sk4f s4 = Sk4f::Load(src[i].fVec);
89 Sk4f d4 = Sk4f_fromL32(dst[i]);
90 dst[i] = Sk4f_toL32(s4 + d4 * Sk4f(1 - get_alpha(s4)));
91 }
92 }
93
94 static inline void SkPM4f_s32_src_mode(SkPMColor dst[], const SkPM4f src[], int count) {
mtklein 2016/01/29 15:23:00 I think we're going to have to come up with a new
reed1 2016/01/29 22:35:27 Done.
95 for (int i = 0; i < (count >> 2); ++i) {
96 SkASSERT(src[0].isUnit());
97 SkASSERT(src[1].isUnit());
98 SkASSERT(src[2].isUnit());
99 SkASSERT(src[3].isUnit());
100 Sk4f_ToBytes((uint8_t*)dst,
101 unit_to_s255_round(src[0]), unit_to_s255_round(src[1]),
102 unit_to_s255_round(src[2]), unit_to_s255_round(src[3]));
103 src += 4;
104 dst += 4;
105 }
106 count &= 3;
107 for (int i = 0; i < count; ++i) {
108 SkASSERT(src[i].isUnit());
109 SkNx_cast<uint8_t>(unit_to_s255_round(src[i])).store((uint8_t*)&dst[i]);
110 }
111 }
112
113 static inline void SkPM4f_s32_srcover_mode(SkPMColor dst[], const SkPM4f src[], int count) {
114 for (int i = 0; i < count; ++i) {
115 SkASSERT(src[i].isUnit());
116 Sk4f s4 = Sk4f::Load(src[i].fVec);
117 Sk4f d4 = Sk4f_fromS32(dst[i]);
118 dst[i] = Sk4f_toS32(s4 + d4 * Sk4f(1 - get_alpha(s4)));
119 }
120 }
121
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698