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

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

Issue 1319413003: Move float<->byte conversions into Sk4f. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: ranges Created 5 years, 3 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
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | src/opts/SkColorCubeFilter_opts.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef SkNx_DEFINED 8 #ifndef SkNx_DEFINED
9 #define SkNx_DEFINED 9 #define SkNx_DEFINED
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 class SkNf { 85 class SkNf {
86 static int32_t MyNi(float); 86 static int32_t MyNi(float);
87 static int64_t MyNi(double); 87 static int64_t MyNi(double);
88 typedef decltype(MyNi(T())) I; 88 typedef decltype(MyNi(T())) I;
89 public: 89 public:
90 SkNf() {} 90 SkNf() {}
91 explicit SkNf(T val) : fLo(val), fHi(val) {} 91 explicit SkNf(T val) : fLo(val), fHi(val) {}
92 static SkNf Load(const T vals[N]) { 92 static SkNf Load(const T vals[N]) {
93 return SkNf(SkNf<N/2,T>::Load(vals), SkNf<N/2,T>::Load(vals+N/2)); 93 return SkNf(SkNf<N/2,T>::Load(vals), SkNf<N/2,T>::Load(vals+N/2));
94 } 94 }
95 // FromBytes() and toBytes() specializations may assume their argument is N- byte aligned.
96 // E.g. Sk4f::FromBytes() may assume it's reading from a 4-byte-aligned poin ter.
97 // Converts [0,255] bytes to [0.0, 255.0] floats.
98 static SkNf FromBytes(const uint8_t bytes[N]) {
99 return SkNf(SkNf<N/2,T>::FromBytes(bytes), SkNf<N/2,T>::FromBytes(bytes+ N/2));
100 }
95 101
96 SkNf(T a, T b) : fLo(a), fHi(b) { REQUIRE(N==2); } 102 SkNf(T a, T b) : fLo(a), fHi(b) { REQUIRE(N==2); }
97 SkNf(T a, T b, T c, T d) : fLo(a,b), fHi(c,d) { REQUIRE(N==4); } 103 SkNf(T a, T b, T c, T d) : fLo(a,b), fHi(c,d) { REQUIRE(N==4); }
98 SkNf(T a, T b, T c, T d, T e, T f, T g, T h) : fLo(a,b,c,d), fHi(e,f,g,h) { REQUIRE(N==8); } 104 SkNf(T a, T b, T c, T d, T e, T f, T g, T h) : fLo(a,b,c,d), fHi(e,f,g,h) { REQUIRE(N==8); }
99 105
100 void store(T vals[N]) const { 106 void store(T vals[N]) const {
101 fLo.store(vals); 107 fLo.store(vals);
102 fHi.store(vals+N/2); 108 fHi.store(vals+N/2);
103 } 109 }
110 // Please see note on FromBytes().
111 // Truncates [0.0,256.0) floats to [0,255] bytes. Other inputs are unspecif ied.
112 void toBytes(uint8_t bytes[N]) const {
113 fLo.toBytes(bytes);
114 fHi.toBytes(bytes+N/2);
115 }
104 116
105 SkNi<N,I> castTrunc() const { return SkNi<N,I>(fLo.castTrunc(), fHi.castTrun c()); } 117 SkNi<N,I> castTrunc() const { return SkNi<N,I>(fLo.castTrunc(), fHi.castTrun c()); }
106 118
107 SkNf operator + (const SkNf& o) const { return SkNf(fLo + o.fLo, fHi + o.fHi ); } 119 SkNf operator + (const SkNf& o) const { return SkNf(fLo + o.fLo, fHi + o.fHi ); }
108 SkNf operator - (const SkNf& o) const { return SkNf(fLo - o.fLo, fHi - o.fHi ); } 120 SkNf operator - (const SkNf& o) const { return SkNf(fLo - o.fLo, fHi - o.fHi ); }
109 SkNf operator * (const SkNf& o) const { return SkNf(fLo * o.fLo, fHi * o.fHi ); } 121 SkNf operator * (const SkNf& o) const { return SkNf(fLo * o.fLo, fHi * o.fHi ); }
110 SkNf operator / (const SkNf& o) const { return SkNf(fLo / o.fLo, fHi / o.fHi ); } 122 SkNf operator / (const SkNf& o) const { return SkNf(fLo / o.fLo, fHi / o.fHi ); }
111 123
112 SkNf operator == (const SkNf& o) const { return SkNf(fLo == o.fLo, fHi == o. fHi); } 124 SkNf operator == (const SkNf& o) const { return SkNf(fLo == o.fLo, fHi == o. fHi); }
113 SkNf operator != (const SkNf& o) const { return SkNf(fLo != o.fLo, fHi != o. fHi); } 125 SkNf operator != (const SkNf& o) const { return SkNf(fLo != o.fLo, fHi != o. fHi); }
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 206
195 template <typename T> 207 template <typename T>
196 class SkNf<1,T> { 208 class SkNf<1,T> {
197 static int32_t MyNi(float); 209 static int32_t MyNi(float);
198 static int64_t MyNi(double); 210 static int64_t MyNi(double);
199 typedef decltype(MyNi(T())) I; 211 typedef decltype(MyNi(T())) I;
200 public: 212 public:
201 SkNf() {} 213 SkNf() {}
202 explicit SkNf(T val) : fVal(val) {} 214 explicit SkNf(T val) : fVal(val) {}
203 static SkNf Load(const T vals[1]) { return SkNf(vals[0]); } 215 static SkNf Load(const T vals[1]) { return SkNf(vals[0]); }
216 static SkNf FromBytes(const uint8_t bytes[1]) { return SkNf((T)bytes[0]); }
204 217
205 void store(T vals[1]) const { vals[0] = fVal; } 218 void store(T vals[1]) const { vals[0] = fVal; }
219 void toBytes(uint8_t bytes[1]) const { bytes[0] = (uint8_t)(fVal); }
206 220
207 SkNi<1,I> castTrunc() const { return SkNi<1,I>(fVal); } 221 SkNi<1,I> castTrunc() const { return SkNi<1,I>(fVal); }
208 222
209 SkNf operator + (const SkNf& o) const { return SkNf(fVal + o.fVal); } 223 SkNf operator + (const SkNf& o) const { return SkNf(fVal + o.fVal); }
210 SkNf operator - (const SkNf& o) const { return SkNf(fVal - o.fVal); } 224 SkNf operator - (const SkNf& o) const { return SkNf(fVal - o.fVal); }
211 SkNf operator * (const SkNf& o) const { return SkNf(fVal * o.fVal); } 225 SkNf operator * (const SkNf& o) const { return SkNf(fVal * o.fVal); }
212 SkNf operator / (const SkNf& o) const { return SkNf(fVal / o.fVal); } 226 SkNf operator / (const SkNf& o) const { return SkNf(fVal / o.fVal); }
213 227
214 SkNf operator == (const SkNf& o) const { return SkNf(fVal == o.fVal); } 228 SkNf operator == (const SkNf& o) const { return SkNf(fVal == o.fVal); }
215 SkNf operator != (const SkNf& o) const { return SkNf(fVal != o.fVal); } 229 SkNf operator != (const SkNf& o) const { return SkNf(fVal != o.fVal); }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 typedef SkNi<4, uint16_t> Sk4h; 290 typedef SkNi<4, uint16_t> Sk4h;
277 typedef SkNi<8, uint16_t> Sk8h; 291 typedef SkNi<8, uint16_t> Sk8h;
278 typedef SkNi<16, uint16_t> Sk16h; 292 typedef SkNi<16, uint16_t> Sk16h;
279 293
280 typedef SkNi<16, uint8_t> Sk16b; 294 typedef SkNi<16, uint8_t> Sk16b;
281 295
282 typedef SkNi<4, int32_t> Sk4i; 296 typedef SkNi<4, int32_t> Sk4i;
283 typedef SkNi<4, uint32_t> Sk4u; 297 typedef SkNi<4, uint32_t> Sk4u;
284 298
285 #endif//SkNx_DEFINED 299 #endif//SkNx_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | src/opts/SkColorCubeFilter_opts.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698