summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4601eac)
raw | patch | inline | side by side (parent: 4601eac)
author | njh <njh@users.sourceforge.net> | |
Fri, 14 Jul 2006 08:26:21 +0000 (08:26 +0000) | ||
committer | njh <njh@users.sourceforge.net> | |
Fri, 14 Jul 2006 08:26:21 +0000 (08:26 +0000) |
o simplified some of the maths
o fixed a bug in the matrix normalisation routine (dubious that it ever
actually worked)
o fixed a bug in the matrix normalisation routine (dubious that it ever
actually worked)
src/trace/siox.cpp | patch | blob | history |
diff --git a/src/trace/siox.cpp b/src/trace/siox.cpp
index 9c5db4731eef30b81b1a2e73d42b045b29f2583c..ff894a48c542cbddd383cc7a6c379cbf5a627f08 100644 (file)
--- a/src/trace/siox.cpp
+++ b/src/trace/siox.cpp
#include <math.h>
#include <stdarg.h>
#include <map>
+#include <algorithm>
namespace org
//# C L A B
//########################################################################
-static std::map<unsigned long, CieLab> clabLookupTable;
-
/**
* Convert integer A, R, G, B values into an pixel value.
*/
{
init();
- //First try looking up in the cache
- std::map<unsigned long, CieLab>::iterator iter;
- iter = clabLookupTable.find(rgb);
- if (iter != clabLookupTable.end())
- {
- CieLab res = iter->second;
- C = res.C;
- L = res.L;
- A = res.A;
- B = res.B;
- }
-
-
int ir = (rgb>>16) & 0xff;
int ig = (rgb>> 8) & 0xff;
int ib = (rgb ) & 0xff;
else
fb = fb / 12.92;
- fr = fr * 100.0;
- fg = fg * 100.0;
- fb = fb * 100.0;
-
// Use white = D65
- float x = fr * 0.4124 + fg * 0.3576 + fb * 0.1805;
- float y = fr * 0.2126 + fg * 0.7152 + fb * 0.0722;
- float z = fr * 0.0193 + fg * 0.1192 + fb * 0.9505;
+ const float x = fr * 0.4124 + fg * 0.3576 + fb * 0.1805;
+ const float y = fr * 0.2126 + fg * 0.7152 + fb * 0.0722;
+ const float z = fr * 0.0193 + fg * 0.1192 + fb * 0.9505;
- float vx = x / 95.047;
- float vy = y / 100.000;
- float vz = z / 108.883;
+ float vx = x / 0.95047;
+ float vy = y;
+ float vz = z / 1.08883;
//printf("vx:%f vy:%f vz:%f\n", vx, vy, vz);
if (vx > 0.008856)
L = 116.0 * vy - 16.0;
A = 500.0 * (vx - vy);
B = 200.0 * (vy - vz);
-
- // Cache for next time
- clabLookupTable[rgb] = *this;
-
}
/**
- * Return this CieLab's value a a packed-pixel ARGB value
+ * Return this CieLab's value converted to a packed-pixel ARGB value
*/
unsigned long CieLab::toRGB()
{
else
vz = (vz - 16.0 / 116.0) / 7.787;
- float x = 95.047 * vx; //use white = D65
- float y = 100.000 * vy;
- float z = 108.883 * vz;
-
- vx = x / 100.0;
- vy = y / 100.0;
- vz = z / 100.0;
+ vx *= 0.95047; //use white = D65
+ vz *= 1.08883;
float vr =(float)(vx * 3.2406 + vy * -1.5372 + vz * -0.4986);
float vg =(float)(vx * -0.9689 + vy * 1.8758 + vz * 0.0415);
-
/**
* Normalizes the matrix to values to [0..1].
*/
void Siox::normalizeMatrix(float *cm, int cmSize)
{
- float max= -1000000.0f;
- for (int i=0; i<cmSize; i++)
- if (max<cm[i] > max)
- max=cm[i];
+ float max = *std::max(cm, cm + cmSize);
if (max<=0.0 || max==1.0)
return;