2 * Copyright 2016 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkRasterPipeline.h"
14 static uint8_t linear_to_srgb(float l) {
15 return (uint8_t)sk_linear_to_srgb(Sk4f{l})[0];
18 DEF_TEST(sk_linear_to_srgb, r) {
19 // All bytes should round trip.
20 for (int i = 0; i < 256; i++) {
21 int actual = linear_to_srgb(sk_linear_from_srgb[i]);
23 ERRORF(r, "%d -> %d\n", i, actual);
27 // Should be monotonic between 0 and 1.
29 for (float f = FLT_MIN; f <= 1.0f; ) { // We don't bother checking denorm values.
30 uint8_t srgb = linear_to_srgb(f);
32 REPORTER_ASSERT(r, srgb >= prev);
35 union { float flt; uint32_t bits; } pun = { f };
37 SkDEBUGCODE(pun.bits += 127);
42 DEF_TEST(sk_pipeline_srgb_roundtrip, r) {
44 for (int i = 0; i < 256; i++) {
48 auto ptr = (void*)reds;
50 SkRasterPipeline_<256> p;
51 p.append(SkRasterPipeline::load_8888, &ptr);
52 p.append_from_srgb(kUnpremul_SkAlphaType);
53 p.append(SkRasterPipeline::to_srgb);
54 p.append(SkRasterPipeline::store_8888, &ptr);
58 for (int i = 0; i < 256; i++) {
59 if (reds[i] != (uint32_t)i) {
60 ERRORF(r, "%d doesn't round trip, %d", i, reds[i]);