< prev index next >

src/java.desktop/share/native/liblcms/cmslut.c

Print this page

 487 
 488 // Given an hypercube of b dimensions, with Dims[] number of nodes by dimension, calculate the total amount of nodes
 489 static
 490 cmsUInt32Number CubeSize(const cmsUInt32Number Dims[], cmsUInt32Number b)
 491 {
 492     cmsUInt32Number rv, dim;
 493 
 494     _cmsAssert(Dims != NULL);
 495 
 496     for (rv = 1; b > 0; b--) {
 497 
 498         dim = Dims[b-1];
 499         if (dim <= 1) return 0;  // Error
 500 
 501         rv *= dim;
 502 
 503         // Check for overflow
 504         if (rv > UINT_MAX / dim) return 0;
 505     }
 506 



 507     return rv;
 508 }
 509 
 510 static
 511 void* CLUTElemDup(cmsStage* mpe)
 512 {
 513     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
 514     _cmsStageCLutData* NewElem;
 515 
 516 
 517     NewElem = (_cmsStageCLutData*) _cmsMallocZero(mpe ->ContextID, sizeof(_cmsStageCLutData));
 518     if (NewElem == NULL) return NULL;
 519 
 520     NewElem ->nEntries       = Data ->nEntries;
 521     NewElem ->HasFloatValues = Data ->HasFloatValues;
 522 
 523     if (Data ->Tab.T) {
 524 
 525         if (Data ->HasFloatValues) {
 526             NewElem ->Tab.TFloat = (cmsFloat32Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.TFloat, Data ->nEntries * sizeof (cmsFloat32Number));

 826             if (clut ->Tab.T != NULL) {
 827                 for (t=0; t < (int) nOutputs; t++)
 828                     clut->Tab.T[index + t] = Out[t];
 829             }
 830         }
 831 
 832         index += nOutputs;
 833     }
 834 
 835     return TRUE;
 836 }
 837 
 838 // Same as anterior, but for floating point
 839 cmsBool CMSEXPORT cmsStageSampleCLutFloat(cmsStage* mpe, cmsSAMPLERFLOAT Sampler, void * Cargo, cmsUInt32Number dwFlags)
 840 {
 841     int i, t, index, rest;
 842     cmsUInt32Number nTotalPoints;
 843     cmsUInt32Number nInputs, nOutputs;
 844     cmsUInt32Number* nSamples;
 845     cmsFloat32Number In[MAX_INPUT_DIMENSIONS+1], Out[MAX_STAGE_CHANNELS];
 846     _cmsStageCLutData* clut = (_cmsStageCLutData*) mpe->Data;






 847 
 848     nSamples = clut->Params ->nSamples;
 849     nInputs  = clut->Params ->nInputs;
 850     nOutputs = clut->Params ->nOutputs;
 851 
 852     if (nInputs <= 0) return FALSE;
 853     if (nOutputs <= 0) return FALSE;
 854     if (nInputs  > MAX_INPUT_DIMENSIONS) return FALSE;
 855     if (nOutputs >= MAX_STAGE_CHANNELS) return FALSE;
 856 
 857     nTotalPoints = CubeSize(nSamples, nInputs);
 858     if (nTotalPoints == 0) return FALSE;
 859 
 860     index = 0;
 861     for (i = 0; i < (int)nTotalPoints; i++) {
 862 
 863         rest = i;
 864         for (t = (int) nInputs-1; t >=0; --t) {
 865 
 866             cmsUInt32Number  Colorant = rest % nSamples[t];

 487 
 488 // Given an hypercube of b dimensions, with Dims[] number of nodes by dimension, calculate the total amount of nodes
 489 static
 490 cmsUInt32Number CubeSize(const cmsUInt32Number Dims[], cmsUInt32Number b)
 491 {
 492     cmsUInt32Number rv, dim;
 493 
 494     _cmsAssert(Dims != NULL);
 495 
 496     for (rv = 1; b > 0; b--) {
 497 
 498         dim = Dims[b-1];
 499         if (dim <= 1) return 0;  // Error
 500 
 501         rv *= dim;
 502 
 503         // Check for overflow
 504         if (rv > UINT_MAX / dim) return 0;
 505     }
 506 
 507     // Again, prevent overflow
 508     if (rv > UINT_MAX / 15) return 0;
 509 
 510     return rv;
 511 }
 512 
 513 static
 514 void* CLUTElemDup(cmsStage* mpe)
 515 {
 516     _cmsStageCLutData* Data = (_cmsStageCLutData*) mpe ->Data;
 517     _cmsStageCLutData* NewElem;
 518 
 519 
 520     NewElem = (_cmsStageCLutData*) _cmsMallocZero(mpe ->ContextID, sizeof(_cmsStageCLutData));
 521     if (NewElem == NULL) return NULL;
 522 
 523     NewElem ->nEntries       = Data ->nEntries;
 524     NewElem ->HasFloatValues = Data ->HasFloatValues;
 525 
 526     if (Data ->Tab.T) {
 527 
 528         if (Data ->HasFloatValues) {
 529             NewElem ->Tab.TFloat = (cmsFloat32Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.TFloat, Data ->nEntries * sizeof (cmsFloat32Number));

 829             if (clut ->Tab.T != NULL) {
 830                 for (t=0; t < (int) nOutputs; t++)
 831                     clut->Tab.T[index + t] = Out[t];
 832             }
 833         }
 834 
 835         index += nOutputs;
 836     }
 837 
 838     return TRUE;
 839 }
 840 
 841 // Same as anterior, but for floating point
 842 cmsBool CMSEXPORT cmsStageSampleCLutFloat(cmsStage* mpe, cmsSAMPLERFLOAT Sampler, void * Cargo, cmsUInt32Number dwFlags)
 843 {
 844     int i, t, index, rest;
 845     cmsUInt32Number nTotalPoints;
 846     cmsUInt32Number nInputs, nOutputs;
 847     cmsUInt32Number* nSamples;
 848     cmsFloat32Number In[MAX_INPUT_DIMENSIONS+1], Out[MAX_STAGE_CHANNELS];
 849     _cmsStageCLutData* clut;
 850 
 851     if (mpe == NULL) return FALSE;
 852 
 853     clut = (_cmsStageCLutData*)mpe->Data;
 854 
 855     if (clut == NULL) return FALSE;
 856 
 857     nSamples = clut->Params ->nSamples;
 858     nInputs  = clut->Params ->nInputs;
 859     nOutputs = clut->Params ->nOutputs;
 860 
 861     if (nInputs <= 0) return FALSE;
 862     if (nOutputs <= 0) return FALSE;
 863     if (nInputs  > MAX_INPUT_DIMENSIONS) return FALSE;
 864     if (nOutputs >= MAX_STAGE_CHANNELS) return FALSE;
 865 
 866     nTotalPoints = CubeSize(nSamples, nInputs);
 867     if (nTotalPoints == 0) return FALSE;
 868 
 869     index = 0;
 870     for (i = 0; i < (int)nTotalPoints; i++) {
 871 
 872         rest = i;
 873         for (t = (int) nInputs-1; t >=0; --t) {
 874 
 875             cmsUInt32Number  Colorant = rest % nSamples[t];
< prev index next >