2693N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2693N/A * This code is free software; you can redistribute it and/or modify it 2693N/A * under the terms of the GNU General Public License version 2 only, as 2693N/A * published by the Free Software Foundation. Oracle designates this 2693N/A * particular file as subject to the "Classpath" exception as provided 2693N/A * by Oracle in the LICENSE file that accompanied this code. 2693N/A * This code is distributed in the hope that it will be useful, but WITHOUT 2693N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2693N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2693N/A * version 2 for more details (a copy is included in the LICENSE file that 2693N/A * You should have received a copy of the GNU General Public License version 2693N/A * 2 along with this work; if not, write to the Free Software Foundation, 2693N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2693N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2693N/A// This file is available under and governed by the GNU General Public 2693N/A// License version 2 only, as published by the Free Software Foundation. 2693N/A// However, the following notice accompanied the original version of this 2693N/A//--------------------------------------------------------------------------------- 2693N/A// Little Color Management System 6271N/A// Copyright (c) 1998-2011 Marti Maria Saguer 2693N/A// Permission is hereby granted, free of charge, to any person obtaining 2693N/A// a copy of this software and associated documentation files (the "Software"), 2693N/A// to deal in the Software without restriction, including without limitation 2693N/A// the rights to use, copy, modify, merge, publish, distribute, sublicense, 2693N/A// and/or sell copies of the Software, and to permit persons to whom the Software 2693N/A// is furnished to do so, subject to the following conditions: 2693N/A// The above copyright notice and this permission notice shall be included in 2693N/A// all copies or substantial portions of the Software. 2693N/A// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 2693N/A// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 2693N/A// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2693N/A// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 2693N/A// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 2693N/A// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2693N/A// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2693N/A//--------------------------------------------------------------------------------- 2693N/A// ------------------------------------------------------------------------ 2693N/A// Gamut boundary description by using Jan Morovic's Segment maxima method 2693N/A// Many thanks to Jan for allowing me to use his algorithm. 2693N/A// A line using the parametric form 2693N/A// A plane using the parametric form 2693N/A// -------------------------------------------------------------------------------------------- 2693N/A// ATAN2() which always returns degree positive numbers 2693N/A // Deal with undefined case 2693N/A if (x ==
0.0 && y ==
0.0)
return 0;
2693N/A// Convert to spherical coordinates 2693N/A// Convert to cartesian from spherical 2693N/A// Quantize sector of a spherical coordinate. Saturate 360, 180 to last sector 2693N/A// The limits are the centers of each sector, so 2693N/A// Line determined by 2 points 2693N/A Closest point in sector line1 to sector line2 (both are defined as 0 <=t <= 1) 2693N/A This code may be freely used and modified for any purpose 2693N/A providing that this copyright notice is included with it. 2693N/A SoftSurfer makes no warranty for this code, and cannot be held 2693N/A liable for any real or imagined damage resulting from its use. 2693N/A Users of this code must verify correctness for their application. 2693N/A D = a*c - b * b;
// Denominator 2693N/A sN =
0.0;
// force using point P0 on segment S1 2693N/A sD =
1.0;
// to prevent possible division by 0.0 later 2693N/A else {
// get the closest points on the infinite lines 2693N/A if (
sN <
0.0) {
// sc < 0 => the s=0 edge is visible 2693N/A else if (
sN >
sD) {
// sc > 1 => the s=1 edge is visible 2693N/A if (
tN <
0.0) {
// tc < 0 => the t=0 edge is visible 2693N/A // recompute sc for this edge 2693N/A else if (
tN >
tD) {
// tc > 1 => the t=1 edge is visible 2693N/A // recompute sc for this edge 2693N/A // finally do the division to get sc and tc 2693N/A// ------------------------------------------------------------------ Wrapper 2693N/A// Allocate & free structure 2693N/A// Auxiliar to retrieve a pointer to the segmentr containing the Lab value 2693N/A // Center L* by substracting half of its domain, that's 50 2693N/A // Convert to spherical coordinates 2693N/A // On which sector it falls? 2693N/A // Get pointer to the sector 2693N/A// Add a point to gamut descriptor. Point to add is in Lab color space. 2693N/A// GBD is centered on a=b=0 and L*=50 2693N/A // Get pointer to the sector 2693N/A // If no samples at this sector, add it 2693N/A // Substitute only if radius is greater 2693N/A// Check if a given point falls inside gamut 2693N/A // Get pointer to the sector 2693N/A // If no samples at this sector, return no data 2693N/A // In gamut only if radius is greater 2693N/A// ----------------------------------------------------------------------------------------------------------------------- 2693N/A// Find near sectors. The list of sectors found is returned on Close[]. 2693N/A// The function returns the number of sectors as well. 2693N/A// Those are the relative movements 2693N/A// {-2,-2}, {-1, -2}, {0, -2}, {+1, -2}, {+2, -2}, 2693N/A// {-2,-1}, {-1, -1}, {0, -1}, {+1, -1}, {+2, -1}, 2693N/A// {-2, 0}, {-1, 0}, {0, 0}, {+1, 0}, {+2, 0}, 2693N/A// {-2,+1}, {-1, +1}, {0, +1}, {+1, +1}, {+2, +1}, 2693N/A// {-2,+2}, {-1, +2}, {0, +2}, {+1, +2}, {+2, +2}}; 2693N/A }
Spiral[] = { {0, -
1}, {+
1, -
1}, {+
1, 0}, {+
1, +
1}, {0, +
1}, {-
1, +
1},
2693N/A {-
1, 0}, {-
1, -
1}, {-
1, -
2}, {0, -
2}, {+
1, -
2}, {+
2, -
2},
2693N/A {+
2, -
1}, {+
2, 0}, {+
2, +
1}, {+
2, +
2}, {+
1, +
2}, {0, +
2},
2693N/A {-
1, +
2}, {-
2, +
2}, {-
2, +
1}, {-
2, 0}, {-
2, -
1}, {-
2, -
2} };
2693N/A// Interpolate a missing sector. Method identifies whatever this is top, bottom or mid 2693N/A // Is that point already specified? 2693N/A // Find a central point on the sector 2693N/A // Create a ray line from centre to this point 2693N/A // A line from sector to sector 2693N/A// Interpolate missing parts. The algorithm fist computes slices at 2693N/A// -------------------------------------------------------------------------------------------------------- 2693N/A// Great for debug, but not suitable for real use 2693N/A // set the viewing orientation and distance 2693N/A // Output the background stuff 2693N/A // Draw the axes as a shape: 2693N/A // We need to transverse all gamut hull.