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 6271N/A// Copyright (c) 1998-2012 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// Read tags using low-level functions, provides necessary glue code to adapt versions, etc. 2693N/A// Factors to convert from 1.15 fixed point to 0..1.0 range and vice-versa 2693N/A// Several resources for gray conversions. 2693N/A// Get a media white point fixing some issues found in certain old profiles 2693N/A // V2 display profiles should give D50 2693N/A// Chromatic adaptation matrix. Fix some issues as well 2693N/A // No CHAD available, default it to identity 2693N/A // V2 display profiles should give D50 2693N/A// Auxiliar, read colorants as a MAT3 structure. Used by any function that needs a matrix-shaper 2693N/A // In this case we implement the profile as an identity matrix plus 3 tone curves 2693N/A // XYZ PCS in encoded in 1.15 format, and the matrix output comes in 0..0xffff range, so 2693N/A // we need to adjust the output by a factor of (0x10000/0xffff) to put data in 2693N/A // a 1.16 range, and then a >> 1 to obtain 1.15. The total factor is (65536.0)/(65535.0*2) 6271N/A // Note that it is certainly possible a single profile would have a LUT based 6271N/A // tag for output working in lab and a matrix-shaper for the fallback cases. 6271N/A // This is not allowed by the spec, but this code is tolerant to those cases 6271N/A// Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded 6271N/AcmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) 6271N/A cmsContext ContextID = cmsGetProfileContextID(hProfile); 6271N/A cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); 6271N/A cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile); 6271N/A if (Lut == NULL) return NULL; 6271N/A // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, 6271N/A // and since the formatter has already accomodated to 0..1.0, we should undo this change 6271N/A cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID)); 6271N/A cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID)); 6271N/A // input and output of transform are in lcms 0..1 encoding. If XYZ or Lab spaces are used, 6271N/A // these need to be normalized into the appropriate ranges (Lab = 100,0,0, XYZ=1.0,1.0,1.0) 2693N/A// Read and create a BRAND NEW MPE LUT from a given profile. All stuff dependent of version, etc 2693N/A// is adjusted here in order to create a LUT that takes care of all those details 6271N/A // On named color, take the appropiate tag 6271N/A // Floating point LUT are always V4, but the encoding range is no 6271N/A // longer 0..1.0, so we need to add an stage depending on the color space 2693N/A // Revert to perceptual if no tag is found 2693N/A // Check profile version and LUT type. Do the necessary adjustments if needed 2693N/A // After reading it, we have now info about the original type 2693N/A // The profile owns the Lut, so we need to copy it 2693N/A // We need to adjust data only for Lab16 on output 6271N/A // If the input is Lab, add also a conversion at the begin 2693N/A // Add a matrix for conversion V2 to V4 Lab PCS 2693N/A // Lut was not found, try to create a matrix-shaper 2693N/A // Check if this is a grayscale profile. 2693N/A // if so, build appropiate conversion tables. 2693N/A // The tables are the PCS iluminant, scaled across GrayTRC 2693N/A // Not gray, create a normal matrix-shaper 2693N/A// --------------------------------------------------------------------------------------------------------------- 2693N/A// XYZ -> Gray or Lab -> Gray. Since we only know the GrayTRC, we need to do some assumptions. Gray component will be 2693N/A// given by Y on XYZ PCS and by L* on Lab PCS, Both across inverse TRC curve. 2693N/A// The complete pipeline on XYZ is Matrix[3:1] -> Tone curve and in Lab Matrix[3:1] -> Tone Curve as well. 2693N/A // XYZ PCS in encoded in 1.15 format, and the matrix input should come in 0..0xffff range, so 2693N/A // we need to adjust the input by a << 1 to obtain a 1.16 fixed and then by a factor of 2693N/A // (0xffff/0x10000) to put data in 0..0xffff range. Total factor is (2.0*65535.0)/65536.0; 6271N/A // Note that it is certainly possible a single profile would have a LUT based 6271N/A // tag for output working in lab and a matrix-shaper for the fallback cases. 6271N/A // This is not allowed by the spec, but this code is tolerant to those cases 6271N/A// Change CLUT interpolation to trilinear 6271N/A// Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded 6271N/AcmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat) 6271N/A cmsContext ContextID = cmsGetProfileContextID(hProfile); 6271N/A cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat)); 6271N/A cmsColorSpaceSignature PCS = cmsGetPCS(hProfile); 6271N/A if (Lut == NULL) return NULL; 6271N/A // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, 6271N/A // and since the formatter has already accomodated to 0..1.0, we should undo this change 6271N/A cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID)); 6271N/A cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID)); 6271N/A // If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding, 6271N/A // and since the formatter has already accomodated to 0..1.0, we should undo this change 6271N/A // the output can be Lab or XYZ, in which case normalisation is needed on the end of the pipeline 2693N/A// Create an output MPE LUT from agiven profile. Version mismatches are handled here 6271N/A // Floating point LUT are always V4 2693N/A // Revert to perceptual if no tag is found 2693N/A // Check profile version and LUT type. Do the necessary adjustments if needed 2693N/A // After reading it, we have info about the original type 2693N/A // The profile owns the Lut, so we need to copy it 6271N/A // Now it is time for a controversial stuff. I found that for 3D LUTS using 6271N/A // Lab used as indexer space, trilinear interpolation should be used 2693N/A // We need to adjust data only for Lab and Lut16 type 2693N/A // Add a matrix for conversion V4 to V2 Lab PCS 6271N/A // If the output is Lab, add also a conversion at the end 2693N/A // Lut not found, try to create a matrix-shaper 2693N/A // Check if this is a grayscale profile. 2693N/A // if so, build appropiate conversion tables. 2693N/A // The tables are the PCS iluminant, scaled across GrayTRC 6271N/A // Not gray, create a normal matrix-shaper, which only operates in XYZ space 2693N/A// --------------------------------------------------------------------------------------------------------------- 6271N/A// Read the AToD0 tag, adjusting the encoding of Lab or XYZ if neded 2693N/A// This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The 2693N/A// tag name here may default to AToB0 6271N/A // On named color, take the appropiate tag 6271N/A // Floating point LUT are always V 2693N/A // Check profile version and LUT type. Do the necessary adjustments if needed 2693N/A // The profile owns the Lut, so we need to copy it 6271N/A // Now it is time for a controversial stuff. I found that for 3D LUTS using 6271N/A // Lab used as indexer space, trilinear interpolation should be used 2693N/A // After reading it, we have info about the original type 2693N/A // We need to adjust data for Lab16 on output 2693N/A // Here it is possible to get Lab on both sides 2693N/A// --------------------------------------------------------------------------------------------------------------- 2693N/A// Returns TRUE if the profile is implemented as matrix-shaper 2693N/A// Returns TRUE if the intent is implemented as CLUT 2693N/A // For devicelinks, the supported intent is that one stated in the header 2693N/A // For proofing, we need rel. colorimetric in output. Let's do some recursion 2693N/A// Return info about supported intents 2693N/A // Is there any matrix-shaper? If so, the intent is supported. This is a bit odd, since V2 matrix shaper 2693N/A // does not fully support relative colorimetric because they cannot deal with non-zero black points, but 2693N/A // many profiles claims that, and this is certainly not true for V4 profiles. Lets answer "yes" no matter 2693N/A // the accuracy would be less than optimal in rel.col and v2 case. 2693N/A// --------------------------------------------------------------------------------------------------------------- 2693N/A// Read both, profile sequence description and profile sequence id if present. Then combine both to 2693N/A// create qa unique structure holding both. Shame on ICC to store things in such complicated way. 2693N/A // Take profile sequence description first 2693N/A // Take profile sequence ID 2693N/A // We have to mix both together. For that they must agree 2693N/A // Ok, proceed to the mixing 2693N/A// Dump the contents of profile sequence in both tags (if v4 available) 2693N/A// Auxiliar, read and duplicate a MLU if found. 2693N/A// Create a sequence description out of an array of profiles 2693N/A// -------------------------------------------------------------------------------------------------------------------