2024-11-17 16:13:37 -07:00
|
|
|
#include "hsv.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define FAIL -1
|
|
|
|
#define OK 0
|
|
|
|
|
|
|
|
int test_conv(int r, int g, int b, double tolerance) {
|
|
|
|
vec3 rgb = {r/255.0, g/255.0, b/255.0};
|
|
|
|
double hsv[3];
|
|
|
|
vec3 out;
|
|
|
|
int test[3];
|
|
|
|
rgb_to_hsv(rgb, hsv);
|
|
|
|
hsv_to_rgb(hsv, out);
|
2024-11-17 16:18:54 -07:00
|
|
|
test[0] = rintf(out[0]*255.0);
|
|
|
|
test[1] = rintf(out[1]*255.0);
|
|
|
|
test[2] = rintf(out[2]*255.0);
|
2024-11-17 16:13:37 -07:00
|
|
|
|
2024-11-17 16:18:54 -07:00
|
|
|
if(fabs(rgb[0] - out[0]) > tolerance || fabs(rgb[1] - out[1]) > tolerance || fabs(rgb[2] - out[2]) > tolerance || r != test[0] || g != test[1] || b != test[2]) {
|
|
|
|
fprintf(stderr, "FAIL:\t#%02X%02X%02X -> #%02X%02X%02X\nIN:\t(%.12f %.12f %.12f)\nOUT:\t(%.12f %.12f %.12f)\nMULT:\t(%.12f %.12f %.12f)\n",
|
2024-11-17 16:13:37 -07:00
|
|
|
r, g, b,
|
|
|
|
test[0], test[1], test[2],
|
|
|
|
rgb[0], rgb[1], rgb[2],
|
|
|
|
out[0], out[1], out[2],
|
2024-11-17 16:18:54 -07:00
|
|
|
rintf(out[0]*255.0), rintf(out[1]*255.0), rintf(out[2]*255.0));
|
2024-11-17 16:13:37 -07:00
|
|
|
return FAIL;
|
|
|
|
} else {
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
for(int r = 0; r < 256; r++) {
|
|
|
|
for(int g = 0; g < 256; g++) {
|
|
|
|
for(int b = 0; b < 256; b++) {
|
2024-11-17 19:38:13 -07:00
|
|
|
if(test_conv(r, g, b, 0.000001) != OK) {
|
2024-11-17 16:13:37 -07:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|