Ejemplo n.º 1
0
LPLUT _cmsComputeSoftProofLUT(cmsHPROFILE hProfile, int nIntent)
{
    cmsHPROFILE hLab;
    LPLUT SoftProof;
    DWORD dwFormat;
    GAMUTCHAIN Chain;
    int nErrState;
    LPGAMMATABLE Trans[3];
        

    // LUTs are never abs. colorimetric, is the transform who
    // is responsible of generating white point displacement
    if (nIntent == INTENT_ABSOLUTE_COLORIMETRIC)
        nIntent = INTENT_RELATIVE_COLORIMETRIC;

    ZeroMemory(&Chain, sizeof(GAMUTCHAIN));

    hLab = cmsCreateLabProfile(NULL);

    // ONLY 4 channels  
    dwFormat = (CHANNELS_SH(4)|BYTES_SH(2));
    
    // Safeguard against early abortion
    nErrState = cmsErrorAction(LCMS_ERROR_IGNORE);

    // Does create the first step
    Chain.hForward = cmsCreateTransform(hLab, TYPE_Lab_16, 
                                        hProfile, dwFormat, 
                                        nIntent,
                                        cmsFLAGS_NOTPRECALC);

    // Does create the last step
    Chain.hReverse = cmsCreateTransform(hProfile, dwFormat, 
                                        hLab, TYPE_Lab_16,                                      
                                        INTENT_RELATIVE_COLORIMETRIC, 
                                        cmsFLAGS_NOTPRECALC);

    // Restores error handler previous state
    cmsErrorAction(nErrState);

    // All ok?
    if (Chain.hForward && Chain.hReverse) {
                
    // This is Lab -> Lab, so 33 point should hold anything
    SoftProof = cmsAllocLUT();
    SoftProof = cmsAlloc3DGrid(SoftProof, 33, 3, 3);

    CreateLabPrelinearization(Trans);
    cmsAllocLinearTable(SoftProof, Trans, 1);
    cmsFreeGammaTriple(Trans);

    cmsSample3DGrid(SoftProof, SoftProofSampler, (LPVOID) &Chain, SoftProof->wFlags);
    }
    else 
        SoftProof = NULL;   // Didn't work...

    // Free all needed stuff.
    if (Chain.hForward) cmsDeleteTransform(Chain.hForward);
    if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse);

    cmsCloseProfile(hLab);

    return SoftProof;
}
Ejemplo n.º 2
0
static
LPLUT ComputeGamutWithInput(cmsHPROFILE hInput, cmsHPROFILE hProfile, int Intent)
{
    cmsHPROFILE hLab;
    LPLUT Gamut;
    DWORD dwFormat;
    GAMUTCHAIN Chain;
    int nErrState, nChannels, nGridpoints;
    LPGAMMATABLE Trans[3];
    icColorSpaceSignature ColorSpace;
            
    
    ZeroMemory(&Chain, sizeof(GAMUTCHAIN)); 
       
    hLab = cmsCreateLabProfile(NULL);
    
    // Safeguard against early abortion
    nErrState = cmsErrorAction(LCMS_ERROR_IGNORE);

    // The figure of merit. On matrix-shaper profiles, should be almost zero as
    // the conversion is pretty exact. On LUT based profiles, different resolutions
    // of input and output CLUT may result in differences. 

    if (!cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_INPUT) &&
        !cmsIsIntentSupported(hProfile, Intent, LCMS_USED_AS_OUTPUT))

        Chain.Thereshold = 1.0;
    else
        Chain.Thereshold = ERR_THERESHOLD;
   
    ColorSpace  = cmsGetColorSpace(hProfile);  

    // If input profile specified, create a transform from such profile to Lab
    if (hInput != NULL) {
          
        nChannels   = _cmsChannelsOf(ColorSpace);     
        nGridpoints = _cmsReasonableGridpointsByColorspace(ColorSpace, cmsFLAGS_HIGHRESPRECALC);
        dwFormat    = (CHANNELS_SH(nChannels)|BYTES_SH(2));

        Chain.hInput = cmsCreateTransform(hInput, dwFormat, 
                                          hLab,   TYPE_Lab_16, 
                                          Intent, 
                                          cmsFLAGS_NOTPRECALC);
    }
    else  {
        // Input transform=NULL (Lab) Used to compute the gamut tag
        // This table will take 53 points to give some accurancy, 
        // 53 * 53 * 53 * 2 = 291K

        nChannels    = 3;      // For Lab
        nGridpoints  = 53;
        Chain.hInput = NULL;
        dwFormat = (CHANNELS_SH(_cmsChannelsOf(ColorSpace))|BYTES_SH(2)); 
    }

   
    // Does create the forward step
    Chain.hForward = cmsCreateTransform(hLab, TYPE_Lab_16, 
                                        hProfile, dwFormat, 
                                        INTENT_RELATIVE_COLORIMETRIC,
                                        cmsFLAGS_NOTPRECALC);

    // Does create the backwards step
    Chain.hReverse = cmsCreateTransform(hProfile, dwFormat, 
                                        hLab, TYPE_Lab_16,                                      
                                        INTENT_RELATIVE_COLORIMETRIC,
                                        cmsFLAGS_NOTPRECALC);

    // Restores error handler previous state
    cmsErrorAction(nErrState);

   
    // All ok?
    if (Chain.hForward && Chain.hReverse) {
           
    // Go on, try to compute gamut LUT from PCS.
    // This consist on a single channel containing 
    // dE when doing a transform back and forth on
    // the colorimetric intent. 

    Gamut = cmsAllocLUT();
    Gamut = cmsAlloc3DGrid(Gamut, nGridpoints, nChannels, 1);
     
    // If no input, then this is a gamut tag operated by Lab,
    // so include pertinent prelinearization
    if (hInput == NULL) {
       
        CreateLabPrelinearization(Trans);               
        cmsAllocLinearTable(Gamut, Trans, 1);              
        cmsFreeGammaTriple(Trans);
    }

   
    cmsSample3DGrid(Gamut, GamutSampler, (LPVOID) &Chain, Gamut ->wFlags);          
    }
    else 
        Gamut = NULL;   // Didn't work...

    // Free all needed stuff.
    if (Chain.hInput)   cmsDeleteTransform(Chain.hInput);
    if (Chain.hForward) cmsDeleteTransform(Chain.hForward);
    if (Chain.hReverse) cmsDeleteTransform(Chain.hReverse);

    cmsCloseProfile(hLab);
    
    // And return computed hull
    return Gamut;
}
Ejemplo n.º 3
0
BOOL cmsxMonitorProfilerDo(LPMONITORPROFILERDATA sys)
{

    cmsCIExyY White;
    LPLUT AToB0, BToA0;

        AToB0 = BToA0 = NULL;

        if (!*sys -> hdr.OutputProfileFile)
                return false;


        if (sys->hdr.ReferenceSheet[0] || sys->hdr.MeasurementSheet[0]) {

                if (sys->hdr.printf) {

                    sys->hdr.printf("Loading sheets...");

                    if (sys->hdr.ReferenceSheet[0])
                        sys->hdr.printf("Reference sheet: %s", sys->hdr.ReferenceSheet);
                    if (sys->hdr.MeasurementSheet[0])
                        sys->hdr.printf("Measurement sheet: %s", sys->hdr.MeasurementSheet);
                }


                if (!cmsxComputeMatrixShaper(sys -> hdr.ReferenceSheet,
                                             sys -> hdr.MeasurementSheet,
                                             MEDIUM_TRANSMISSIVE,
                                             sys -> Prelinearization,
                                             &sys -> hdr.WhitePoint,
                                             &sys -> hdr.BlackPoint,
                                             &sys -> hdr.Primaries)) return false;

                if (sys->hdr.printf) {

                    char Buffer[1024];
                    _cmsIdentifyWhitePoint(Buffer, &sys ->hdr.WhitePoint);
                    sys->hdr.printf("%s", Buffer);

                    sys->hdr.printf("Primaries: R:%1.2g, %1.2g  G:%1.2g, %1.2g  B:%1.2g, %1.2g",
                            sys->hdr.Primaries.Red.x,sys->hdr.Primaries.Red.y,
                            sys->hdr.Primaries.Green.x, sys->hdr.Primaries.Green.y,
                            sys->hdr.Primaries.Blue.x, sys->hdr.Primaries.Blue.y);
                }

        }


        CreatePrimaryMatrices(sys);


        cmsXYZ2xyY(&White, &sys->hdr.WhitePoint);

        sys->hdr.hProfile = cmsCreateRGBProfile(&White,
                                                &sys-> hdr.Primaries,
                                                sys -> Prelinearization);

        cmsSetDeviceClass(sys->hdr.hProfile, sys->hdr.DeviceClass);

        if (sys -> hdr.lUseCIECAM97s)
            sys->hdr.PCSType = PT_Lab;
        else
            sys->hdr.PCSType = PT_XYZ;

        cmsSetPCS(sys->hdr.hProfile,  _cmsICCcolorSpace(sys->hdr.PCSType));

        if (sys -> hdr.lUseCIECAM97s)
                        CreateLUTS(sys, &AToB0, &BToA0);


        cmsxEmbedTextualInfo(&sys ->hdr);

        cmsAddTag(sys->hdr.hProfile, icSigMediaWhitePointTag,  &sys->hdr.WhitePoint);
        cmsAddTag(sys->hdr.hProfile, icSigMediaBlackPointTag, &sys->hdr.BlackPoint);


        if (sys->hdr.ProfileVerbosityLevel >= 2) {

            cmsxEmbedCharTarget(&sys ->hdr);
        }


        _cmsSaveProfile(sys->hdr.hProfile, sys->hdr.OutputProfileFile);
        cmsCloseProfile(sys->hdr.hProfile);
        sys->hdr.hProfile = NULL;


        if (AToB0) cmsFreeLUT(AToB0);
        if (BToA0) cmsFreeLUT(BToA0);

        if (sys ->Prelinearization[0])
            cmsFreeGammaTriple(sys -> Prelinearization);

    return true;
}
Ejemplo n.º 4
0
void _cmsComputePrelinearizationTablesFromXFORM(cmsHTRANSFORM h[], int nTransforms, LPLUT Grid)
{
    LPGAMMATABLE Trans[MAXCHANNELS];
    unsigned int t, i, v;  
    int j;
    WORD In[MAXCHANNELS], Out[MAXCHANNELS];
    BOOL lIsSuitable;
    _LPcmsTRANSFORM InputXForm   = (_LPcmsTRANSFORM) h[0];   
    _LPcmsTRANSFORM OutputXForm  = (_LPcmsTRANSFORM) h[nTransforms-1];   

    
    // First space is *Lab, use our specialized curves for v2 Lab
    
    if (InputXForm ->EntryColorSpace == icSigLabData && 
        OutputXForm->ExitColorSpace != icSigLabData) {
    
                CreateLabPrelinearization(Trans);
                cmsAllocLinearTable(Grid, Trans, 1);
                cmsFreeGammaTriple(Trans);
                return;
    }
              

    // Do nothing on all but RGB to RGB transforms

    if ((InputXForm ->EntryColorSpace != icSigRgbData) || 
        (OutputXForm->ExitColorSpace  != icSigRgbData)) return;
    

    for (t = 0; t < Grid -> InputChan; t++) 
            Trans[t] = cmsAllocGamma(PRELINEARIZATION_POINTS);

    for (i=0; i < PRELINEARIZATION_POINTS; i++) {

                v = _cmsQuantizeVal(i, PRELINEARIZATION_POINTS);

                for (t=0; t < Grid -> InputChan; t++)
                        In[t] = (WORD) v;

                cmsDoTransform(h[0], In, Out, 1);
                for (j=1; j < nTransforms; j++)
                        cmsDoTransform(h[j], Out, Out, 1);

                for (t=0; t < Grid -> InputChan; t++)
                        Trans[t] ->GammaTable[i] = Out[t];

    }
    

    // Check transfer curves
    lIsSuitable = TRUE;
    for (t=0; (lIsSuitable && (t < Grid->InputChan)); t++) {

    
        // Exclude if already linear
        if (MostlyLinear(Trans[t]->GammaTable, PRELINEARIZATION_POINTS))
                    lIsSuitable = FALSE;

        // Exclude if non-monotonic
        if (!IsMonotonic(Trans[t]))
                    lIsSuitable = FALSE;        
        
        // Exclude if weird endpoints
        if (!HasProperEndpoints(Trans[t]))
                    lIsSuitable = FALSE;

        // Exclude if transfer function is not smooth enough
        // to be modelled as a gamma function, or the gamma is reversed
        if (cmsEstimateGamma(Trans[t]) < 1.0)
                    lIsSuitable = FALSE;
              
    }

    if (lIsSuitable) {
    
            for (t = 0; t < Grid ->InputChan; t++) 
                SlopeLimiting(Trans[t]->GammaTable, Trans[t]->nEntries);
    }
      
    if (lIsSuitable) cmsAllocLinearTable(Grid, Trans, 1);


    for (t = 0; t < Grid ->InputChan; t++) 
                        cmsFreeGamma(Trans[t]);

    
}
Ejemplo n.º 5
0
static
BOOL CreateLUTS(LPMONITORPROFILERDATA sys, LPLUT* A2B, LPLUT* B2A)
{
    LPLUT AToB0 = cmsAllocLUT();
    LPLUT BToA0 = cmsAllocLUT();
    LPGAMMATABLE LabG;
    cmsCIExyY xyY;


        cmsAlloc3DGrid(AToB0, sys->hdr.CLUTPoints, 3, 3);
        cmsAlloc3DGrid(BToA0, sys->hdr.CLUTPoints, 3, 3);

        /* cmsAllocLinearTable(AToB0, sys -> Prelinearization, 1);     */

        sys->ReverseTables[0] = cmsReverseGamma(4096, sys ->Prelinearization[0]);
        sys->ReverseTables[1] = cmsReverseGamma(4096, sys ->Prelinearization[1]);
        sys->ReverseTables[2] = cmsReverseGamma(4096, sys ->Prelinearization[2]);

        /* Prelinearization */

        LabG = cmsBuildGamma(4096, 3.0);

        sys -> PreLab[0] = cmsJoinGammaEx(LabG, sys ->Prelinearization[0], 4096);
        sys -> PreLab[1] = cmsJoinGammaEx(LabG, sys ->Prelinearization[1], 4096);
        sys -> PreLab[2] = cmsJoinGammaEx(LabG, sys ->Prelinearization[2], 4096);

        sys -> PreLabRev[0] = cmsJoinGammaEx(sys ->Prelinearization[0], LabG, 4096);
        sys -> PreLabRev[1] = cmsJoinGammaEx(sys ->Prelinearization[1], LabG, 4096);
        sys -> PreLabRev[2] = cmsJoinGammaEx(sys ->Prelinearization[2], LabG, 4096);


        cmsFreeGamma(LabG);


        cmsAllocLinearTable(AToB0, sys->PreLabRev, 1);
        cmsAllocLinearTable(BToA0, sys->PreLab,    2);


        /* Set CIECAM97s parameters */

        sys -> hdr.device.whitePoint.X = sys -> hdr.WhitePoint.X * 100.;
        sys -> hdr.device.whitePoint.Y = sys -> hdr.WhitePoint.Y * 100.;
        sys -> hdr.device.whitePoint.Z = sys -> hdr.WhitePoint.Z * 100.;


        /* Normalize White point for CIECAM97s model */
        cmsXYZ2xyY(&xyY,  &sys -> hdr.device.whitePoint);
        xyY.Y = 100.;
        cmsxyY2XYZ(&sys -> hdr.device.whitePoint, &xyY);


        sys->hdr.hDevice = cmsCIECAM97sInit(&sys->hdr.device);
        sys->hdr.hPCS    = cmsCIECAM97sInit(&sys->hdr.PCS);


        cmsSample3DGrid(AToB0, RegressionSamplerA2B, sys, 0);
        cmsSample3DGrid(BToA0, RegressionSamplerB2A, sys, 0);

        cmsCIECAM97sDone(sys->hdr.hDevice);
        cmsCIECAM97sDone(sys->hdr.hPCS);

       cmsAddTag(sys->hdr.hProfile, icSigAToB0Tag, AToB0);
       cmsAddTag(sys->hdr.hProfile, icSigBToA0Tag, BToA0);

       /* This is the 0xff00 trick to map white at lattice point */
       BToA0 ->Matrix.v[0].n[0] = DOUBLE_TO_FIXED((65535.0 / 65280.0));

       *A2B  = AToB0;
       *B2A  = BToA0;

        cmsFreeGammaTriple(sys->ReverseTables);
        cmsFreeGammaTriple(sys->PreLab);
        cmsFreeGammaTriple(sys->PreLabRev);
        return true;
}