| 1 |
|
| 2 |
/* |
| 3 |
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. |
| 4 |
* All Rights Reserved |
| 5 |
* |
| 6 |
* This file is a component of an X Window System-specific implementation |
| 7 |
* of XCMS based on the TekColor Color Management System. Permission is |
| 8 |
* hereby granted to use, copy, modify, sell, and otherwise distribute this |
| 9 |
* software and its documentation for any purpose and without fee, provided |
| 10 |
* that this copyright, permission, and disclaimer notice is reproduced in |
| 11 |
* all copies of this software and in supporting documentation. TekColor |
| 12 |
* is a trademark of Tektronix, Inc. |
| 13 |
* |
| 14 |
* Tektronix makes no representation about the suitability of this software |
| 15 |
* for any purpose. It is provided "as is" and with all faults. |
| 16 |
* |
| 17 |
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, |
| 18 |
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 19 |
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY |
| 20 |
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 21 |
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF |
| 22 |
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 23 |
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. |
| 24 |
* |
| 25 |
* |
| 26 |
* |
| 27 |
* NAME |
| 28 |
* CIEXYZ.c |
| 29 |
* |
| 30 |
* DESCRIPTION |
| 31 |
* CIE XYZ Color Space |
| 32 |
* |
| 33 |
* |
| 34 |
*/ |
| 35 |
|
| 36 |
#ifdef HAVE_CONFIG_H |
| 37 |
#include <config.h> |
| 38 |
#endif |
| 39 |
#include <nx-X11/Xos.h> |
| 40 |
#include "Xlibint.h" |
| 41 |
#include "Xcmsint.h" |
| 42 |
#include "Cv.h" |
| 43 |
|
| 44 |
#include <stdio.h> /* sscanf */ |
| 45 |
|
| 46 |
/* |
| 47 |
* DEFINES |
| 48 |
* Internal definitions that need NOT be exported to any package |
| 49 |
* or program using this package. |
| 50 |
*/ |
| 51 |
#ifdef DBL_EPSILON |
| 52 |
# define XMY_DBL_EPSILON DBL_EPSILON |
| 53 |
#else |
| 54 |
# define XMY_DBL_EPSILON 0.00001 |
| 55 |
#endif |
| 56 |
|
| 57 |
/* |
| 58 |
* FORWARD DECLARATIONS |
| 59 |
*/ |
| 60 |
static int CIEXYZ_ParseString(register char *spec, XcmsColor *pColor); |
| 61 |
|
| 62 |
/* |
| 63 |
* LOCALS VARIABLES |
| 64 |
*/ |
| 65 |
|
| 66 |
static XcmsConversionProc Fl_CIEXYZ_to_CIEXYZ[] = { |
| 67 |
NULL |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
/* |
| 73 |
* GLOBALS |
| 74 |
* Variables declared in this package that are allowed |
| 75 |
* to be used globally. |
| 76 |
*/ |
| 77 |
/* |
| 78 |
* CIE XYZ Color Space |
| 79 |
*/ |
| 80 |
XcmsColorSpace XcmsCIEXYZColorSpace = |
| 81 |
{ |
| 82 |
_XcmsCIEXYZ_prefix, /* prefix */ |
| 83 |
XcmsCIEXYZFormat, /* id */ |
| 84 |
CIEXYZ_ParseString, /* parseString */ |
| 85 |
Fl_CIEXYZ_to_CIEXYZ, /* to_CIEXYZ */ |
| 86 |
Fl_CIEXYZ_to_CIEXYZ, /* from_CIEXYZ */ |
| 87 |
1 |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
/************************************************************************ |
| 92 |
* * |
| 93 |
* PRIVATE ROUTINES * |
| 94 |
* * |
| 95 |
************************************************************************/ |
| 96 |
|
| 97 |
/* |
| 98 |
* NAME |
| 99 |
* CIEXYZ_ParseString |
| 100 |
* |
| 101 |
* SYNOPSIS |
| 102 |
*/ |
| 103 |
static int |
| 104 |
CIEXYZ_ParseString( |
| 105 |
register char *spec, |
| 106 |
XcmsColor *pColor) |
| 107 |
/* |
| 108 |
* DESCRIPTION |
| 109 |
* This routines takes a string and attempts to convert |
| 110 |
* it into a XcmsColor structure with XcmsCIEXYZFormat. |
| 111 |
* The assumed CIEXYZ string syntax is: |
| 112 |
* CIEXYZ:<X>/<Y>/<Z> |
| 113 |
* Where X, Y, and Z are in string input format for floats |
| 114 |
* consisting of: |
| 115 |
* a. an optional sign |
| 116 |
* b. a string of numbers possibly containing a decimal point, |
| 117 |
* c. an optional exponent field containing an 'E' or 'e' |
| 118 |
* followed by a possibly signed integer string. |
| 119 |
* |
| 120 |
* RETURNS |
| 121 |
*/ |
| 122 |
{ |
| 123 |
size_t n; |
| 124 |
char *pchar; |
| 125 |
|
| 126 |
if ((pchar = strchr(spec, ':')) == NULL) { |
| 127 |
return(XcmsFailure); |
| 128 |
} |
| 129 |
n = (size_t)(pchar - spec); |
| 130 |
|
| 131 |
/* |
| 132 |
* Check for proper prefix. |
| 133 |
*/ |
| 134 |
if (strncmp(spec, _XcmsCIEXYZ_prefix, n) != 0) { |
| 135 |
return(XcmsFailure); |
| 136 |
} |
| 137 |
|
| 138 |
/* |
| 139 |
* Attempt to parse the value portion. |
| 140 |
*/ |
| 141 |
if (sscanf(spec + n + 1, "%lf/%lf/%lf", |
| 142 |
&pColor->spec.CIEXYZ.X, |
| 143 |
&pColor->spec.CIEXYZ.Y, |
| 144 |
&pColor->spec.CIEXYZ.Z) != 3) { |
| 145 |
char *s; /* Maybe failed due to locale */ |
| 146 |
int f; |
| 147 |
if ((s = strdup(spec))) { |
| 148 |
for (f = 0; s[f]; ++f) |
| 149 |
if (s[f] == '.') |
| 150 |
s[f] = ','; |
| 151 |
else if (s[f] == ',') |
| 152 |
s[f] = '.'; |
| 153 |
if (sscanf(s + n + 1, "%lf/%lf/%lf", |
| 154 |
&pColor->spec.CIEXYZ.X, |
| 155 |
&pColor->spec.CIEXYZ.Y, |
| 156 |
&pColor->spec.CIEXYZ.Z) != 3) { |
| 157 |
free(s); |
| 158 |
return(XcmsFailure); |
| 159 |
} |
| 160 |
free(s); |
| 161 |
} else |
| 162 |
return(XcmsFailure); |
| 163 |
} |
| 164 |
pColor->format = XcmsCIEXYZFormat; |
| 165 |
pColor->pixel = 0; |
| 166 |
return(_XcmsCIEXYZ_ValidSpec(pColor)); |
| 167 |
} |
| 168 |
|
| 169 |
|
| 170 |
/************************************************************************ |
| 171 |
* * |
| 172 |
* PUBLIC ROUTINES * |
| 173 |
* * |
| 174 |
************************************************************************/ |
| 175 |
|
| 176 |
/* |
| 177 |
* NAME |
| 178 |
* XcmsCIELab_ValidSpec |
| 179 |
* |
| 180 |
* SYNOPSIS |
| 181 |
*/ |
| 182 |
Status |
| 183 |
_XcmsCIEXYZ_ValidSpec( |
| 184 |
XcmsColor *pColor) |
| 185 |
/* |
| 186 |
* DESCRIPTION |
| 187 |
* Checks if color specification valid for CIE XYZ |
| 188 |
* |
| 189 |
* RETURNS |
| 190 |
* XcmsFailure if invalid, |
| 191 |
* XcmsSuccess if valid. |
| 192 |
* |
| 193 |
*/ |
| 194 |
{ |
| 195 |
if (pColor->format != XcmsCIEXYZFormat |
| 196 |
|| |
| 197 |
(pColor->spec.CIEXYZ.Y < 0.0 - XMY_DBL_EPSILON) |
| 198 |
|| |
| 199 |
(pColor->spec.CIEXYZ.Y > 1.0 + XMY_DBL_EPSILON)) { |
| 200 |
return(XcmsFailure); |
| 201 |
} |
| 202 |
return(XcmsSuccess); |
| 203 |
} |