0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// This file is available under and governed by the GNU General Public 0N/A// License version 2 only, as published by the Free Software Foundation. 0N/A// However, the following notice accompanied the original version of this 2693N/A//--------------------------------------------------------------------------------- 2693N/A// Little Color Management System 2693N/A// Copyright (c) 1998-2010 Marti Maria Saguer 0N/A// Permission is hereby granted, free of charge, to any person obtaining 0N/A// a copy of this software and associated documentation files (the "Software"), 0N/A// to deal in the Software without restriction, including without limitation 0N/A// the rights to use, copy, modify, merge, publish, distribute, sublicense, 0N/A// and/or sell copies of the Software, and to permit persons to whom the Software 0N/A// is furnished to do so, subject to the following conditions: 0N/A// The above copyright notice and this permission notice shall be included in 0N/A// all copies or substantial portions of the Software. 0N/A// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0N/A// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 0N/A// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0N/A// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 0N/A// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 0N/A// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 0N/A// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2693N/A//--------------------------------------------------------------------------------- 2693N/A// This file contains routines for resampling and LUT optimization, black point detection 2693N/A// Black point detection ------------------------------------------------------------------------- 2693N/A// PCS -> PCS round trip transform, always uses relative intent on the device -> pcs 2693N/A// Use darker colorants to obtain black point. This works in the relative colorimetric intent and 2693N/A// assumes more ink results in darker colors. No ink limit is assumed. 2693N/A // If the profile does not support input direction, assume Black point 0 2693N/A // Create a formatter which has n channels and floating point 2693N/A // Try to get black by using black colorant 2693N/A // This function returns darker colorant in 16 bits for several spaces 2693N/A // Lab will be used as the output space, but lab2 will avoid recursion 2693N/A // Something went wrong. Get rid of open resources and return zero as black 2693N/A // Force it to be neutral, clip to max. L* of 50 2693N/A // Convert from Lab (which is now clipped) to XYZ. 2693N/A// Get a black point of output CMYK profile, discounting any ink-limiting embedded 2693N/A// in the profile. For doing that, we use perceptual intent in input direction: 2693N/A// Lab (0, 0, 0) -> [Perceptual] Profile -> CMYK -> [Rel. colorimetric] Profile -> Lab 2693N/A // Is the intent supported by the profile? 2693N/A // Clip Lab to reasonable limits 2693N/A// This function shouldn't exist at all -- there is such quantity of broken 2693N/A// profiles on black point tag, that we must somehow fix chromaticity to 2693N/A// avoid huge tint when doing Black point compensation. This function does 2693N/A// just that. There is a special flag for using black point tag, but turned 2693N/A// off by default because it is bogus on most profiles. The detection algorithm 2693N/A// involves to turn BP to neutral and to use only L component. 2693N/A // v4 + perceptual & saturation intents does have its own black point, and it is 2693N/A // well specified enough to use it. Black point tag is deprecated in V4. 2693N/A // Matrix shaper share MRC & perceptual intents 2693N/A // Get Perceptual black out of v4 profiles. That is fixed for perceptual & saturation intents 2693N/A // If black point is specified, then use it, 2693N/A // Black point is absolute XYZ, so adapt to D50 to get PCS value 2693N/A // Force a=b=0 to get rid of any chroma 2693N/A // That is about v2 profiles. 2693N/A // If output profile, discount ink-limiting and that's all 2693N/A // Nope, compute BP using current intent. 6271N/A// --------------------------------------------------------------------------------------------------------- 6271N/A// Least Squares Fit of a Quadratic Curve to Data 6271N/A // x = ( - u + Sqrt( u^2 - 4 t c ) ) / ( 2 t ) 6271N/A for (i = n-
2; i >= 0; --i) {
6271N/A// Calculates the black point of a destination profile. 6271N/A// This algorithm comes from the Adobe paper disclosing its black point compensation method. 6271N/A // Make sure intent is adequate 6271N/A // v4 + perceptual & saturation intents does have its own black point, and it is 6271N/A // well specified enough to use it. Black point tag is deprecated in V4. 6271N/A // Matrix shaper share MRC & perceptual intents 6271N/A // Get Perceptual black out of v4 profiles. That is fixed for perceptual & saturation intents 6271N/A // Check if the profile is lut based and gray, rgb or cmyk (7.2 in Adobe's document) 6271N/A // In this case, handle as input case 6271N/A // It is one of the valid cases!, presto chargo hocus pocus, go for the Adobe magic 6271N/A // Set a first guess, that should work on good profiles. 6271N/A // calculate initial Lab as source black point 6271N/A // set the initial Lab to zero, that should be the black point for perceptual and saturation 6271N/A // Create a roundtrip. Define a Transform BT for all x in L*a*b* 6271N/A // check if quadratic estimation needs to be done. 6271N/A // Conceptually, this code tests how close the source l and converted L are to one another in the mid-range 6271N/A // of the values. If the converted ramp of L values is close enough to a straight line y=x, then InitialLab 6271N/A // is good enough to be the DestinationBlackPoint, 6271N/A // Check the mid range in 20% after MinL 6271N/A // Too far away, profile is buggy! 6271N/A // Check is always performed for perceptual and saturation intents 6271N/A // If no furter checking is needed, we are done 6271N/A // The round-trip curve normally looks like a nearly constant section at the black point, 6271N/A // with a corner and a nearly straight line to the white point. 6271N/A // find the black point using the least squares error quadratic curve fitting 6271N/A // Perceptual and saturation 6271N/A // Capture points for the fitting. 6271N/A // This part is not on the Adobe paper, but I found is necessary for getting any result. 6271N/A // Monotonic means lower point is stil valid 6271N/A // No suitable points, regret and use safer algorithm 6271N/A // fit and get the vertex of quadratic curve 6271N/A if (
Lab.L <
0.0 ||
Lab.L >
50.0) {
// clip to zero L* if the vertex is negative