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

Side by Side Diff: tests/SkNxTest.cpp

Issue 1312053004: Require Sk4f::toBytes() clamps (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak 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
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | no next file » | 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 #include "Sk4px.h" 8 #include "Sk4px.h"
9 #include "SkNx.h" 9 #include "SkNx.h"
10 #include "SkRandom.h" 10 #include "SkRandom.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 SkPreMultiplyColor(0x00000000), 201 SkPreMultiplyColor(0x00000000),
202 }; 202 };
203 auto packed = Sk4px::Load4(colors); 203 auto packed = Sk4px::Load4(colors);
204 204
205 auto wideLo = packed.widenLo(), 205 auto wideLo = packed.widenLo(),
206 wideHi = packed.widenHi(), 206 wideHi = packed.widenHi(),
207 wideLoHi = packed.widenLoHi(), 207 wideLoHi = packed.widenLoHi(),
208 wideLoHiAlt = wideLo + wideHi; 208 wideLoHiAlt = wideLo + wideHi;
209 REPORTER_ASSERT(r, 0 == memcmp(&wideLoHi, &wideLoHiAlt, sizeof(wideLoHi))); 209 REPORTER_ASSERT(r, 0 == memcmp(&wideLoHi, &wideLoHiAlt, sizeof(wideLoHi)));
210 } 210 }
211
212 DEF_TEST(Sk4f_toBytes, r) {
213 uint8_t bytes[4];
214
215 // toBytes truncates, not rounds.
216 Sk4f(0.7f).toBytes(bytes);
217 REPORTER_ASSERT(r, bytes[0] == 0);
218
219 // Clamping edge cases.
220 Sk4f(-2.0f, -0.7f, 255.9f, 256.0f).toBytes(bytes);
221 REPORTER_ASSERT(r, bytes[0] == 0);
222 REPORTER_ASSERT(r, bytes[1] == 0);
223 REPORTER_ASSERT(r, bytes[2] == 255);
224 REPORTER_ASSERT(r, bytes[3] == 255);
225 }
OLDNEW
« no previous file with comments | « src/opts/SkNx_sse.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698