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

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

Issue 1312053004: Require Sk4f::toBytes() clamps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak 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/opts/SkNx_sse.h » ('j') | no next file with comments »
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 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); }
103 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); }
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); } 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); }
105 105
106 void store(T vals[N]) const { 106 void store(T vals[N]) const {
107 fLo.store(vals); 107 fLo.store(vals);
108 fHi.store(vals+N/2); 108 fHi.store(vals+N/2);
109 } 109 }
110 // Please see note on FromBytes(). 110 // Please see note on FromBytes().
111 // Truncates [0.0,256.0) floats to [0,255] bytes. Other inputs are unspecif ied. 111 // Clamps to [0.0,255.0] floats and truncates to [0,255] bytes.
112 void toBytes(uint8_t bytes[N]) const { 112 void toBytes(uint8_t bytes[N]) const {
113 fLo.toBytes(bytes); 113 fLo.toBytes(bytes);
114 fHi.toBytes(bytes+N/2); 114 fHi.toBytes(bytes+N/2);
115 } 115 }
116 116
117 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()); }
118 118
119 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 ); }
120 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 ); }
121 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 ); }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 static int32_t MyNi(float); 209 static int32_t MyNi(float);
210 static int64_t MyNi(double); 210 static int64_t MyNi(double);
211 typedef decltype(MyNi(T())) I; 211 typedef decltype(MyNi(T())) I;
212 public: 212 public:
213 SkNf() {} 213 SkNf() {}
214 explicit SkNf(T val) : fVal(val) {} 214 explicit SkNf(T val) : fVal(val) {}
215 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]); } 216 static SkNf FromBytes(const uint8_t bytes[1]) { return SkNf((T)bytes[0]); }
217 217
218 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); } 219 void toBytes(uint8_t bytes[1]) const { bytes[0] = (uint8_t)(SkTMin(fVal, (T) 255.0)); }
220 220
221 SkNi<1,I> castTrunc() const { return SkNi<1,I>(fVal); } 221 SkNi<1,I> castTrunc() const { return SkNi<1,I>(fVal); }
222 222
223 SkNf operator + (const SkNf& o) const { return SkNf(fVal + o.fVal); } 223 SkNf operator + (const SkNf& o) const { return SkNf(fVal + o.fVal); }
224 SkNf operator - (const SkNf& o) const { return SkNf(fVal - o.fVal); } 224 SkNf operator - (const SkNf& o) const { return SkNf(fVal - o.fVal); }
225 SkNf operator * (const SkNf& o) const { return SkNf(fVal * o.fVal); } 225 SkNf operator * (const SkNf& o) const { return SkNf(fVal * o.fVal); }
226 SkNf operator / (const SkNf& o) const { return SkNf(fVal / o.fVal); } 226 SkNf operator / (const SkNf& o) const { return SkNf(fVal / o.fVal); }
227 227
228 SkNf operator == (const SkNf& o) const { return SkNf(fVal == o.fVal); } 228 SkNf operator == (const SkNf& o) const { return SkNf(fVal == o.fVal); }
229 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
290 typedef SkNi<4, uint16_t> Sk4h; 290 typedef SkNi<4, uint16_t> Sk4h;
291 typedef SkNi<8, uint16_t> Sk8h; 291 typedef SkNi<8, uint16_t> Sk8h;
292 typedef SkNi<16, uint16_t> Sk16h; 292 typedef SkNi<16, uint16_t> Sk16h;
293 293
294 typedef SkNi<16, uint8_t> Sk16b; 294 typedef SkNi<16, uint8_t> Sk16b;
295 295
296 typedef SkNi<4, int32_t> Sk4i; 296 typedef SkNi<4, int32_t> Sk4i;
297 typedef SkNi<4, uint32_t> Sk4u; 297 typedef SkNi<4, uint32_t> Sk4u;
298 298
299 #endif//SkNx_DEFINED 299 #endif//SkNx_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/opts/SkNx_sse.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698