From 094535c010320967639e8e86f974d878e80baa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Fri, 1 May 2015 16:13:57 +0200 Subject: Imported Upstream version 1.7.0 --- profile/invprofcheck.c | 334 +++++-------------------------------------------- 1 file changed, 29 insertions(+), 305 deletions(-) (limited to 'profile/invprofcheck.c') diff --git a/profile/invprofcheck.c b/profile/invprofcheck.c index 0965096..8cb9f34 100644 --- a/profile/invprofcheck.c +++ b/profile/invprofcheck.c @@ -37,6 +37,8 @@ #include "numlib.h" #include "icc.h" #include "xicc.h" +#include "vrml.h" +#include "ui.h" /* Resolution of the sampling modes */ #define TRES 11 @@ -92,19 +94,14 @@ void usage(void) { fprintf(stderr," -R res Specific grid resolution\n"); fprintf(stderr," -c Show CIE94 delta E values\n"); fprintf(stderr," -k Show CIEDE2000 delta E values\n"); - fprintf(stderr," -w create VRML visualisation (profile.wrl)\n"); - fprintf(stderr," -x Use VRML axes\n"); + fprintf(stderr," -w create %s visualisation (profile%s)\n",vrml_format(),vrml_ext()); + fprintf(stderr," -x Use %s axes\n",vrml_format()); fprintf(stderr," -e Color vectors acording to delta E\n"); fprintf(stderr," profile.icm Profile to check\n"); exit(1); } -FILE *start_vrml(char *name, int doaxes); -void start_line_set(FILE *wrl); -void add_vertex(FILE *wrl, double pp[3]); -void make_lines(FILE *wrl, int ppset); -void make_de_lines(FILE *wrl); -void end_vrml(FILE *wrl); +static void DE2RGB(double *out, double in); #if defined(__IBMC__) && defined(_M_IX86) void bug_workaround(int *co) { }; /* Workaround optimiser bug */ @@ -123,14 +120,14 @@ main( int doaxes = 0; int dodecol = 0; char in_name[MAXNAMEL+1]; - char out_name[MAXNAMEL+1], *xl; /* VRML name */ + char out_name[MAXNAMEL+1], *xl; /* VRML/X3D name */ icmFile *rd_fp; icc *icco; int rv = 0; int tres = TRES; double tlimit = -1.0; double klimit = -1.0; - FILE *wrl = NULL; + vrml *wrl = NULL; error_program = "invprofcheck"; @@ -206,7 +203,7 @@ main( klimit = limit/100.0; } - /* VRML */ + /* VRML/X3D */ else if (argv[fa][1] == 'w' || argv[fa][1] == 'W') dovrml = 1; @@ -242,7 +239,7 @@ main( strncpy(out_name,in_name,MAXNAMEL-4); out_name[MAXNAMEL-4] = '\000'; if ((xl = strrchr(out_name, '.')) == NULL) /* Figure where extention is */ xl = out_name + strlen(out_name); - strcpy(xl,".wrl"); + xl[0] = '\000'; /* Remove extension */ /* Open up the file for reading */ if ((rd_fp = new_icmFileStd_name(in_name,"r")) == NULL) @@ -282,8 +279,8 @@ main( } if (dovrml) { - wrl = start_vrml(out_name, doaxes); - start_line_set(wrl); + wrl = new_vrml(out_name, doaxes, vrml_lab); + wrl->start_line_set(wrl, 0); } /* Grab any device calibration curves */ @@ -357,8 +354,21 @@ main( /* Delta E */ if (dovrml) { - add_vertex(wrl, pcsin); - add_vertex(wrl, pcsout); + int ix[2]; + + /* Add the verticies */ + ix[0] = wrl->add_vertex(wrl, 0, pcsin); + ix[1] = wrl->add_vertex(wrl, 0, pcsout); + + /* Add the line */ + if (dodecol) { /* Lines with color determined by length */ + double rgb[3]; + DE2RGB(rgb, icmNorm33(pcsin, pcsout)); + wrl->add_col_line(wrl, 0, ix, rgb); + + } else { /* Natural color */ + wrl->add_line(wrl, 0, ix); + } } /* Check the result */ @@ -386,11 +396,8 @@ main( } } if (dovrml) { - if (dodecol) - make_de_lines(wrl); - else - make_lines(wrl, 2); - end_vrml(wrl); + wrl->make_lines_vc(wrl, 0, 0.0); + wrl->del(wrl); } printf("Profile check complete, errors%s: max. = %f, avg. = %f, RMS = %f\n", @@ -409,291 +416,8 @@ main( /* ------------------------------------------------ */ -/* Some simple functions to do basix VRML work */ -/* !!! Should change to plot/vrml lib !!! */ - -#define GAMUT_LCENT 50.0 -static int npoints = 0; -static int paloc = 0; -static struct { double pp[3]; } *pary; - -static void Lab2RGB(double *out, double *in); -static void DE2RGB(double *out, double in); - -FILE *start_vrml(char *name, int doaxes) { - FILE *wrl; - - /* Define the axis boxes */ - struct { - double x, y, z; /* Box center */ - double wx, wy, wz; /* Box size */ - double r, g, b; /* Box color */ - } axes[5] = { - { 0, 0, 50-GAMUT_LCENT, 2, 2, 100, .7, .7, .7 }, /* L axis */ - { 50, 0, 0-GAMUT_LCENT, 100, 2, 2, 1, 0, 0 }, /* +a (red) axis */ - { 0, -50, 0-GAMUT_LCENT, 2, 100, 2, 0, 0, 1 }, /* -b (blue) axis */ - { -50, 0, 0-GAMUT_LCENT, 100, 2, 2, 0, 1, 0 }, /* -a (green) axis */ - { 0, 50, 0-GAMUT_LCENT, 2, 100, 2, 1, 1, 0 }, /* +b (yellow) axis */ - }; - - /* Define the labels */ - struct { - double x, y, z; - double size; - char *string; - double r, g, b; - } labels[6] = { - { -2, 2, -GAMUT_LCENT + 100 + 10, 10, "+L*", .7, .7, .7 }, /* Top of L axis */ - { -2, 2, -GAMUT_LCENT - 10, 10, "0", .7, .7, .7 }, /* Bottom of L axis */ - { 100 + 5, -3, 0-GAMUT_LCENT, 10, "+a*", 1, 0, 0 }, /* +a (red) axis */ - { -5, -100 - 10, 0-GAMUT_LCENT, 10, "-b*", 0, 0, 1 }, /* -b (blue) axis */ - { -100 - 15, -3, 0-GAMUT_LCENT, 10, "-a*", 0, 0, 1 }, /* -a (green) axis */ - { -5, 100 + 5, 0-GAMUT_LCENT, 10, "+b*", 1, 1, 0 }, /* +b (yellow) axis */ - }; - - if ((wrl = fopen(name,"w")) == NULL) - error("Error opening VRML file '%s'\n",name); - - npoints = 0; - - fprintf(wrl,"#VRML V2.0 utf8\n"); - fprintf(wrl,"\n"); - fprintf(wrl,"# Created by the Argyll CMS\n"); - fprintf(wrl,"Transform {\n"); - fprintf(wrl,"children [\n"); - fprintf(wrl," NavigationInfo {\n"); - fprintf(wrl," type \"EXAMINE\" # It's an object we examine\n"); - fprintf(wrl," } # We'll add our own light\n"); - fprintf(wrl,"\n"); - fprintf(wrl," DirectionalLight {\n"); - fprintf(wrl," direction 0 0 -1 # Light illuminating the scene\n"); - fprintf(wrl," direction 0 -1 0 # Light illuminating the scene\n"); - fprintf(wrl," }\n"); - fprintf(wrl,"\n"); - fprintf(wrl," Viewpoint {\n"); - fprintf(wrl," position 0 0 340 # Position we view from\n"); - fprintf(wrl," }\n"); - fprintf(wrl,"\n"); - if (doaxes != 0) { - int n; - fprintf(wrl," # Lab axes as boxes:\n"); - for (n = 0; n < 5; n++) { - fprintf(wrl," Transform { translation %f %f %f\n", axes[n].x, axes[n].y, axes[n].z); - fprintf(wrl," children [\n"); - fprintf(wrl," Shape{\n"); - fprintf(wrl," geometry Box { size %f %f %f }\n", - axes[n].wx, axes[n].wy, axes[n].wz); - fprintf(wrl," appearance Appearance { material Material "); - fprintf(wrl,"{ diffuseColor %f %f %f} }\n", axes[n].r, axes[n].g, axes[n].b); - fprintf(wrl," }\n"); - fprintf(wrl," ]\n"); - fprintf(wrl," }\n"); - } - fprintf(wrl," # Axes identification:\n"); - for (n = 0; n < 6; n++) { - fprintf(wrl," Transform { translation %f %f %f\n", labels[n].x, labels[n].y, labels[n].z); - fprintf(wrl," children [\n"); - fprintf(wrl," Shape{\n"); - fprintf(wrl," geometry Text { string [\"%s\"]\n",labels[n].string); - fprintf(wrl," fontStyle FontStyle { family \"SANS\" style \"BOLD\" size %f }\n", - labels[n].size); - fprintf(wrl," }\n"); - fprintf(wrl," appearance Appearance { material Material "); - fprintf(wrl,"{ diffuseColor %f %f %f} }\n", labels[n].r, labels[n].g, labels[n].b); - fprintf(wrl," }\n"); - fprintf(wrl," ]\n"); - fprintf(wrl," }\n"); - } - fprintf(wrl,"\n"); - } - - return wrl; -} - -void -start_line_set(FILE *wrl) { - - fprintf(wrl,"\n"); - fprintf(wrl,"Shape {\n"); - fprintf(wrl," geometry IndexedLineSet { \n"); - fprintf(wrl," coord Coordinate { \n"); - fprintf(wrl," point [\n"); -} - -void add_vertex(FILE *wrl, double pp[3]) { - - fprintf(wrl,"%f %f %f,\n",pp[1], pp[2], pp[0]-GAMUT_LCENT); - - if (paloc < (npoints+1)) { - paloc = (paloc + 10) * 2; - if (pary == NULL) - pary = malloc(paloc * 3 * sizeof(double)); - else - pary = realloc(pary, paloc * 3 * sizeof(double)); - - if (pary == NULL) - error ("Malloc failed"); - } - pary[npoints].pp[0] = pp[0]; - pary[npoints].pp[1] = pp[1]; - pary[npoints].pp[2] = pp[2]; - npoints++; -} - - -void make_lines(FILE *wrl, int ppset) { - int i, j; - - fprintf(wrl," ]\n"); - fprintf(wrl," }\n"); - fprintf(wrl," coordIndex [\n"); - - for (i = 0; i < npoints;) { - for (j = 0; j < ppset; j++, i++) { - fprintf(wrl,"%d, ", i); - } - fprintf(wrl,"-1,\n"); - } - fprintf(wrl," ]\n"); - - /* Color */ - fprintf(wrl," colorPerVertex TRUE\n"); - fprintf(wrl," color Color {\n"); - fprintf(wrl," color [ # RGB colors of each vertex\n"); - - for (i = 0; i < npoints; i++) { - double rgb[3], Lab[3]; - Lab[0] = pary[i].pp[0]; - Lab[1] = pary[i].pp[1]; - Lab[2] = pary[i].pp[2]; - Lab2RGB(rgb, Lab); - fprintf(wrl," %f %f %f,\n", rgb[0], rgb[1], rgb[2]); - } - fprintf(wrl," ] \n"); - fprintf(wrl," }\n"); - /* End color */ - - fprintf(wrl," }\n"); - fprintf(wrl,"} # end shape\n"); -} - -/* Assume 2 ppset, and make line color prop to length */ -void make_de_lines(FILE *wrl) { - int i, j; - - fprintf(wrl," ]\n"); - fprintf(wrl," }\n"); - fprintf(wrl," coordIndex [\n"); - - for (i = 0; i < npoints;) { - for (j = 0; j < 2; j++, i++) { - fprintf(wrl,"%d, ", i); - } - fprintf(wrl,"-1,\n"); - } - fprintf(wrl," ]\n"); - - /* Color */ - fprintf(wrl," colorPerVertex TRUE\n"); - fprintf(wrl," color Color {\n"); - fprintf(wrl," color [ # RGB colors of each vertex\n"); - - for (i = 0; i < npoints; i++) { - double rgb[3], ss; - for (ss = 0.0, j = 0; j < 3; j++) { - double tt = (pary[i & ~1].pp[j] - pary[i | 1].pp[j]); - ss += tt * tt; - } - ss = sqrt(ss); - DE2RGB(rgb, ss); - fprintf(wrl," %f %f %f,\n", rgb[0], rgb[1], rgb[2]); - } - fprintf(wrl," ] \n"); - fprintf(wrl," }\n"); - /* End color */ - - fprintf(wrl," }\n"); - fprintf(wrl,"} # end shape\n"); -} - -void end_vrml(FILE *wrl) { - - fprintf(wrl,"\n"); - fprintf(wrl," ] # end of children for world\n"); - fprintf(wrl,"}\n"); - - if (fclose(wrl) != 0) - error("Error closing VRML file\n"); -} - - -/* Convert a gamut Lab value to an RGB value for display purposes */ -static void -Lab2RGB(double *out, double *in) { - double L = in[0], a = in[1], b = in[2]; - double x,y,z,fx,fy,fz; - double R, G, B; - - /* Scale so that black is visible */ - L = L * (100 - 40.0)/100.0 + 40.0; - - /* First convert to XYZ using D50 white point */ - if (L > 8.0) { - fy = (L + 16.0)/116.0; - y = pow(fy,3.0); - } else { - y = L/903.2963058; - fy = 7.787036979 * y + 16.0/116.0; - } - - fx = a/500.0 + fy; - if (fx > 24.0/116.0) - x = pow(fx,3.0); - else - x = (fx - 16.0/116.0)/7.787036979; - - fz = fy - b/200.0; - if (fz > 24.0/116.0) - z = pow(fz,3.0); - else - z = (fz - 16.0/116.0)/7.787036979; - - x *= 0.9642; /* Multiply by white point, D50 */ - y *= 1.0; - z *= 0.8249; - - /* Now convert to sRGB values */ - R = x * 3.2410 + y * -1.5374 + z * -0.4986; - G = x * -0.9692 + y * 1.8760 + z * 0.0416; - B = x * 0.0556 + y * -0.2040 + z * 1.0570; - - if (R < 0.0) - R = 0.0; - else if (R > 1.0) - R = 1.0; - - if (G < 0.0) - G = 0.0; - else if (G > 1.0) - G = 1.0; - - if (B < 0.0) - B = 0.0; - else if (B > 1.0) - B = 1.0; - - R = pow(R, 1.0/2.2); - G = pow(G, 1.0/2.2); - B = pow(B, 1.0/2.2); - - out[0] = R; - out[1] = G; - out[2] = B; -} - /* Convert a delta E value into a signal color: */ -static void -DE2RGB(double *out, double in) { +static void DE2RGB(double *out, double in) { struct { double de; double r, g, b; -- cgit v1.2.3