OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The LibYuv Project Authors. All rights reserved. | 2 * Copyright 2015 The LibYuv Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 | 216 |
217 /* YUV converted to ARGB. */ | 217 /* YUV converted to ARGB. */ |
218 J400ToARGB(orig_y, kWidth, orig_pixels, kWidth * 4, kWidth, kHeight); | 218 J400ToARGB(orig_y, kWidth, orig_pixels, kWidth * 4, kWidth, kHeight); |
219 | 219 |
220 *b = orig_pixels[0]; | 220 *b = orig_pixels[0]; |
221 *g = orig_pixels[1]; | 221 *g = orig_pixels[1]; |
222 *r = orig_pixels[2]; | 222 *r = orig_pixels[2]; |
223 } | 223 } |
224 | 224 |
225 // Pick a method for clamping. | 225 // Pick a method for clamping. |
226 #define CLAMPMETHOD_IF 1 | 226 // #define CLAMPMETHOD_IF 1 |
227 // #define CLAMPMETHOD_TABLE 1 | 227 // #define CLAMPMETHOD_TABLE 1 |
228 // #define CLAMPMETHOD_TERNARY 1 | 228 #define CLAMPMETHOD_TERNARY 1 |
229 // #define CLAMPMETHOD_MASK 1 | 229 // #define CLAMPMETHOD_MASK 1 |
230 | 230 |
231 // Pick a method for rounding. | 231 // Pick a method for rounding. |
232 #define ROUND(f) static_cast<int>(f + 0.5) | 232 #define ROUND(f) static_cast<int>(f + 0.5f) |
233 // #define ROUND(f) lrintf(f) | 233 // #define ROUND(f) lrintf(f) |
234 // #define ROUND(f) static_cast<int>(round(f)) | 234 // #define ROUND(f) static_cast<int>(round(f)) |
235 // #define ROUND(f) _mm_cvt_ss2si(_mm_load_ss(&f)) | 235 // #define ROUND(f) _mm_cvt_ss2si(_mm_load_ss(&f)) |
236 | 236 |
237 #if defined(CLAMPMETHOD_IF) | 237 #if defined(CLAMPMETHOD_IF) |
238 static int RoundToByte(float f) { | 238 static int RoundToByte(float f) { |
239 int i = ROUND(f); | 239 int i = ROUND(f); |
240 if (i < 0) { | 240 if (i < 0) { |
241 i = 0; | 241 i = 0; |
242 } | 242 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 int i = ROUND(f); | 307 int i = ROUND(f); |
308 i = ((-(i) >> 31) & (i)); // clamp to 0. | 308 i = ((-(i) >> 31) & (i)); // clamp to 0. |
309 return (((255 - (i)) >> 31) | (i)) & 255; // clamp to 255. | 309 return (((255 - (i)) >> 31) | (i)) & 255; // clamp to 255. |
310 } | 310 } |
311 #endif | 311 #endif |
312 | 312 |
313 #define RANDOM256(s) ((s & 1) ? ((s >> 1) ^ 0xb8) : (s >> 1)) | 313 #define RANDOM256(s) ((s & 1) ? ((s >> 1) ^ 0xb8) : (s >> 1)) |
314 | 314 |
315 TEST_F(libyuvTest, TestRoundToByte) { | 315 TEST_F(libyuvTest, TestRoundToByte) { |
316 int allb = 0; | 316 int allb = 0; |
| 317 int count = benchmark_width_ * benchmark_height_; |
317 for (int i = 0; i < benchmark_iterations_; ++i) { | 318 for (int i = 0; i < benchmark_iterations_; ++i) { |
318 for (int u2 = 0; u2 < 256; ++u2) { | 319 float f = (fastrand() & 255) * 3.14f - 260.f; |
319 for (int v2 = 0; v2 < 256; ++v2) { | 320 for (int j = 0; j < count; ++j) { |
320 for (int y2 = 0; y2 < 256; ++y2) { | 321 int b = RoundToByte(f); |
321 int y = RANDOM256(y2); | 322 f += 0.91f; |
322 int b = RoundToByte(y * 810.33 - 257); | 323 allb |= b; |
323 allb |= b; | |
324 } | |
325 } | |
326 } | 324 } |
327 } | 325 } |
328 EXPECT_GE(allb, 0); | 326 EXPECT_GE(allb, 0); |
329 EXPECT_LE(allb, 255); | 327 EXPECT_LE(allb, 255); |
330 } | 328 } |
331 | 329 |
332 static void YUVToRGBReference(int y, int u, int v, int* r, int* g, int* b) { | 330 static void YUVToRGBReference(int y, int u, int v, int* r, int* g, int* b) { |
333 *r = RoundToByte((y - 16) * 1.164 - (v - 128) * -1.596); | 331 *r = RoundToByte((y - 16) * 1.164 - (v - 128) * -1.596); |
334 *g = RoundToByte((y - 16) * 1.164 - (u - 128) * 0.391 - (v - 128) * 0.813); | 332 *g = RoundToByte((y - 16) * 1.164 - (u - 128) * 0.391 - (v - 128) * 0.813); |
335 *b = RoundToByte((y - 16) * 1.164 - (u - 128) * -2.018); | 333 *b = RoundToByte((y - 16) * 1.164 - (u - 128) * -2.018); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 EXPECT_EQ(r0, r1); | 549 EXPECT_EQ(r0, r1); |
552 EXPECT_EQ(g0, g1); | 550 EXPECT_EQ(g0, g1); |
553 EXPECT_EQ(b0, b1); | 551 EXPECT_EQ(b0, b1); |
554 EXPECT_EQ(r0, r2); | 552 EXPECT_EQ(r0, r2); |
555 EXPECT_EQ(g0, g2); | 553 EXPECT_EQ(g0, g2); |
556 EXPECT_EQ(b0, b2); | 554 EXPECT_EQ(b0, b2); |
557 } | 555 } |
558 } | 556 } |
559 | 557 |
560 } // namespace libyuv | 558 } // namespace libyuv |
OLD | NEW |