forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_scales_tests.cpp
47 lines (36 loc) · 1.06 KB
/
color_scales_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Aseprite Document Library
// Copyright (c) 2022 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gtest/gtest.h>
#include "doc/color_scales.h"
#include <cmath>
#include <cstdlib>
using namespace doc;
TEST(ColorScales, MatchValues)
{
for (int v = 0; v < 8; ++v)
EXPECT_EQ(scale_3bits_to_8bits(v), scale_xbits_to_8bits(3, v));
for (int v = 0; v < 32; ++v)
EXPECT_EQ(scale_5bits_to_8bits(v), scale_xbits_to_8bits(5, v));
for (int v = 0; v < 64; ++v)
EXPECT_EQ(scale_6bits_to_8bits(v), scale_xbits_to_8bits(6, v));
for (int x = 1; x <= 8; ++x) {
for (int v = 0; v < (1 << x); ++v)
EXPECT_LE(std::abs((255 * v / ((1 << x) - 1)) - scale_xbits_to_8bits(x, v)), 1);
}
}
TEST(ColorScales, TenBits)
{
EXPECT_EQ(0xff, scale_xbits_to_8bits(10, 0x3ff));
EXPECT_EQ(0x7f, scale_xbits_to_8bits(10, 0x1ff));
}
int main(int argc, char** argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}