#include "hsv.h" #include #include #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); test[0] = rintf(out[0]*255.0); test[1] = rintf(out[1]*255.0); test[2] = rintf(out[2]*255.0); 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", r, g, b, test[0], test[1], test[2], rgb[0], rgb[1], rgb[2], out[0], out[1], out[2], rintf(out[0]*255.0), rintf(out[1]*255.0), rintf(out[2]*255.0)); 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++) { if(test_conv(r, g, b, 0.000001) != OK) { return -1; } } } } }