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

Side by Side Diff: src/core/SkPMFloat.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
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 SkPM_DEFINED 8 #ifndef SkPM_DEFINED
9 #define SkPM_DEFINED 9 #define SkPM_DEFINED
10 10
(...skipping 10 matching lines...) Expand all
21 namespace { 21 namespace {
22 22
23 // A pre-multiplied color storing each component in the same order as SkPMColor, 23 // A pre-multiplied color storing each component in the same order as SkPMColor,
24 // but as a float in the range [0, 1]. 24 // but as a float in the range [0, 1].
25 class SkPMFloat : public Sk4f { 25 class SkPMFloat : public Sk4f {
26 public: 26 public:
27 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); } 27 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); }
28 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF loat(a,r,g,b); } 28 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF loat(a,r,g,b); }
29 static SkPMFloat FromOpaqueColor(SkColor c); // Requires c's alpha == 0xFF. 29 static SkPMFloat FromOpaqueColor(SkColor c); // Requires c's alpha == 0xFF.
30 30
31 Sk4f alphas() const; // argb -> aaaa, generally faster than the equivalent Sk4f(this->a()). 31 Sk4f alphas() const { return Sk4f(this->a()); }
32 32
33 // Uninitialized. 33 // Uninitialized.
34 SkPMFloat() {} 34 SkPMFloat() {}
35 explicit SkPMFloat(SkPMColor); 35 explicit SkPMFloat(SkPMColor c) { *this = Sk4f::FromBytes((uint8_t*)&c) * Sk 4f(1.0f/255); }
36 SkPMFloat(float a, float r, float g, float b) 36 SkPMFloat(float a, float r, float g, float b)
37 #ifdef SK_PMCOLOR_IS_RGBA 37 #ifdef SK_PMCOLOR_IS_RGBA
38 : INHERITED(r,g,b,a) {} 38 : INHERITED(r,g,b,a) {}
39 #else 39 #else
40 : INHERITED(b,g,r,a) {} 40 : INHERITED(b,g,r,a) {}
41 #endif 41 #endif
42 42
43 SkPMFloat(const Sk4f& fs) : INHERITED(fs) {} 43 SkPMFloat(const Sk4f& fs) : INHERITED(fs) {}
44 44
45 float a() const { return this->kth<SK_A32_SHIFT / 8>(); } 45 float a() const { return this->kth<SK_A32_SHIFT / 8>(); }
46 float r() const { return this->kth<SK_R32_SHIFT / 8>(); } 46 float r() const { return this->kth<SK_R32_SHIFT / 8>(); }
47 float g() const { return this->kth<SK_G32_SHIFT / 8>(); } 47 float g() const { return this->kth<SK_G32_SHIFT / 8>(); }
48 float b() const { return this->kth<SK_B32_SHIFT / 8>(); } 48 float b() const { return this->kth<SK_B32_SHIFT / 8>(); }
49 49
50 SkPMColor round() const; // Rounds from [0.0f, 1.0f] to [0, 255], clamping if out of range. 50 SkPMColor round() const {
51 SkPMColor c;
52 (*this * Sk4f(255) + Sk4f(0.5f)).toBytes((uint8_t*)&c);
53 return c;
54 }
51 55
52 bool isValid() const { 56 bool isValid() const {
53 return this->a() >= 0 && this->a() <= 1 57 return this->a() >= 0 && this->a() <= 1
54 && this->r() >= 0 && this->r() <= this->a() 58 && this->r() >= 0 && this->r() <= this->a()
55 && this->g() >= 0 && this->g() <= this->a() 59 && this->g() >= 0 && this->g() <= this->a()
56 && this->b() >= 0 && this->b() <= this->a(); 60 && this->b() >= 0 && this->b() <= this->a();
57 } 61 }
58 62
59 private: 63 private:
60 typedef Sk4f INHERITED; 64 typedef Sk4f INHERITED;
61 }; 65 };
62 66
63 } // namespace 67 } // namespace
64 68
65 #ifdef SKNX_NO_SIMD
66 // Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _non e is generic.
67 #include "../opts/SkPMFloat_none.h"
68 #else
69 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
70 #include "../opts/SkPMFloat_sse.h"
71 #elif defined(SK_ARM_HAS_NEON)
72 #include "../opts/SkPMFloat_neon.h"
73 #else
74 #include "../opts/SkPMFloat_none.h"
75 #endif
76 #endif
77
78 #endif//SkPM_DEFINED 69 #endif//SkPM_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698