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

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

Issue 974643002: Test and fix SkPMFloat rounding. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: f Created 5 years, 9 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/SkPMFloat_SSE2.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 #ifndef SkPM_DEFINED 1 #ifndef SkPM_DEFINED
2 #define SkPM_DEFINED 2 #define SkPM_DEFINED
3 3
4 #include "SkTypes.h" 4 #include "SkTypes.h"
5 #include "SkColor.h" 5 #include "SkColor.h"
6 #include "Sk4x.h" 6 #include "Sk4x.h"
7 7
8 // A pre-multiplied color storing each component as a float in the range [0, 255 ]. 8 // A pre-multiplied color storing each component as a float in the range [0, 255 ].
9 class SK_STRUCT_ALIGN(16) SkPMFloat { 9 class SK_STRUCT_ALIGN(16) SkPMFloat {
10 public: 10 public:
(...skipping 11 matching lines...) Expand all
22 float g() const { return fColor[SK_G32_SHIFT / 8]; } 22 float g() const { return fColor[SK_G32_SHIFT / 8]; }
23 float b() const { return fColor[SK_B32_SHIFT / 8]; } 23 float b() const { return fColor[SK_B32_SHIFT / 8]; }
24 24
25 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; } 25 void setA(float val) { fColor[SK_A32_SHIFT / 8] = val; }
26 void setR(float val) { fColor[SK_R32_SHIFT / 8] = val; } 26 void setR(float val) { fColor[SK_R32_SHIFT / 8] = val; }
27 void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; } 27 void setG(float val) { fColor[SK_G32_SHIFT / 8] = val; }
28 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; } 28 void setB(float val) { fColor[SK_B32_SHIFT / 8] = val; }
29 29
30 void set(SkPMColor); 30 void set(SkPMColor);
31 31
32 // get() and clamped() round component values to the nearest integer.
32 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen tations may clamp. 33 SkPMColor get() const; // May SkASSERT(this->isValid()). Some implemen tations may clamp.
33 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may assert isValid(). 34 SkPMColor clamped() const; // Will clamp all values to [0, 255]. Then may assert isValid().
34 35
35 bool isValid() const { 36 bool isValid() const {
36 return this->a() >= 0 && this->a() <= 255 37 return this->a() >= 0 && this->a() <= 255
37 && this->r() >= 0 && this->r() <= this->a() 38 && this->r() >= 0 && this->r() <= this->a()
38 && this->g() >= 0 && this->g() <= this->a() 39 && this->g() >= 0 && this->g() <= this->a()
39 && this->b() >= 0 && this->b() <= this->a(); 40 && this->b() >= 0 && this->b() <= this->a();
40 } 41 }
41 42
42 private: 43 private:
43 // We mirror SkPMColor order only to make set()/get()/clamped() as fast as p ossible. 44 // We mirror SkPMColor order only to make set()/get()/clamped() as fast as p ossible.
44 float fColor[4]; 45 float fColor[4];
45 }; 46 };
46 47
47 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 48 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
48 #include "../opts/SkPMFloat_SSE2.h" 49 #include "../opts/SkPMFloat_SSE2.h"
49 #elif defined(__ARM_NEON__) 50 #elif defined(__ARM_NEON__)
50 #include "../opts/SkPMFloat_neon.h" 51 #include "../opts/SkPMFloat_neon.h"
51 #else 52 #else
52 #include "../opts/SkPMFloat_none.h" 53 #include "../opts/SkPMFloat_none.h"
53 #endif 54 #endif
54 55
55 #endif//SkPM_DEFINED 56 #endif//SkPM_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/opts/SkPMFloat_SSE2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698