• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkSRGB.h"
9 #include "SkTypes.h"
10 #include "Test.h"
11 #include <math.h>
12 
linear_to_srgb(float l)13 static uint8_t linear_to_srgb(float l) {
14     return (uint8_t)sk_linear_to_srgb(Sk4f{l})[0];
15 }
16 
DEF_TEST(sk_linear_to_srgb,r)17 DEF_TEST(sk_linear_to_srgb, r) {
18     // All bytes should round trip.
19     for (int i = 0; i < 256; i++) {
20         int actual = linear_to_srgb(sk_linear_from_srgb[i]);
21         if (i != actual) {
22             ERRORF(r, "%d -> %d\n", i, actual);
23         }
24     }
25 
26     // Should be monotonic between 0 and 1.
27     uint8_t prev = 0;
28     for (float f = FLT_MIN; f <= 1.0f; ) {  // We don't bother checking denorm values.
29         uint8_t srgb = linear_to_srgb(f);
30 
31         REPORTER_ASSERT(r, srgb >= prev);
32         prev = srgb;
33 
34         union { float flt; uint32_t bits; } pun = { f };
35         pun.bits++;
36         SkDEBUGCODE(pun.bits += 127);
37         f = pun.flt;
38     }
39 }
40