/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// This file is available under and governed by the GNU General Public
// License version 2 only, as published by the Free Software Foundation.
// However, the following notice accompanied the original version of this
// file:
//
//---------------------------------------------------------------------------------
//
// Little Color Management System
// Copyright (c) 1998-2012 Marti Maria Saguer
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//---------------------------------------------------------------------------------
//
#include "lcms2_internal.h"
// Read tags using low-level functions, provides necessary glue code to adapt versions, etc.
// LUT tags
cmsSigAToB1Tag, // Relative colorimetric
cmsSigAToB2Tag, // Saturation
cmsSigAToB1Tag }; // Absolute colorimetric
cmsSigDToB1Tag, // Relative colorimetric
cmsSigDToB2Tag, // Saturation
cmsSigDToB3Tag }; // Absolute colorimetric
cmsSigBToA1Tag, // Relative colorimetric
cmsSigBToA2Tag, // Saturation
cmsSigBToA1Tag }; // Absolute colorimetric
cmsSigBToD1Tag, // Relative colorimetric
cmsSigBToD2Tag, // Saturation
cmsSigBToD3Tag }; // Absolute colorimetric
// Factors to convert from 1.15 fixed point to 0..1.0 range and vice-versa
// Several resources for gray conversions.
static const cmsFloat64Number GrayInputMatrix[] = { (InpAdj*cmsD50X), (InpAdj*cmsD50Y), (InpAdj*cmsD50Z) };
// Get a media white point fixing some issues found in certain old profiles
{
// If no wp, take D50
*Dest = *cmsD50_XYZ();
return TRUE;
}
// V2 display profiles should give D50
*Dest = *cmsD50_XYZ();
return TRUE;
}
}
// All seems ok
return TRUE;
}
// Chromatic adaptation matrix. Fix some issues as well
{
return TRUE;
}
// No CHAD available, default it to identity
// V2 display profiles should give D50
return TRUE;
}
}
}
return TRUE;
}
// Auxiliar, read colorants as a MAT3 structure. Used by any function that needs a matrix-shaper
static
{
_cmsAssert(r != NULL);
return FALSE;
return TRUE;
}
// Gray input pipeline
static
{
// In this case we implement the profile as an identity matrix plus 3 tone curves
return NULL;
}
cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, OneToThreeInputMatrix, NULL));
}
else {
cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 1, GrayInputMatrix, NULL));
}
return Lut;
}
// RGB Matrix shaper
static
{
int i, j;
// XYZ PCS in encoded in 1.15 format, and the matrix output comes in 0..0xffff range, so
// we need to adjust the output by a factor of (0x10000/0xffff) to put data in
// a 1.16 range, and then a >> 1 to obtain 1.15. The total factor is (65536.0)/(65535.0*2)
for (i=0; i < 3; i++)
for (j=0; j < 3; j++)
return NULL;
cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Mat, NULL));
// Note that it is certainly possible a single profile would have a LUT based
// tag for output working in lab and a matrix-shaper for the fallback cases.
// This is not allowed by the spec, but this code is tolerant to those cases
}
}
return Lut;
}
// Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded
/*static
cmsPipeline* _cmsReadFloatInputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
{
cmsContext ContextID = cmsGetProfileContextID(hProfile);
cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
cmsColorSpaceSignature spc = cmsGetColorSpace(hProfile);
if (Lut == NULL) return NULL;
// If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding,
// and since the formatter has already accomodated to 0..1.0, we should undo this change
if ( spc == cmsSigLabData)
{
cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromLabFloat(ContextID));
}
else
if (spc == cmsSigXYZData)
{
cmsPipelineInsertStage(Lut, cmsAT_END, _cmsStageNormalizeFromXyzFloat(ContextID));
}
return Lut;
}
*/
static
{
// input and output of transform are in lcms 0..1 encoding. If XYZ or Lab spaces are used,
// these need to be normalized into the appropriate ranges (Lab = 100,0,0, XYZ=1.0,1.0,1.0)
if ( spc == cmsSigLabData)
{
}
else if (spc == cmsSigXYZData)
{
}
if ( PCS == cmsSigLabData)
{
}
else if( PCS == cmsSigXYZData)
{
}
return Lut;
}
// Read and create a BRAND NEW MPE LUT from a given profile. All stuff dependent of version, etc
// is adjusted here in order to create a LUT that takes care of all those details
{
// On named color, take the appropiate tag
return NULL;
}
return Lut;
}
// Floating point LUT are always V4, but the encoding range is no
// longer 0..1.0, so we need to add an stage depending on the color space
}
// Revert to perceptual if no tag is found
tag16 = Device2PCS16[0];
}
// Check profile version and LUT type. Do the necessary adjustments if needed
// First read the tag
// After reading it, we have now info about the original type
// The profile owns the Lut, so we need to copy it
// We need to adjust data only for Lab16 on output
return Lut;
// If the input is Lab, add also a conversion at the begin
// Add a matrix for conversion V2 to V4 Lab PCS
return Lut;
}
// Lut was not found, try to create a matrix-shaper
// Check if this is a grayscale profile.
// if so, build appropiate conversion tables.
// The tables are the PCS iluminant, scaled across GrayTRC
return BuildGrayInputMatrixPipeline(hProfile);
}
// Not gray, create a normal matrix-shaper
return BuildRGBInputMatrixShaper(hProfile);
}
// ---------------------------------------------------------------------------------------------------------------
// Gray output pipeline.
// XYZ -> Gray or Lab -> Gray. Since we only know the GrayTRC, we need to do some assumptions. Gray component will be
// given by Y on XYZ PCS and by L* on Lab PCS, Both across inverse TRC curve.
// The complete pipeline on XYZ is Matrix[3:1] -> Tone curve and in Lab Matrix[3:1] -> Tone Curve as well.
static
{
return NULL;
}
cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 1, 3, PickLstarMatrix, NULL));
}
else {
}
return Lut;
}
static
{
int i, j;
return NULL;
return NULL;
// XYZ PCS in encoded in 1.15 format, and the matrix input should come in 0..0xffff range, so
// we need to adjust the input by a << 1 to obtain a 1.16 fixed and then by a factor of
// (0xffff/0x10000) to put data in 0..0xffff range. Total factor is (2.0*65535.0)/65536.0;
for (i=0; i < 3; i++)
for (j=0; j < 3; j++)
return NULL;
return NULL;
}
// Note that it is certainly possible a single profile would have a LUT based
// tag for output working in lab and a matrix-shaper for the fallback cases.
// This is not allowed by the spec, but this code is tolerant to those cases
}
cmsPipelineInsertStage(Lut, cmsAT_END, cmsStageAllocMatrix(ContextID, 3, 3, (cmsFloat64Number*) &Inv, NULL));
}
return Lut;
}
// Change CLUT interpolation to trilinear
static
{
}
}
}
// Read the DToAX tag, adjusting the encoding of Lab or XYZ if neded
/*static
cmsPipeline* _cmsReadFloatOutputTag(cmsHPROFILE hProfile, cmsTagSignature tagFloat)
{
cmsContext ContextID = cmsGetProfileContextID(hProfile);
cmsPipeline* Lut = cmsPipelineDup((cmsPipeline*) cmsReadTag(hProfile, tagFloat));
cmsColorSpaceSignature PCS = cmsGetPCS(hProfile);
if (Lut == NULL) return NULL;
// If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding,
// and since the formatter has already accomodated to 0..1.0, we should undo this change
if ( PCS == cmsSigLabData)
{
cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToLabFloat(ContextID));
}
else
if (PCS == cmsSigXYZData)
{
cmsPipelineInsertStage(Lut, cmsAT_BEGIN, _cmsStageNormalizeToXyzFloat(ContextID));
}
return Lut;
}*/
static
{
// If PCS is Lab or XYZ, the floating point tag is accepting data in the space encoding,
// and since the formatter has already accomodated to 0..1.0, we should undo this change
if ( PCS == cmsSigLabData)
{
}
else
if (PCS == cmsSigXYZData)
{
}
// the output can be Lab or XYZ, in which case normalisation is needed on the end of the pipeline
if ( dataSpace == cmsSigLabData)
{
}
else if ( dataSpace == cmsSigXYZData)
{
}
return Lut;
}
// Create an output MPE LUT from agiven profile. Version mismatches are handled here
{
// Floating point LUT are always V4
}
// Revert to perceptual if no tag is found
tag16 = PCS2Device16[0];
}
// Check profile version and LUT type. Do the necessary adjustments if needed
// First read the tag
// After reading it, we have info about the original type
// The profile owns the Lut, so we need to copy it
// Now it is time for a controversial stuff. I found that for 3D LUTS using
// Lab used as indexer space, trilinear interpolation should be used
// We need to adjust data only for Lab and Lut16 type
return Lut;
// Add a matrix for conversion V4 to V2 Lab PCS
// If the output is Lab, add also a conversion at the end
return Lut;
}
// Lut not found, try to create a matrix-shaper
// Check if this is a grayscale profile.
// if so, build appropiate conversion tables.
// The tables are the PCS iluminant, scaled across GrayTRC
return BuildGrayOutputPipeline(hProfile);
}
// Not gray, create a normal matrix-shaper, which only operates in XYZ space
return BuildRGBOutputMatrixShaper(hProfile);
}
// ---------------------------------------------------------------------------------------------------------------
// Read the AToD0 tag, adjusting the encoding of Lab or XYZ if neded
static
{
if (spc == cmsSigLabData)
{
}
else
if (spc == cmsSigXYZData)
{
}
if (PCS == cmsSigLabData)
{
}
else
if (PCS == cmsSigXYZData)
{
}
return Lut;
}
// This one includes abstract profiles as well. Matrix-shaper cannot be obtained on that device class. The
// tag name here may default to AToB0
{
// On named color, take the appropiate tag
return NULL;
}
return Lut;
}
// Floating point LUT are always V
}
tagFloat = Device2PCSFloat[0];
}
tag16 = Device2PCS16[0];
}
// Check profile version and LUT type. Do the necessary adjustments if needed
// Read the tag
// The profile owns the Lut, so we need to copy it
// Now it is time for a controversial stuff. I found that for 3D LUTS using
// Lab used as indexer space, trilinear interpolation should be used
// After reading it, we have info about the original type
// We need to adjust data for Lab16 on output
// Here it is possible to get Lab on both sides
}
}
return Lut;
}
// ---------------------------------------------------------------------------------------------------------------
// Returns TRUE if the profile is implemented as matrix-shaper
{
switch (cmsGetColorSpace(hProfile)) {
case cmsSigGrayData:
case cmsSigRgbData:
default:
return FALSE;
}
}
// Returns TRUE if the intent is implemented as CLUT
cmsBool CMSEXPORT cmsIsCLUT(cmsHPROFILE hProfile, cmsUInt32Number Intent, cmsUInt32Number UsedDirection)
{
// For devicelinks, the supported intent is that one stated in the header
}
switch (UsedDirection) {
// For proofing, we need rel. colorimetric in output. Let's do some recursion
case LCMS_USED_AS_PROOF:
default:
cmsSignalError(cmsGetProfileContextID(hProfile), cmsERROR_RANGE, "Unexpected direction (%d)", UsedDirection);
return FALSE;
}
}
// Return info about supported intents
{
// Is there any matrix-shaper? If so, the intent is supported. This is a bit odd, since V2 matrix shaper
// does not fully support relative colorimetric because they cannot deal with non-zero black points, but
// many profiles claims that, and this is certainly not true for V4 profiles. Lets answer "yes" no matter
// the accuracy would be less than optimal in rel.col and v2 case.
return cmsIsMatrixShaper(hProfile);
}
// ---------------------------------------------------------------------------------------------------------------
// Read both, profile sequence description and profile sequence id if present. Then combine both to
// create qa unique structure holding both. Shame on ICC to store things in such complicated way.
{
// Take profile sequence description first
// Take profile sequence ID
// We have to mix both together. For that they must agree
// Ok, proceed to the mixing
for (i=0; i < ProfileSeq ->n; i++) {
}
}
return NewSeq;
}
// Dump the contents of profile sequence in both tags (if v4 available)
{
}
return TRUE;
}
// Auxiliar, read and duplicate a MLU if found.
static
{
}
// Create a sequence description out of an array of profiles
cmsSEQ* _cmsCompileProfileSequence(cmsContext ContextID, cmsUInt32Number nProfiles, cmsHPROFILE hProfiles[])
{
for (i=0; i < nProfiles; i++) {
cmsHPROFILE h = hProfiles[i];
else
}
return seq;
}
// -------------------------------------------------------------------------------------------------------------------
static
{
switch (Info) {
case cmsInfoDescription:
break;
case cmsInfoManufacturer:
break;
case cmsInfoModel:
break;
case cmsInfoCopyright:
break;
default: return NULL;
}
}
{
}
{
}