blob: 66b0ea60abbe5bdab5682d9029c29ab5ead881f5 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright 2005, 2006 by Gerald Friedland, Kristian Jantz and Lars Knipping
* Conversion to C++ for Inkscape by Bob Jamison
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef INKSCAPE_TRACE_CIELAB_H
#define INKSCAPE_TRACE_CIELAB_H
#include <cstdint>
namespace Inkscape {
namespace Trace {
class CieLab
{
public:
CieLab()
{
C = 0;
L = A = B = 0.0f;
}
/**
* Construct this CieLab from an ARGB value
*/
CieLab(uint32_t rgb);
CieLab(float l, float a, float b)
{
C = 0;
L = l;
A = a;
B = b;
}
CieLab(CieLab const &other)
{
C = other.C;
L = other.L;
A = other.A;
B = other.B;
}
CieLab &operator=(CieLab const &other)
{
C = other.C;
L = other.L;
A = other.A;
B = other.B;
return *this;
}
/**
* Retrieve a CieLab value via index.
*/
float operator()(unsigned index) const
{
switch (index) {
case 0: return L;
case 1: return A;
case 2: return B;
default: return 0;
}
}
void add(CieLab const &other)
{
C += other.C;
L += other.L;
A += other.A;
B += other.B;
}
void mul(float scale)
{
L *= scale;
A *= scale;
B *= scale;
}
/**
* Return this CieLab's value converted to an ARGB value
*/
uint32_t toRGB() const;
/**
* Squared Euclidean distance between two colors in CieLab space.
*/
static float diffSq(CieLab const &c1, CieLab const &c2);
/**
* Computes euclidean distance in CieLab space between two colors.
*/
static float diff(CieLab const &c1, CieLab const &c2);
unsigned C;
float L;
float A;
float B;
};
} // namespace Trace
} // namespace Inkscape
#endif // INKSCAPE_TRACE_CIELAB_H
|