diff --git a/src/doc/CMakeLists.txt b/src/doc/CMakeLists.txt index d1c5973d1..2b2f5492a 100644 --- a/src/doc/CMakeLists.txt +++ b/src/doc/CMakeLists.txt @@ -1,4 +1,5 @@ # Aseprite Document Library +# Copyright (C) 2020 Igara Studio S.A. # Copyright (C) 2001-2018 David Capello if(WIN32) @@ -28,6 +29,7 @@ add_library(doc-lib cel_data_io.cpp cel_io.cpp cels_range.cpp + color.cpp compressed_image.cpp conversion_to_surface.cpp document.cpp diff --git a/src/doc/color.cpp b/src/doc/color.cpp new file mode 100644 index 000000000..470d71b90 --- /dev/null +++ b/src/doc/color.cpp @@ -0,0 +1,46 @@ +// Aseprite Document Library +// Copyright (c) 2020 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 "doc/color.h" + +#include + +namespace doc { + +color_t rgba_to_graya_using_hsv(const color_t c) +{ + const uint8_t M = std::max(rgba_getr(c), + std::max(rgba_getg(c), + rgba_getb(c))); + return graya(M, + rgba_geta(c)); +} + +color_t rgba_to_graya_using_hsl(const color_t c) +{ + const int m = std::min(rgba_getr(c), + std::min(rgba_getg(c), + rgba_getb(c))); + const int M = std::max(rgba_getr(c), + std::max(rgba_getg(c), + rgba_getb(c))); + return graya((M + m) / 2, + rgba_geta(c)); +} + +color_t rgba_to_graya_using_luma(const color_t c) +{ + return graya(rgb_luma(rgba_getr(c), + rgba_getg(c), + rgba_getb(c)), + rgba_geta(c)); +} + +} // namespace doc diff --git a/src/doc/color.h b/src/doc/color.h index 20b04608d..ac65b0034 100644 --- a/src/doc/color.h +++ b/src/doc/color.h @@ -11,8 +11,6 @@ #include "base/ints.h" -#include - namespace doc { // The greatest int type to storage a color for an image in the @@ -95,31 +93,9 @@ namespace doc { typedef color_t (*rgba_to_graya_func)(const color_t c); - inline color_t rgba_to_graya_using_hsv(const color_t c) { - const uint8_t M = std::max(rgba_getr(c), - std::max(rgba_getg(c), - rgba_getb(c))); - return graya(M, - rgba_geta(c)); - } - - inline color_t rgba_to_graya_using_hsl(const color_t c) { - const int m = std::min(rgba_getr(c), - std::min(rgba_getg(c), - rgba_getb(c))); - const int M = std::max(rgba_getr(c), - std::max(rgba_getg(c), - rgba_getb(c))); - return graya((M + m) / 2, - rgba_geta(c)); - } - - inline color_t rgba_to_graya_using_luma(const color_t c) { - return graya(rgb_luma(rgba_getr(c), - rgba_getg(c), - rgba_getb(c)), - rgba_geta(c)); - } + color_t rgba_to_graya_using_hsv(const color_t c); + color_t rgba_to_graya_using_hsl(const color_t c); + color_t rgba_to_graya_using_luma(const color_t c); } // namespace doc