< prev index next >

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

Print this page

 312 
 313             memmove(&p ->Segments[i], &Segments[i], sizeof(cmsCurveSegment));
 314 
 315             if (Segments[i].Type == 0 && Segments[i].SampledPoints != NULL)
 316                 p ->Segments[i].SampledPoints = (cmsFloat32Number*) _cmsDupMem(ContextID, Segments[i].SampledPoints, sizeof(cmsFloat32Number) * Segments[i].nGridPoints);
 317             else
 318                 p ->Segments[i].SampledPoints = NULL;
 319 
 320 
 321             c = GetParametricCurveByType(ContextID, Segments[i].Type, NULL);
 322             if (c != NULL)
 323                     p ->Evals[i] = c ->Evaluator;
 324         }
 325     }
 326 
 327     p ->InterpParams = _cmsComputeInterpParams(ContextID, p ->nEntries, 1, 1, p->Table16, CMS_LERP_FLAGS_16BITS);
 328     if (p->InterpParams != NULL)
 329         return p;
 330 
 331 Error:




 332     if (p -> SegInterp) _cmsFree(ContextID, p -> SegInterp);
 333     if (p -> Segments) _cmsFree(ContextID, p -> Segments);
 334     if (p -> Evals) _cmsFree(ContextID, p -> Evals);
 335     if (p ->Table16) _cmsFree(ContextID, p ->Table16);
 336     _cmsFree(ContextID, p);
 337     return NULL;
 338 }
 339 
 340 
 341 // Generates a sigmoidal function with desired steepness.
 342 cmsINLINE double sigmoid_base(double k, double t)
 343 {
 344     return (1.0 / (1.0 + exp(-k * t))) - 0.5;
 345 }
 346 
 347 cmsINLINE double inverted_sigmoid_base(double k, double t)
 348 {
 349     return -log((1.0 / (t + 0.5)) - 1.0) / k;
 350 }
 351 

 605             }
 606         }
 607         else {
 608             if (fabs(Params[3]) < MATRIX_DET_TOLERANCE)
 609                 Val = 0;
 610             else
 611                 Val = (R - Params[6]) / Params[3];
 612         }
 613 
 614     }
 615     break;
 616 
 617 
 618     // Types 6,7,8 comes from segmented curves as described in ICCSpecRevision_02_11_06_Float.pdf
 619     // Type 6 is basically identical to type 5 without d
 620 
 621     // Y = (a * X + b) ^ Gamma + c
 622     case 6:
 623         e = Params[1]*R + Params[2];
 624 
 625         if (e < 0)
 626             Val = Params[3];
 627         else
 628             Val = pow(e, Params[0]) + Params[3];






 629         break;
 630 
 631     // ((Y - c) ^1/Gamma - b) / a
 632     case -6:
 633     {
 634         if (fabs(Params[0]) < MATRIX_DET_TOLERANCE ||
 635             fabs(Params[1]) < MATRIX_DET_TOLERANCE)
 636         {
 637             Val = 0;
 638         }
 639         else
 640         {
 641             e = R - Params[3];
 642             if (e < 0)
 643                 Val = 0;
 644             else
 645                 Val = (pow(e, 1.0 / Params[0]) - Params[2]) / Params[1];
 646         }
 647     }
 648     break;

1503 
1504             gamma = log(y) / log(x);
1505             sum  += gamma;
1506             sum2 += gamma * gamma;
1507             n++;
1508         }
1509     }
1510 
1511     // We need enough valid samples
1512     if (n <= 1) return -1.0;
1513 
1514     // Take a look on SD to see if gamma isn't exponential at all
1515     Std = sqrt((n * sum2 - sum * sum) / (n*(n-1)));
1516 
1517     if (Std > Precision)
1518         return -1.0;
1519 
1520     return (sum / n);   // The mean
1521 }
1522 

1523 
1524 // Retrieve parameters on one-segment tone curves
1525 
1526 cmsFloat64Number* CMSEXPORT cmsGetToneCurveParams(const cmsToneCurve* t)
1527 {
1528     _cmsAssert(t != NULL);
1529 
1530     if (t->nSegments != 1) return NULL;
1531     return t->Segments[0].Params;
1532 }


 312 
 313             memmove(&p ->Segments[i], &Segments[i], sizeof(cmsCurveSegment));
 314 
 315             if (Segments[i].Type == 0 && Segments[i].SampledPoints != NULL)
 316                 p ->Segments[i].SampledPoints = (cmsFloat32Number*) _cmsDupMem(ContextID, Segments[i].SampledPoints, sizeof(cmsFloat32Number) * Segments[i].nGridPoints);
 317             else
 318                 p ->Segments[i].SampledPoints = NULL;
 319 
 320 
 321             c = GetParametricCurveByType(ContextID, Segments[i].Type, NULL);
 322             if (c != NULL)
 323                     p ->Evals[i] = c ->Evaluator;
 324         }
 325     }
 326 
 327     p ->InterpParams = _cmsComputeInterpParams(ContextID, p ->nEntries, 1, 1, p->Table16, CMS_LERP_FLAGS_16BITS);
 328     if (p->InterpParams != NULL)
 329         return p;
 330 
 331 Error:
 332     for (i=0; i < nSegments; i++) {
 333         if (p ->Segments && p ->Segments[i].SampledPoints) _cmsFree(ContextID, p ->Segments[i].SampledPoints);
 334         if (p ->SegInterp && p ->SegInterp[i]) _cmsFree(ContextID, p ->SegInterp[i]);
 335     }
 336     if (p -> SegInterp) _cmsFree(ContextID, p -> SegInterp);
 337     if (p -> Segments) _cmsFree(ContextID, p -> Segments);
 338     if (p -> Evals) _cmsFree(ContextID, p -> Evals);
 339     if (p ->Table16) _cmsFree(ContextID, p ->Table16);
 340     _cmsFree(ContextID, p);
 341     return NULL;
 342 }
 343 
 344 
 345 // Generates a sigmoidal function with desired steepness.
 346 cmsINLINE double sigmoid_base(double k, double t)
 347 {
 348     return (1.0 / (1.0 + exp(-k * t))) - 0.5;
 349 }
 350 
 351 cmsINLINE double inverted_sigmoid_base(double k, double t)
 352 {
 353     return -log((1.0 / (t + 0.5)) - 1.0) / k;
 354 }
 355 

 609             }
 610         }
 611         else {
 612             if (fabs(Params[3]) < MATRIX_DET_TOLERANCE)
 613                 Val = 0;
 614             else
 615                 Val = (R - Params[6]) / Params[3];
 616         }
 617 
 618     }
 619     break;
 620 
 621 
 622     // Types 6,7,8 comes from segmented curves as described in ICCSpecRevision_02_11_06_Float.pdf
 623     // Type 6 is basically identical to type 5 without d
 624 
 625     // Y = (a * X + b) ^ Gamma + c
 626     case 6:
 627         e = Params[1]*R + Params[2];
 628 
 629         // On gamma 1.0, don't clamp
 630         if (Params[0] == 1.0) {
 631             Val = e + Params[3];
 632         }
 633         else {
 634             if (e < 0)
 635                 Val = Params[3];
 636             else
 637                 Val = pow(e, Params[0]) + Params[3];
 638         }
 639         break;
 640 
 641     // ((Y - c) ^1/Gamma - b) / a
 642     case -6:
 643     {
 644         if (fabs(Params[0]) < MATRIX_DET_TOLERANCE ||
 645             fabs(Params[1]) < MATRIX_DET_TOLERANCE)
 646         {
 647             Val = 0;
 648         }
 649         else
 650         {
 651             e = R - Params[3];
 652             if (e < 0)
 653                 Val = 0;
 654             else
 655                 Val = (pow(e, 1.0 / Params[0]) - Params[2]) / Params[1];
 656         }
 657     }
 658     break;

1513 
1514             gamma = log(y) / log(x);
1515             sum  += gamma;
1516             sum2 += gamma * gamma;
1517             n++;
1518         }
1519     }
1520 
1521     // We need enough valid samples
1522     if (n <= 1) return -1.0;
1523 
1524     // Take a look on SD to see if gamma isn't exponential at all
1525     Std = sqrt((n * sum2 - sum * sum) / (n*(n-1)));
1526 
1527     if (Std > Precision)
1528         return -1.0;
1529 
1530     return (sum / n);   // The mean
1531 }
1532 
1533 // Retrieve segments on tone curves
1534 
1535 const cmsCurveSegment* CMSEXPORT cmsGetToneCurveSegment(cmsInt32Number n, const cmsToneCurve* t)


1536 {
1537     _cmsAssert(t != NULL);
1538 
1539     if (n < 0 || n >= (cmsInt32Number) t->nSegments) return NULL;
1540     return t->Segments + n;
1541 }
1542 
< prev index next >