Esempio n. 1
0
// Compute K -> L* relationship. Flags may include black point compensation. In this case, 
// the relationship is assumed from the profile with BPC to a black point zero.
static
LPGAMMATABLE ComputeKToLstar(cmsHPROFILE hProfile, int nPoints, int Intent, DWORD dwFlags)
{
    LPGAMMATABLE out;   
    int i;
    WORD cmyk[4], wLab[3];
    cmsHPROFILE   hLab  = cmsCreateLabProfile(NULL);
    cmsHTRANSFORM xform = cmsCreateTransform(hProfile, TYPE_CMYK_16,
                                             hLab, TYPE_Lab_16, 
                                             Intent, (dwFlags|cmsFLAGS_NOTPRECALC));


    out = cmsAllocGamma(nPoints);
    for (i=0; i < nPoints; i++) {

        cmyk[0] = 0;
        cmyk[1] = 0;
        cmyk[2] = 0;
        cmyk[3] = _cmsQuantizeVal(i, nPoints);

        cmsDoTransform(xform, cmyk, wLab, 1);
        out->GammaTable[i] = (WORD) (0xFFFF - wLab[0]);
    }

    cmsDeleteTransform(xform);
    cmsCloseProfile(hLab);

    return out;
}
Esempio n. 2
0
// Does create a linear ramp
static
LPGAMMATABLE CreateLinear()
{
	LPGAMMATABLE Gamma = cmsAllocGamma(4096);
	LPWORD Table = Gamma ->GammaTable;
	int i;

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

		   Table[i] = _cmsQuantizeVal(i, 4096);              		   

       }
       return Gamma;
}
LPGAMMATABLE
f_cms_gamma_table_new (unsigned short data[], int start, int length)
{
	LPGAMMATABLE table = cmsAllocGamma (length);
	int i;
	if (!table)
		return NULL;

	data += start;

	for (i = 0; i < length; i++)
		table->GammaTable [i] = data [i];

	g_warning ("table %p, count = %d v[0] = %d", table, table->nEntries, table->GammaTable [0]);
	
	return table;
}
Esempio n. 4
0
static
void CreateLabPrelinearization(LPGAMMATABLE LabTable[])
{
    int i;

    LabTable[0] = cmsAllocGamma(257);
    LabTable[1] = cmsBuildGamma(257, 1.0);
    LabTable[2] = cmsBuildGamma(257, 1.0);

    // L* uses 257 entries. Entry 256 holds 0xFFFF, so, the effective range
    // is 0..0xFF00. Last entry (257) is also collapsed to 0xFFFF

    // From 0 to 0xFF00
    for (i=0; i < 256; i++) 
        LabTable[0]->GammaTable[i] = RGB_8_TO_16(i);

    // Repeat last for 0xFFFF
    LabTable[0] ->GammaTable[256] = 0xFFFF;        
}
Esempio n. 5
0
cmsHPROFILE LCMSEXPORT cmsCreateNULLProfile(void)
{
        cmsHPROFILE hProfile;        
        LPLUT Lut;
        LPGAMMATABLE EmptyTab;

        hProfile = _cmsCreateProfilePlaceholder();
        if (!hProfile)                          // can't allocate
                return NULL;
      
        cmsSetDeviceClass(hProfile, icSigOutputClass);
        cmsSetColorSpace(hProfile,  icSigGrayData);
        cmsSetPCS(hProfile,         icSigLabData);
        

       // An empty LUTs is all we need
       Lut = cmsAllocLUT();
       if (Lut == NULL) {
           cmsCloseProfile(hProfile);
           return NULL;
           }

       Lut -> InputChan = 3;
       Lut -> OutputChan = 1;

       EmptyTab = cmsAllocGamma(2);
       EmptyTab ->GammaTable[0] = 0;
       EmptyTab ->GammaTable[1] = 0;

       cmsAllocLinearTable(Lut, &EmptyTab, 2);
        
       cmsAddTag(hProfile, icSigBToA0Tag, (LPVOID) Lut);
    
       cmsFreeLUT(Lut);
       cmsFreeGamma(EmptyTab);
       
       return hProfile;
}
Esempio n. 6
0
static
cmsHPROFILE GetTIFFProfile(TIFF* in)
{    
    cmsCIExyYTRIPLE Primaries;
	float* chr;
    cmsCIExyY WhitePoint;
    float* wp;
    int i;       
    LPGAMMATABLE Gamma[3]; 
    LPWORD gmr, gmg, gmb;
    cmsHPROFILE hProfile;
    DWORD EmbedLen;
    LPBYTE EmbedBuffer;
      
              
       if (IgnoreEmbedded) return NULL;

       if (TIFFGetField(in, TIFFTAG_ICCPROFILE, &EmbedLen, &EmbedBuffer)) {

              hProfile = cmsOpenProfileFromMem(EmbedBuffer, EmbedLen);
   
              if (Verbose) {

                  fprintf(stdout, " (Embedded profile found)\n");
                  fprintf(stdout, "Product name: %s\n", cmsTakeProductName(hProfile));
                  fprintf(stdout, "Description : %s\n", cmsTakeProductDesc(hProfile));                          
                  fflush(stdout);
              }

              if (hProfile != NULL && SaveEmbedded != NULL)
                  SaveMemoryBlock(EmbedBuffer, EmbedLen, SaveEmbedded);

              if (hProfile) return hProfile;
       }

        // Try to see if "colorimetric" tiff

       if (TIFFGetField(in, TIFFTAG_PRIMARYCHROMATICITIES, &chr)) {
                      
           Primaries.Red.x   =  chr[0];
           Primaries.Red.y   =  chr[1];
           Primaries.Green.x =  chr[2];
           Primaries.Green.y =  chr[3];
           Primaries.Blue.x  =  chr[4];
           Primaries.Blue.y  =  chr[5];
           
           Primaries.Red.Y = Primaries.Green.Y = Primaries.Blue.Y = 1.0;
                      
           if (TIFFGetField(in, TIFFTAG_WHITEPOINT, &wp)) {
               
               WhitePoint.x = wp[0];
               WhitePoint.y = wp[1];
               WhitePoint.Y = 1.0;
                                             
               // Transferfunction is a bit harder....
               
               for (i=0; i < 3; i++)
                   Gamma[i] = cmsAllocGamma(256);
                                            
               TIFFGetFieldDefaulted(in, TIFFTAG_TRANSFERFUNCTION,
                   &gmr, 
                   &gmg,
                   &gmb);
               
               CopyMemory(Gamma[0]->GammaTable, gmr, 256*sizeof(WORD));
               CopyMemory(Gamma[1]->GammaTable, gmg, 256*sizeof(WORD));
               CopyMemory(Gamma[2]->GammaTable, gmb, 256*sizeof(WORD));
               
               hProfile = cmsCreateRGBProfile(&WhitePoint, &Primaries, Gamma);
               
               for (i=0; i < 3; i++)
                   cmsFreeGamma(Gamma[i]);

                if (Verbose) {
                  fprintf(stdout, " (Colorimetric TIFF)\n");
                }
             
               
               return hProfile;
           }
       }

       return NULL;
}
Esempio n. 7
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]);

    
}