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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkPMFloat.h » ('j') | src/opts/SkColorCubeFilter_opts.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkNx.h
diff --git a/src/core/SkNx.h b/src/core/SkNx.h
index 84f9b693537bdae6a56d4cb09757da8942400353..895b972dd1b3f88bef79c4494ac9068376ce8498 100644
--- a/src/core/SkNx.h
+++ b/src/core/SkNx.h
@@ -92,6 +92,12 @@ public:
static SkNf Load(const T vals[N]) {
return SkNf(SkNf<N/2,T>::Load(vals), SkNf<N/2,T>::Load(vals+N/2));
}
+ // FromBytes() and toBytes() specializations may assume their argument is N-byte aligned.
+ // E.g. Sk4f::FromBytes() may assume it's reading from a 4-byte-aligned pointer.
+ // Converts [0,255] bytes to [0.0, 255.0] floats.
+ static SkNf FromBytes(const uint8_t bytes[N]) {
+ return SkNf(SkNf<N/2,T>::FromBytes(bytes), SkNf<N/2,T>::FromBytes(bytes+N/2));
+ }
SkNf(T a, T b) : fLo(a), fHi(b) { REQUIRE(N==2); }
SkNf(T a, T b, T c, T d) : fLo(a,b), fHi(c,d) { REQUIRE(N==4); }
@@ -101,6 +107,12 @@ public:
fLo.store(vals);
fHi.store(vals+N/2);
}
+ // Please see note on FromBytes().
+ // Truncates [0.0,256.0) floats to [0,255] bytes. Other inputs are unspecified.
+ void toBytes(uint8_t bytes[N]) const {
+ fLo.toBytes(bytes);
+ fHi.toBytes(bytes+N/2);
+ }
SkNi<N,I> castTrunc() const { return SkNi<N,I>(fLo.castTrunc(), fHi.castTrunc()); }
@@ -201,8 +213,10 @@ public:
SkNf() {}
explicit SkNf(T val) : fVal(val) {}
static SkNf Load(const T vals[1]) { return SkNf(vals[0]); }
+ static SkNf FromBytes(const uint8_t bytes[1]) { return SkNf((T)bytes[0]); }
void store(T vals[1]) const { vals[0] = fVal; }
+ void toBytes(uint8_t bytes[1]) const { bytes[0] = (uint8_t)(fVal); }
SkNi<1,I> castTrunc() const { return SkNi<1,I>(fVal); }
« 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