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

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

Issue 1056143004: Revert of Code's more readable when SkPMFloat is an Sk4f. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 5 years, 8 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/SkXfermode.cpp » ('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 SkPM_DEFINED 8 #ifndef SkPM_DEFINED
9 #define SkPM_DEFINED 9 #define SkPM_DEFINED
10 10
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 #include "SkColor.h" 12 #include "SkColor.h"
13 #include "SkColorPriv.h" 13 #include "SkColorPriv.h"
14 #include "SkNx.h" 14 #include "SkNx.h"
15 15
16 // A pre-multiplied color storing each component in the same order as SkPMColor, 16 // A pre-multiplied color storing each component in the same order as SkPMColor,
17 // but as a float in the range [0, 255]. 17 // but as a float in the range [0, 255].
18 class SkPMFloat : public Sk4f { 18 class SK_STRUCT_ALIGN(16) SkPMFloat {
19 public: 19 public:
20 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); } 20 static SkPMFloat FromPMColor(SkPMColor c) { return SkPMFloat(c); }
21 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF loat(a,r,g,b); } 21 static SkPMFloat FromARGB(float a, float r, float g, float b) { return SkPMF loat(a,r,g,b); }
22 22
23 // May be more efficient than one at a time. No special alignment assumed f or SkPMColors. 23 // May be more efficient than one at a time. No special alignment assumed f or SkPMColors.
24 static void From4PMColors(const SkPMColor[4], SkPMFloat*, SkPMFloat*, SkPMFl oat*, SkPMFloat*); 24 static void From4PMColors(const SkPMColor[4], SkPMFloat*, SkPMFloat*, SkPMFl oat*, SkPMFloat*);
25 25
26 // Uninitialized. 26 // Uninitialized.
27 SkPMFloat() {} 27 SkPMFloat() {}
28 explicit SkPMFloat(SkPMColor); 28 explicit SkPMFloat(SkPMColor);
29 SkPMFloat(float a, float r, float g, float b) 29 SkPMFloat(float a, float r, float g, float b)
30 #ifdef SK_PMCOLOR_IS_RGBA 30 #ifdef SK_PMCOLOR_IS_RGBA
31 : INHERITED(r,g,b,a) {} 31 : fColors(r,g,b,a) {}
32 #else 32 #else
33 : INHERITED(b,g,r,a) {} 33 : fColors(b,g,r,a) {}
34 #endif 34 #endif
35 35
36 SkPMFloat(const Sk4f& fs) : INHERITED(fs) {}
37 36
38 float a() const { return this->kth<SK_A32_SHIFT / 8>(); } 37 // Freely autoconvert between SkPMFloat and Sk4f.
39 float r() const { return this->kth<SK_R32_SHIFT / 8>(); } 38 /*implicit*/ SkPMFloat(const Sk4f& fs) { fColors = fs; }
40 float g() const { return this->kth<SK_G32_SHIFT / 8>(); } 39 /*implicit*/ operator Sk4f() const { return fColors; }
41 float b() const { return this->kth<SK_B32_SHIFT / 8>(); } 40
41 float a() const { return fColors.kth<SK_A32_SHIFT / 8>(); }
42 float r() const { return fColors.kth<SK_R32_SHIFT / 8>(); }
43 float g() const { return fColors.kth<SK_G32_SHIFT / 8>(); }
44 float b() const { return fColors.kth<SK_B32_SHIFT / 8>(); }
42 45
43 // N.B. All methods returning an SkPMColor call SkPMColorAssert on that resu lt before returning. 46 // N.B. All methods returning an SkPMColor call SkPMColorAssert on that resu lt before returning.
44 47
45 // round() and roundClamp() round component values to the nearest integer. 48 // round() and roundClamp() round component values to the nearest integer.
46 SkPMColor round() const; // Assumes all values in [0, 255]. Some implement ations may clamp. 49 SkPMColor round() const; // Assumes all values in [0, 255]. Some implement ations may clamp.
47 SkPMColor roundClamp() const; // Will clamp all values to [0, 255]. 50 SkPMColor roundClamp() const; // Will clamp all values to [0, 255].
48 51
49 // Like round(), but truncates instead of rounding. 52 // Like round(), but truncates instead of rounding.
50 // The domain of this function is (-1.0f, 256.0f). Values in (-1.0f, 0.0f] trunc to a zero. 53 // The domain of this function is (-1.0f, 256.0f). Values in (-1.0f, 0.0f] trunc to a zero.
51 SkPMColor trunc() const; 54 SkPMColor trunc() const;
52 55
53 // 4-at-a-time versions of round() and roundClamp(). Like From4PMColors(), n o alignment assumed. 56 // 4-at-a-time versions of round() and roundClamp(). Like From4PMColors(), n o alignment assumed.
54 static void RoundTo4PMColors( 57 static void RoundTo4PMColors(
55 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa t&, SkPMColor[4]); 58 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa t&, SkPMColor[4]);
56 static void RoundClampTo4PMColors( 59 static void RoundClampTo4PMColors(
57 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa t&, SkPMColor[4]); 60 const SkPMFloat&, const SkPMFloat&, const SkPMFloat&, const SkPMFloa t&, SkPMColor[4]);
58 61
59 bool isValid() const { 62 bool isValid() const {
60 return this->a() >= 0 && this->a() <= 255 63 return this->a() >= 0 && this->a() <= 255
61 && this->r() >= 0 && this->r() <= this->a() 64 && this->r() >= 0 && this->r() <= this->a()
62 && this->g() >= 0 && this->g() <= this->a() 65 && this->g() >= 0 && this->g() <= this->a()
63 && this->b() >= 0 && this->b() <= this->a(); 66 && this->b() >= 0 && this->b() <= this->a();
64 } 67 }
65 68
66 private: 69 private:
67 typedef Sk4f INHERITED; 70 Sk4f fColors;
68 }; 71 };
69 72
70 #ifdef SKNX_NO_SIMD 73 #ifdef SKNX_NO_SIMD
71 // Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _non e is generic. 74 // Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _non e is generic.
72 #include "../opts/SkPMFloat_none.h" 75 #include "../opts/SkPMFloat_none.h"
73 #else 76 #else
74 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 77 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
75 #include "../opts/SkPMFloat_SSSE3.h" 78 #include "../opts/SkPMFloat_SSSE3.h"
76 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 79 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
77 #include "../opts/SkPMFloat_SSE2.h" 80 #include "../opts/SkPMFloat_SSE2.h"
78 #elif defined(SK_ARM_HAS_NEON) 81 #elif defined(SK_ARM_HAS_NEON)
79 #include "../opts/SkPMFloat_neon.h" 82 #include "../opts/SkPMFloat_neon.h"
80 #else 83 #else
81 #include "../opts/SkPMFloat_none.h" 84 #include "../opts/SkPMFloat_none.h"
82 #endif 85 #endif
83 #endif 86 #endif
84 87
85 #endif//SkPM_DEFINED 88 #endif//SkPM_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698