13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2010 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
320
321 static
322 cmsUInt16Number ab2Fix4(cmsFloat64Number ab)
323 {
324 return _cmsQuickSaturateWord((ab + 128.0) * 257.0);
325 }
326
327 void CMSEXPORT cmsFloat2LabEncoded(cmsUInt16Number wLab[3], const cmsCIELab* fLab)
328 {
329 cmsCIELab Lab;
330
331 Lab.L = Clamp_L_doubleV4(fLab ->L);
332 Lab.a = Clamp_ab_doubleV4(fLab ->a);
333 Lab.b = Clamp_ab_doubleV4(fLab ->b);
334
335 wLab[0] = L2Fix4(Lab.L);
336 wLab[1] = ab2Fix4(Lab.a);
337 wLab[2] = ab2Fix4(Lab.b);
338 }
339
340 // Auxiliar: convert to Radians
341 static
342 cmsFloat64Number RADIANS(cmsFloat64Number deg)
343 {
344 return (deg * M_PI) / 180.;
345 }
346
347
348 // Auxiliar: atan2 but operating in degrees and returning 0 if a==b==0
349 static
350 cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b)
351 {
352 cmsFloat64Number h;
353
354 if (a == 0 && b == 0)
355 h = 0;
356 else
357 h = atan2(a, b);
358
359 h *= (180. / M_PI);
360
361 while (h > 360.)
362 h -= 360.;
363
364 while ( h < 0)
365 h += 360.;
366
367 return h;
368 }
369
370
371 // Auxiliar: Square
372 static
373 cmsFloat64Number Sqr(cmsFloat64Number v)
374 {
375 return v * v;
376 }
377 // From cylindrical coordinates. No check is performed, then negative values are allowed
378 void CMSEXPORT cmsLab2LCh(cmsCIELCh* LCh, const cmsCIELab* Lab)
379 {
380 LCh -> L = Lab -> L;
381 LCh -> C = pow(Sqr(Lab ->a) + Sqr(Lab ->b), 0.5);
382 LCh -> h = atan2deg(Lab ->b, Lab ->a);
383 }
384
385
386 // To cylindrical coordinates. No check is performed, then negative values are allowed
387 void CMSEXPORT cmsLCh2Lab(cmsCIELab* Lab, const cmsCIELCh* LCh)
388 {
389 cmsFloat64Number h = (LCh -> h * M_PI) / 180.0;
390
391 Lab -> L = LCh -> L;
|
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 // This file is available under and governed by the GNU General Public
26 // License version 2 only, as published by the Free Software Foundation.
27 // However, the following notice accompanied the original version of this
28 // file:
29 //
30 //---------------------------------------------------------------------------------
31 //
32 // Little Color Management System
33 // Copyright (c) 1998-2016 Marti Maria Saguer
34 //
35 // Permission is hereby granted, free of charge, to any person obtaining
36 // a copy of this software and associated documentation files (the "Software"),
37 // to deal in the Software without restriction, including without limitation
38 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
39 // and/or sell copies of the Software, and to permit persons to whom the Software
40 // is furnished to do so, subject to the following conditions:
41 //
42 // The above copyright notice and this permission notice shall be included in
43 // all copies or substantial portions of the Software.
44 //
45 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
47 // THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
48 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
49 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
50 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
51 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 //
53 //---------------------------------------------------------------------------------
320
321 static
322 cmsUInt16Number ab2Fix4(cmsFloat64Number ab)
323 {
324 return _cmsQuickSaturateWord((ab + 128.0) * 257.0);
325 }
326
327 void CMSEXPORT cmsFloat2LabEncoded(cmsUInt16Number wLab[3], const cmsCIELab* fLab)
328 {
329 cmsCIELab Lab;
330
331 Lab.L = Clamp_L_doubleV4(fLab ->L);
332 Lab.a = Clamp_ab_doubleV4(fLab ->a);
333 Lab.b = Clamp_ab_doubleV4(fLab ->b);
334
335 wLab[0] = L2Fix4(Lab.L);
336 wLab[1] = ab2Fix4(Lab.a);
337 wLab[2] = ab2Fix4(Lab.b);
338 }
339
340 // Auxiliary: convert to Radians
341 static
342 cmsFloat64Number RADIANS(cmsFloat64Number deg)
343 {
344 return (deg * M_PI) / 180.;
345 }
346
347
348 // Auxiliary: atan2 but operating in degrees and returning 0 if a==b==0
349 static
350 cmsFloat64Number atan2deg(cmsFloat64Number a, cmsFloat64Number b)
351 {
352 cmsFloat64Number h;
353
354 if (a == 0 && b == 0)
355 h = 0;
356 else
357 h = atan2(a, b);
358
359 h *= (180. / M_PI);
360
361 while (h > 360.)
362 h -= 360.;
363
364 while ( h < 0)
365 h += 360.;
366
367 return h;
368 }
369
370
371 // Auxiliary: Square
372 static
373 cmsFloat64Number Sqr(cmsFloat64Number v)
374 {
375 return v * v;
376 }
377 // From cylindrical coordinates. No check is performed, then negative values are allowed
378 void CMSEXPORT cmsLab2LCh(cmsCIELCh* LCh, const cmsCIELab* Lab)
379 {
380 LCh -> L = Lab -> L;
381 LCh -> C = pow(Sqr(Lab ->a) + Sqr(Lab ->b), 0.5);
382 LCh -> h = atan2deg(Lab ->b, Lab ->a);
383 }
384
385
386 // To cylindrical coordinates. No check is performed, then negative values are allowed
387 void CMSEXPORT cmsLCh2Lab(cmsCIELab* Lab, const cmsCIELCh* LCh)
388 {
389 cmsFloat64Number h = (LCh -> h * M_PI) / 180.0;
390
391 Lab -> L = LCh -> L;
|