Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cmake stuff, and a cheap difference #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: macOS

on: [push]
on: [push, pull_request]

jobs:
build-test:
Expand All @@ -18,4 +18,4 @@ jobs:
- name: make
run: make
- name: ctest
run: ctest
run: ctest --output-on-failure
4 changes: 2 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Ubuntu

on: [push]
on: [push, pull_request]

jobs:
build-test:
Expand All @@ -22,4 +22,4 @@ jobs:
- name: make
run: make
- name: ctest
run: ctest
run: ctest --output-on-failure
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ cmake_minimum_required(VERSION 3.1)
project(color-util CXX)
set(CMAKE_CXX_STANDARD 11)

find_package(Eigen3 REQUIRED)
find_package(Eigen3)
if((NOT TARGET Eigen3::Eigen) AND (DEFINED EIGEN3_INCLUDE_DIR))
add_library(AliasEigen3 INTERFACE)
target_include_directories(AliasEigen3 INTERFACE ${EIGEN3_INCLUDE_DIR})
add_library(Eigen3::Eigen ALIAS AliasEigen3)
else()
message(FATAL_ERROR "Cannot find Eigen3 and EIGEN3_INCLUDE_DIR is undefined")
endif()

file(GLOB HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/color-util/*.hpp)
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ A header-only C++11 library for handling colors, including color space converter

## Color Difference Calculators

### Redmean

Given two sRGB colors, `calculate_redmean` calculates a difference between these two colors based on an [informal metric](https://www.compuphase.com/cmetric.htm). The function is defined in `color-util/redmean.hpp`.

This simple metric is more perceptually uniform than an Euclidean distance in sRGB space, but is otherwise a bad choice.

### CIE76

Given two CIELAB colors, `calculate_CIE76` calculates a *perceptual* difference between these two colors based on a metric called CIE76. This function is defined in `color-util/CIE76.hpp`.
Expand Down
24 changes: 24 additions & 0 deletions include/color-util/redmean.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// \file redmean.hpp

#ifndef COLORUTIL_REDMEAN_HPP
#define COLORUTIL_REDMEAN_HPP

#include <cmath>
#include <color-util/type.hpp>

namespace colorutil
{
/// \brief Calculate a cheap color difference based on redmean.
/// \param color_1 The first color. This should be expressed in sRGB color space.
/// \param color_2 The second color. This should be expressed in sRGB color space.
/// \return The color difference of the two colors.
inline double calculate_redmean(const RGB& color_1, const RGB& color_1)
{
double redmean = (color_1(0) + color_2(0)) * 0.5;
Eigen::Vector3d diff = color_1 - color_2;
diff = diff.cwiseProduct(Eigen::Map<const Eigen::Vector3d>(diff));
return sqrt((2 + redmean) * diff(0) + 4 * diff(1) + (2 - redmean) * diff(2));
}
} // namespace colorutil

#endif // COLORUTIL_REDMEAN_HPP