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

Side by Side Diff: src/opts/SkPMFloat_none.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 | « src/opts/SkPMFloat_neon.h ('k') | tests/PMFloatTest.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 #include "SkColorPriv.h" 1 #include "SkColorPriv.h"
2 2
3 inline void SkPMFloat::set(SkPMColor c) { 3 inline void SkPMFloat::set(SkPMColor c) {
4 this->setA(SkGetPackedA32(c)); 4 this->setA(SkGetPackedA32(c));
5 this->setR(SkGetPackedR32(c)); 5 this->setR(SkGetPackedR32(c));
6 this->setG(SkGetPackedG32(c)); 6 this->setG(SkGetPackedG32(c));
7 this->setB(SkGetPackedB32(c)); 7 this->setB(SkGetPackedB32(c));
8 SkASSERT(this->isValid()); 8 SkASSERT(this->isValid());
9 } 9 }
10 10
11 inline SkPMColor SkPMFloat::get() const { 11 inline SkPMColor SkPMFloat::get() const {
12 SkASSERT(this->isValid()); 12 SkASSERT(this->isValid());
13 return SkPackARGB32(this->a(), this->r(), this->g(), this->b()); 13 return SkPackARGB32(this->a()+0.5f, this->r()+0.5f, this->g()+0.5f, this->b( )+0.5f);
14 } 14 }
15 15
16 inline SkPMColor SkPMFloat::clamped() const { 16 inline SkPMColor SkPMFloat::clamped() const {
17 float a = this->a(), 17 float a = this->a(),
18 r = this->r(), 18 r = this->r(),
19 g = this->g(), 19 g = this->g(),
20 b = this->b(); 20 b = this->b();
21 a = a < 0 ? 0 : (a > 255 ? 255 : a); 21 a = a < 0 ? 0 : (a > 255 ? 255 : a);
22 r = r < 0 ? 0 : (r > 255 ? 255 : r); 22 r = r < 0 ? 0 : (r > 255 ? 255 : r);
23 g = g < 0 ? 0 : (g > 255 ? 255 : g); 23 g = g < 0 ? 0 : (g > 255 ? 255 : g);
24 b = b < 0 ? 0 : (b > 255 ? 255 : b); 24 b = b < 0 ? 0 : (b > 255 ? 255 : b);
25 return SkPackARGB32(a, r, g, b); 25 return SkPackARGB32(a+0.5f, r+0.5f, g+0.5f, b+0.5f);
26 } 26 }
OLDNEW
« no previous file with comments | « src/opts/SkPMFloat_neon.h ('k') | tests/PMFloatTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698