colorspace_oklab.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SuperTux
  2. // Copyright (C) 2015 Ingo Ruhnke <grumbel@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include "util/colorspace_oklab.hpp"
  17. #include <gtest/gtest.h>
  18. #include "video/color.hpp"
  19. TEST(ColorOKLCh, ctor)
  20. {
  21. ColorOKLCh color(.3f, .4f, .5f);
  22. // Can't use strict equality because of imprecision
  23. // 1 / 256 = 0.00390625, so 0.001 should make no difference.
  24. EXPECT_NEAR(color.L, .3f, 0.001f);
  25. EXPECT_NEAR(color.C, .4f, 0.001f);
  26. EXPECT_NEAR(color.h, .5f, 0.001f);
  27. }
  28. TEST(ColorOKLCh, ctor_Color)
  29. {
  30. Color col(.3f, .4f, .5f);
  31. ColorOKLCh color(col);
  32. EXPECT_NEAR(color.L, .50023675f, 0.001f);
  33. EXPECT_NEAR(color.C, .050982524f, 0.001f);
  34. EXPECT_NEAR(color.h, -1.9393998f, 0.001f);
  35. }
  36. TEST(ColorOKLCh, to_srgb)
  37. {
  38. Color col(.1f, 1.f, 0.f);
  39. ColorOKLCh color(col);
  40. col = color.to_srgb();
  41. EXPECT_NEAR(col.red, .1f, 0.001f);
  42. EXPECT_NEAR(col.green, 1.f, 0.001f);
  43. EXPECT_NEAR(col.blue, 0.f, 0.001f);
  44. }
  45. TEST(ColorOKLCh, get_maximum_chroma)
  46. {
  47. ColorOKLCh color(.6f, 1.f, .3f);
  48. float chroma = color.get_maximum_chroma();
  49. EXPECT_NEAR(chroma, .24032472f, 0.001f);
  50. }
  51. TEST(ColorOKLCh, get_maximum_chroma_any_l)
  52. {
  53. ColorOKLCh color(0.f, .1f, .05f);
  54. float chroma = color.get_maximum_chroma_any_l();
  55. EXPECT_NEAR(chroma, .26009744f, 0.001f);
  56. }
  57. TEST(ColorOKLCh, clip_chroma)
  58. {
  59. ColorOKLCh color(.45f, .67f, .12f);
  60. color.clip_chroma();
  61. EXPECT_NEAR(color.L, .45f, 0.001f);
  62. EXPECT_NEAR(color.C, .1804768f, 0.001f);
  63. EXPECT_NEAR(color.h, .12f, 0.001f);
  64. }
  65. TEST(ColorOKLCh, clip_lightness)
  66. {
  67. ColorOKLCh color(.45f, .67f, .12f);
  68. color.clip_lightness();
  69. EXPECT_NEAR(color.L, .64147455f, 0.001f);
  70. EXPECT_NEAR(color.C, .2572695f, 0.001f);
  71. EXPECT_NEAR(color.h, .12f, 0.001f);
  72. }
  73. TEST(ColorOKLCh, clip_adaptive_L0_L_cusp)
  74. {
  75. ColorOKLCh color(1.f, 1.f, 1.f);
  76. color.clip_adaptive_L0_L_cusp(0.25f);
  77. EXPECT_NEAR(color.L, .83574224f, 0.001f);
  78. EXPECT_NEAR(color.C, .10836758f, 0.001f);
  79. EXPECT_NEAR(color.h, 1.f, 0.001f);
  80. }
  81. /* EOF */