xref: /aosp_15_r20/external/pdfium/core/fxge/dib/cfx_cmyk_to_srgb_unittest.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2019 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "core/fxge/dib/cfx_cmyk_to_srgb.h"
6 
7 #include "testing/gtest/include/gtest/gtest.h"
8 
9 union Float_t {
Float_t(float num=0.0f)10   Float_t(float num = 0.0f) : f(num) {}
11 
12   int32_t i;
13   float f;
14 };
15 
TEST(fxge,CMYK_Rounding)16 TEST(fxge, CMYK_Rounding) {
17   // Testing all floats from 0.0 to 1.0 takes about 35 seconds in release
18   // builds and much longer in debug builds, so just test the known-dangerous
19   // range.
20   constexpr float kStartValue = 0.001f;
21   constexpr float kEndValue = 0.003f;
22   float R = 0.0f;
23   float G = 0.0f;
24   float B = 0.0f;
25   // Iterate through floats by incrementing the representation, as discussed in
26   // https://randomascii.wordpress.com/2012/01/23/stupid-float-tricks-2/
27   for (Float_t f = kStartValue; f.f < kEndValue; f.i++) {
28     std::tie(R, G, B) = AdobeCMYK_to_sRGB(f.f, f.f, f.f, f.f);
29   }
30   // Check various other 'special' numbers.
31   std::tie(R, G, B) = AdobeCMYK_to_sRGB(0.0f, 0.25f, 0.5f, 1.0f);
32 }
33