Initial HSV
This commit is contained in:
parent
ff70185dda
commit
b24c7ee546
@ -38,26 +38,65 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include <vips/vips.h>
|
#include <vips/vips.h>
|
||||||
|
|
||||||
#include "pcolour.h"
|
#include "pcolour.h"
|
||||||
|
|
||||||
|
#define sixth_of_char 42.5
|
||||||
|
#define H p[0]
|
||||||
|
#define S p[1]
|
||||||
|
#define V p[2]
|
||||||
|
#define R p[0]
|
||||||
|
#define G p[1]
|
||||||
|
#define B p[2]
|
||||||
|
|
||||||
typedef VipsColourCode VipsHSV2sRGB;
|
typedef VipsColourCode VipsHSV2sRGB;
|
||||||
typedef VipsColourCodeClass VipsHSV2sRGBClass;
|
typedef VipsColourCodeClass VipsHSV2sRGBClass;
|
||||||
|
|
||||||
G_DEFINE_TYPE( VipsHSV2sRGB, vips_HSV2sRGB, VIPS_TYPE_COLOUR_CODE );
|
G_DEFINE_TYPE( VipsHSV2sRGB, vips_HSV2sRGB, VIPS_TYPE_COLOUR_CODE );
|
||||||
|
|
||||||
static void
|
static void vips_HSV2sRGB_line(VipsColour *colour, VipsPel *out, VipsPel **in,
|
||||||
vips_HSV2sRGB_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
int width) {
|
||||||
{
|
|
||||||
unsigned char *p = (unsigned char *) in[0];
|
unsigned char *p = (unsigned char *) in[0];
|
||||||
unsigned char *q = (unsigned char *) out;
|
unsigned char *q = (unsigned char *) out;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for( i = 0; i < width; i++ ) {
|
|
||||||
q[0] = p[0];
|
|
||||||
q[1] = p[1];
|
float c, x, m, s, t, u;
|
||||||
q[2] = p[2];
|
for (i = 0; i < width; i++) {
|
||||||
|
|
||||||
|
c = V* S / 255.0f;
|
||||||
|
x = C * (1 - abs(fmod(H / sixth_of_char, 2) - 1));
|
||||||
|
m = V - c;
|
||||||
|
|
||||||
|
if (H < sixth_of_char) {
|
||||||
|
R= (c+m);
|
||||||
|
G= (x+m);
|
||||||
|
B= (0+m);
|
||||||
|
} else if (H < 2*sixth_of_char) {
|
||||||
|
R= (x+m);
|
||||||
|
G= (c+m);
|
||||||
|
B= (0+m);
|
||||||
|
} else if (H < 3*sixth_of_char) {
|
||||||
|
R= (0+m);
|
||||||
|
G= (c+m);
|
||||||
|
B= (x+m);
|
||||||
|
} else if (H < 4*sixth_of_char) {
|
||||||
|
R= (0+m);
|
||||||
|
G= (x+m);
|
||||||
|
B= (c+m);
|
||||||
|
} else if (H < 5*sixth_of_char) {
|
||||||
|
R= (x+m);
|
||||||
|
G= (0+m);
|
||||||
|
B= (c+m);
|
||||||
|
} else {
|
||||||
|
R= (c+m);
|
||||||
|
G= (0+m);
|
||||||
|
B= (x+m);
|
||||||
|
}
|
||||||
|
|
||||||
p += 3;
|
p += 3;
|
||||||
q += 3;
|
q += 3;
|
||||||
|
@ -58,6 +58,10 @@ vips_sRGB2HSV_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
|||||||
|
|
||||||
float wrap_around_hue, secondary_diff;
|
float wrap_around_hue, secondary_diff;
|
||||||
|
|
||||||
|
#define RED 255.0f;
|
||||||
|
#define GREEN 85.0f;
|
||||||
|
#define BLUE 170.0f;
|
||||||
|
|
||||||
|
|
||||||
for( i = 0; i < width; i++ ) {
|
for( i = 0; i < width; i++ ) {
|
||||||
|
|
||||||
@ -66,12 +70,12 @@ vips_sRGB2HSV_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
|||||||
c_max = p[0];
|
c_max = p[0];
|
||||||
c_min = p[1];
|
c_min = p[1];
|
||||||
secondary_diff = p[1] - p[2];
|
secondary_diff = p[1] - p[2];
|
||||||
wrap_around_hue = 255.0f;
|
wrap_around_hue = RED;
|
||||||
} else {
|
} else {
|
||||||
c_max = p[2];
|
c_max = p[2];
|
||||||
c_min = VIPS_MIN(p[1], p[0]);
|
c_min = VIPS_MIN(p[1], p[0]);
|
||||||
secondary_diff = p[0] - p[1];
|
secondary_diff = p[0] - p[1];
|
||||||
wrap_around_hue = 170.0f;
|
wrap_around_hue = BLUE;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (p[1] < p[0]) {
|
if (p[1] < p[0]) {
|
||||||
@ -83,7 +87,7 @@ vips_sRGB2HSV_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
|||||||
c_max = p[1];
|
c_max = p[1];
|
||||||
c_min = VIPS_MIN(p[2], p[0]);
|
c_min = VIPS_MIN(p[2], p[0]);
|
||||||
secondary_diff = p[2] - p[0];
|
secondary_diff = p[2] - p[0];
|
||||||
wrap_around_hue = 85.0f;
|
wrap_around_hue = GREEN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +103,7 @@ vips_sRGB2HSV_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
|||||||
if (delta == 0) {
|
if (delta == 0) {
|
||||||
q[0] = 0;
|
q[0] = 0;
|
||||||
} else {
|
} else {
|
||||||
q[0] = (unsigned char) (42.5f*(secondary_diff / (float) delta) + wrap_around_hue);
|
q[0] = (42.5f*(secondary_diff / (float) delta) + wrap_around_hue);
|
||||||
}
|
}
|
||||||
|
|
||||||
q[1] = (( delta*255.0f / (float) c_max));
|
q[1] = (( delta*255.0f / (float) c_max));
|
||||||
|
Loading…
Reference in New Issue
Block a user