Flat curve editor widget, HSV tool modified to use it.
Usage : - click & drag a control point to move it in X&Y direction - click & drag a vertical line to move it in horizontal or vertical direction (the very first move will be used to determine the motion direction) - click & drag the yellow or blue square handle to modify the tangent of the same color
This commit is contained in:
@@ -17,9 +17,16 @@
|
||||
* along with RawTherapee. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <utils.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef MAX
|
||||
#undef MIN
|
||||
|
||||
#define MAX(a,b) ((a)<(b)?(b):(a))
|
||||
#define MIN(a,b) ((a)>(b)?(b):(a))
|
||||
|
||||
namespace rtengine {
|
||||
|
||||
void bilinearInterp (const unsigned char* src, int sw, int sh, unsigned char* dst, int dw, int dh) {
|
||||
@@ -139,6 +146,77 @@ void vflip (unsigned char* img, int w, int h) {
|
||||
delete [] flipped;
|
||||
}
|
||||
|
||||
void rgb2hsv (int r, int g, int b, float &h, float &s, float &v) {
|
||||
|
||||
double var_R = r / 65535.0;
|
||||
double var_G = g / 65535.0;
|
||||
double var_B = b / 65535.0;
|
||||
|
||||
double var_Min = MIN(MIN(var_R,var_G),var_B);
|
||||
double var_Max = MAX(MAX(var_R,var_G),var_B);
|
||||
double del_Max = var_Max - var_Min;
|
||||
v = var_Max;
|
||||
if (fabs(del_Max)<0.00001) {
|
||||
h = 0;
|
||||
s = 0;
|
||||
}
|
||||
else {
|
||||
s = del_Max/var_Max;
|
||||
|
||||
if ( var_R == var_Max ) h = (var_G - var_B)/del_Max;
|
||||
else if ( var_G == var_Max ) h = 2.0 + (var_B - var_R)/del_Max;
|
||||
else if ( var_B == var_Max ) h = 4.0 + (var_R - var_G)/del_Max;
|
||||
h /= 6.0;
|
||||
|
||||
if ( h < 0 ) h += 1;
|
||||
if ( h > 1 ) h -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void hsv2rgb (float h, float s, float v, int &r, int &g, int &b) {
|
||||
|
||||
float h1 = h*6; // sector 0 to 5
|
||||
int i = floor( h1 );
|
||||
float f = h1 - i; // fractional part of h
|
||||
|
||||
float p = v * ( 1 - s );
|
||||
float q = v * ( 1 - s * f );
|
||||
float t = v * ( 1 - s * ( 1 - f ) );
|
||||
|
||||
float r1,g1,b1;
|
||||
|
||||
if (i==0) {r1 = v; g1 = t; b1 = p;}
|
||||
if (i==1) {r1 = q; g1 = v; b1 = p;}
|
||||
if (i==2) {r1 = p; g1 = v; b1 = t;}
|
||||
if (i==3) {r1 = p; g1 = q; b1 = v;}
|
||||
if (i==4) {r1 = t; g1 = p; b1 = v;}
|
||||
if (i==5) {r1 = v; g1 = p; b1 = q;}
|
||||
|
||||
r = (int)((r1)*65535);
|
||||
g = (int)((g1)*65535);
|
||||
b = (int)((b1)*65535);
|
||||
}
|
||||
|
||||
// The same function but set float values intead if int
|
||||
// Function copied for speed concerns
|
||||
void hsv2rgb (float h, float s, float v, float &r, float &g, float &b) {
|
||||
|
||||
float h1 = h*6; // sector 0 to 5
|
||||
int i = floor( h1 );
|
||||
float f = h1 - i; // fractional part of h
|
||||
|
||||
float p = v * ( 1 - s );
|
||||
float q = v * ( 1 - s * f );
|
||||
float t = v * ( 1 - s * ( 1 - f ) );
|
||||
|
||||
if (i==0) {r = v; g = t; b = p;}
|
||||
if (i==1) {r = q; g = v; b = p;}
|
||||
if (i==2) {r = p; g = v; b = t;}
|
||||
if (i==3) {r = p; g = q; b = v;}
|
||||
if (i==4) {r = t; g = p; b = v;}
|
||||
if (i==5) {r = v; g = p; b = q;}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user