Skip to content

Commit

Permalink
color matrix was wrong. brightness is translation, contrast is scale
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Mar 5, 2014
1 parent 2217c3a commit 53a2f46
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/ColorTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,22 @@ class ColorTransform::Private : public QSharedData
}
void compute() const {
recompute = false;
//http://docs.rainmeter.net/tips/colormatrix-guide
//http://www.graficaobscura.com/matrix/index.html
//http://beesbuzz.biz/code/hsv_color_transforms.php
// ??
float b = (brightness < 0.0f ? brightness : 4.0f * brightness) + 1.0f;
float b = brightness;
// brightness R,G,B
QMatrix4x4 B(b, 0, 0, 0,
0, b, 0, 0,
0, 0, b, 0,
QMatrix4x4 B(1, 0, 0, b,
0, 1, 0, b,
0, 0, 1, b,
0, 0, 0, 1);
// ??
float c = -contrast;
float c = contrast+1.0;
// Contrast (offset) R,G,B
QMatrix4x4 C(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
c, c, c, 1);

QMatrix4x4 C(c, 0, 0, 0,
0, c, 0, 0,
0, 0, c, 0,
0, 0, 0, 1);
// Saturation
const float wr = 0.3086f;
const float wg = 0.6094f;
Expand All @@ -95,7 +96,7 @@ class ColorTransform::Private : public QSharedData
(1.0f - s)*wr + s, (1.0f - s)*wg , (1.0f - s)*wb , 0.0f,
(1.0f - s)*wr , (1.0f - s)*wg + s, (1.0f - s)*wb , 0.0f,
(1.0f - s)*wr , (1.0f - s)*wg , (1.0f - s)*wb + s, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f
0.0f, 0.0f, 0.0f, 1.0f
);
// Hue
const float n = 1.0f / sqrtf(3.0f); // normalized hue rotation axis: sqrt(3)*(1 1 1)
Expand Down

0 comments on commit 53a2f46

Please sign in to comment.