Skip to content

Commit

Permalink
Made member functions constant and replaced double comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
hechth committed Dec 29, 2020
1 parent 8cdcedc commit 3b6be67
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions ImageProcessing/src/BlueFramework/ImageProcessing/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include <cstddef>
#include <iostream>

#include <BlueFramework/Core/Math/util.h>

#include "BlueFramework/ImageProcessing/namespace.h"

BLUEFRAMEWORK_IMAGEPROCESSING_NAMESPACE_BEGIN
Expand Down Expand Up @@ -282,7 +284,7 @@ class Color<T, 3> {
const double max = std::max({red(), green(), blue()}) / 255.0;
const double min = std::min({red(), green(), blue()}) / 255.0;

if (max == 0) {
if (buw::doubleEqual(max, 0.0)) {
return 0;
}
return (max - min) / max;
Expand Down Expand Up @@ -313,7 +315,7 @@ class Color<T, 3> {
}

// get the X-Value of XYZ from sRGB value
double getXYZ_X() {
double getXYZ_X() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -325,7 +327,7 @@ class Color<T, 3> {
}

// get the Y-Value of XYZ from sRGB value
double getXYZ_Y() {
double getXYZ_Y() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -337,7 +339,7 @@ class Color<T, 3> {
}

// get the Z-Value of XYZ from sRGB value
double getXYZ_Z() {
double getXYZ_Z() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -359,13 +361,13 @@ class Color<T, 3> {
}

// get the L-value of L*ab from sRGB value
double getLAB_L() {
double getLAB_L() const {
const double Y = getXYZ_Y();
return 116 * LAB_helperFunction(Y) - 16;
}

// get the a-value of L*ab from sRGB value
double getLAB_a(double x, double y) {
double getLAB_a(double x, double y) const {
const double Yn = 1;
const double Xn = x * (Yn / y);
const double X = getXYZ_X();
Expand All @@ -374,7 +376,7 @@ class Color<T, 3> {
}

// get the b-value of L*ab from sRGB value
double getLAB_b(double x, double y) {
double getLAB_b(double x, double y) const {
const double Yn = 1;
const double Zn = (1 - x - y) * (Yn / y);
const double Z = getXYZ_Z();
Expand Down Expand Up @@ -477,7 +479,7 @@ class Color<T, 4> {
return -1.0;
}

double getHue() {
double getHue() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -488,7 +490,7 @@ class Color<T, 4> {
const double max = std::max(std::max(r, g), b);
const double min = std::min(std::min(r, g), b);

if (max == min) {
if (buw::doubleEqual(max,min)) {
return 0;
} else if (max == r) {
return 60 * ((g - b) / (max - min));
Expand All @@ -499,7 +501,7 @@ class Color<T, 4> {
}
}

double getSaturation() {
double getSaturation() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -510,14 +512,14 @@ class Color<T, 4> {
const double max = std::max(std::max(r, g), b);
const double min = std::min(std::min(r, g), b);

if (max == 0) {
if (buw::doubleEqual(max, 0.0)) {
return 0;
} else {
return (max - min) / max;
}
}

double getBrightness() {
double getBrightness() const {
return std::max({red(), green(), blue()}) / 255;
}

Expand All @@ -542,7 +544,7 @@ class Color<T, 4> {
}

// get the X-Value of XYZ from sRGB value
double getXYZ_X() {
double getXYZ_X() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -554,7 +556,7 @@ class Color<T, 4> {
}

// get the Y-Value of XYZ from sRGB value
double getXYZ_Y() {
double getXYZ_Y() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -566,7 +568,7 @@ class Color<T, 4> {
}

// get the Z-Value of XYZ from sRGB value
double getXYZ_Z() {
double getXYZ_Z() const {
const int red = (*this)[0];
const int green = (*this)[1];
const int blue = (*this)[2];
Expand All @@ -588,13 +590,13 @@ class Color<T, 4> {
}

// get the L-value of L*ab from sRGB value
double getLAB_L() {
double getLAB_L() const {
const double Y = getXYZ_Y();
return 116 * LAB_helperFunction(Y) - 16;
}

// get the a-value of L*ab from sRGB value
double getLAB_a(double x, double y) {
double getLAB_a(const double x, const double y) const {
const double Yn = 1;
const double Xn = x * (Yn / y);
const double X = getXYZ_X();
Expand All @@ -603,7 +605,7 @@ class Color<T, 4> {
}

// get the b-value of L*ab from sRGB value
double getLAB_b(double x, double y) {
double getLAB_b(double x, double y) const {
const double Yn = 1;
const double Zn = (1 - x - y) * (Yn / y);
const double Z = getXYZ_Z();
Expand Down

0 comments on commit 3b6be67

Please sign in to comment.