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

Side by Side Diff: src/core/SkColor.cpp

Issue 1666343002: add kRGBA_F16_SkColorType (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add unittest Created 4 years, 10 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 | « include/core/SkPixmap.h ('k') | src/core/SkPixmap.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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 #include "SkColor.h" 8 #include "SkColor.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkFixed.h" 10 #include "SkFixed.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 case 2: r = p; g = v; b = t; break; 96 case 2: r = p; g = v; b = t; break;
97 case 3: r = p; g = q; b = v; break; 97 case 3: r = p; g = q; b = v; break;
98 case 4: r = t; g = p; b = v; break; 98 case 4: r = t; g = p; b = v; break;
99 default: r = v; g = p; b = q; break; 99 default: r = v; g = p; b = q; break;
100 } 100 }
101 return SkColorSetARGB(a, r, g, b); 101 return SkColorSetARGB(a, r, g, b);
102 } 102 }
103 103
104 //////////////////////////////////////////////////////////////////////////////// /////////////////// 104 //////////////////////////////////////////////////////////////////////////////// ///////////////////
105 #include "SkNx.h" 105 #include "SkNx.h"
106 #include "SkHalf.h"
106 107
107 SkPM4f SkPM4f::FromPMColor(SkPMColor c) { 108 SkPM4f SkPM4f::FromPMColor(SkPMColor c) {
108 Sk4f value = SkNx_cast<float>(Sk4b::Load(&c)); 109 Sk4f value = SkNx_cast<float>(Sk4b::Load(&c));
109 SkPM4f c4; 110 SkPM4f c4;
110 (value * Sk4f(1.0f / 255)).store(&c4); 111 (value * Sk4f(1.0f / 255)).store(&c4);
111 return c4; 112 return c4;
112 } 113 }
113 114
114 SkColor4f SkPM4f::unpremul() const { 115 SkColor4f SkPM4f::unpremul() const {
115 float alpha = fVec[A]; 116 float alpha = fVec[A];
116 if (0 == alpha) { 117 if (0 == alpha) {
117 return { 0, 0, 0, 0 }; 118 return { 0, 0, 0, 0 };
118 } else { 119 } else {
119 float invAlpha = 1 / alpha; 120 float invAlpha = 1 / alpha;
120 return { alpha, fVec[R] * invAlpha, fVec[G] * invAlpha, fVec[B] * invAlp ha }; 121 return { alpha, fVec[R] * invAlpha, fVec[G] * invAlpha, fVec[B] * invAlp ha };
121 } 122 }
122 } 123 }
123 124
125 void SkPM4f::toF16(uint16_t half[4]) const {
126 for (int i = 0; i < 4; ++i) {
127 half[i] = SkFloatToHalf(fVec[i]);
128 }
129 }
130
131 uint64_t SkPM4f::toF16() const {
132 uint64_t value;
133 this->toF16(reinterpret_cast<uint16_t*>(&value));
134 return value;
135 }
136
137 SkPM4f SkPM4f::FromF16(const uint16_t half[4]) {
138 return {{
139 SkHalfToFloat(half[0]),
140 SkHalfToFloat(half[1]),
141 SkHalfToFloat(half[2]),
142 SkHalfToFloat(half[3])
143 }};
144 }
145
146 #ifdef SK_DEBUG
147 void SkPM4f::assertIsUnit() const {
148 auto c4 = Sk4f::Load(fVec);
149 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue());
150 }
151 #endif
152
153 //////////////////////////////////////////////////////////////////////////////// ///////////////////
154
124 SkColor4f SkColor4f::FromColor(SkColor c) { 155 SkColor4f SkColor4f::FromColor(SkColor c) {
125 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c))); 156 Sk4f value = SkNx_shuffle<3,2,1,0>(SkNx_cast<float>(Sk4b::Load(&c)));
126 SkColor4f c4; 157 SkColor4f c4;
127 (value * Sk4f(1.0f / 255)).store(&c4); 158 (value * Sk4f(1.0f / 255)).store(&c4);
128 return c4; 159 return c4;
129 } 160 }
130 161
131 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) { 162 SkColor4f SkColor4f::Pin(float a, float r, float g, float b) {
132 SkColor4f c4; 163 SkColor4f c4;
133 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec()); 164 Sk4f::Min(Sk4f::Max(Sk4f(a, r, g, b), Sk4f(0)), Sk4f(1)).store(c4.vec());
(...skipping 10 matching lines...) Expand all
144 Sk4f dst = SkNx_shuffle<3,2,1,0>(src); 175 Sk4f dst = SkNx_shuffle<3,2,1,0>(src);
145 #else 176 #else
146 // ARGB -> RGBA 177 // ARGB -> RGBA
147 Sk4f dst = SkNx_shuffle<1,2,3,0>(src); 178 Sk4f dst = SkNx_shuffle<1,2,3,0>(src);
148 #endif 179 #endif
149 180
150 SkPM4f pm4; 181 SkPM4f pm4;
151 dst.store(&pm4); 182 dst.store(&pm4);
152 return pm4; 183 return pm4;
153 } 184 }
154
155 #ifdef SK_DEBUG
156 void SkPM4f::assertIsUnit() const {
157 auto c4 = Sk4f::Load(fVec);
158 SkASSERT((c4 >= Sk4f(0)).allTrue() && (c4 <= Sk4f(1)).allTrue());
159 }
160 #endif
OLDNEW
« no previous file with comments | « include/core/SkPixmap.h ('k') | src/core/SkPixmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698