home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 21 / macformat_21.iso / Shareware / Programación / VideoToolbox / VideoToolboxSources / VLambda.c < prev    next >
Text File  |  1995-07-19  |  5KB  |  145 lines

  1. /*
  2. VLambda.c
  3.  
  4. VLambda(double nm) returns the photopic sensitivity of the standard
  5. CIE observer, relative to the peak at 555 nm.
  6.  
  7. VLambdaPrime(double nm) returns the scotopic sensitivity of the standard
  8. CIE observer, relative to the peak at 507 nm.
  9.  
  10. Both are based on the Wyszecki and Stiles tables. Intermediate values
  11. are interpolated geometrically. Sensitivity at wavelengths outside
  12. the range covered by the tables is assumed to be zero.
  13.  
  14. Based on Tables I(3.3.1) and I(4.3.2) in G. Wyszecki and W.S. Stiles (1982) 
  15. Color Science, 2nd Ed., Wiley, New York.
  16.  
  17. HISTORY:
  18. 1990    dgp wrote it.
  19. 10/23/92 dgp sped it up by taking the log only once, the first time it's called.
  20. 12/13/92 dgp cosmetic editing of the code.
  21. 5/27/95 dgp extracted the interpolation code into a generic subroutine
  22. */
  23. #include "VideoToolbox.h"
  24. #if !MAC_C
  25.     #define Boolean unsigned char
  26. #endif
  27. typedef struct{
  28.     double *f,firstX,lastX,dx;
  29.     int n;
  30.     Boolean convertedToLog;
  31. }TabulatedFunction;
  32.  
  33. /* this subroutine is used only within this file */
  34. double InterpolateTableGeometrically(double x,TabulatedFunction *s);
  35.  
  36. double InterpolateTableGeometrically(register double x,register TabulatedFunction *s)
  37. {
  38.     register double a;
  39.     register int i;
  40.  
  41.     if(!s->convertedToLog){
  42.         assert(s->n==1+(s->lastX-s->firstX)/s->dx);
  43.         for(i=0;i<s->n;i++)s->f[i]=log(s->f[i]);
  44.         s->convertedToLog=1;
  45.     }
  46.     a=(x-s->firstX)/s->dx;
  47.     i=a;    /* integer part */
  48.     a-=i;    /* fractional part */
  49.     if(i==s->n-1 && a==0.0)return exp(s->f[s->n-1]);
  50.     if(i<0 || i>=s->n-1)return 0.0;
  51.     return exp(s->f[i]+(s->f[i+1]-s->f[i])*a);    /* geometric interpolation */
  52. }
  53.  
  54. double VLambda(double nm)
  55. {
  56.     /* at 5 nm intervals, from Table I(3.3.1) page 725,
  57.     G. Wyszecki and W.S.Stiles (1982) Color Science,
  58.     2nd Ed., Wiley, New York. 
  59.     */
  60.     static double V[]={ 
  61.         0.00000391700, 0.00000696500, 0.00001239000, 0.00002202000, 
  62.         0.00003900000, 0.00006400000, 0.00012000000, 0.00021700000, 
  63.         0.00039600000, 0.00064000000, 0.00121000000, 0.00218000000, 
  64.         0.00400000000, 0.00730000000, 0.01160000000, 0.01684000000, 
  65.         0.02300000000, 0.02980000000, 0.03800000000, 0.04800000000, 
  66.         0.06000000000, 0.07390000000, 0.09098000000, 0.11260000000, 
  67.         0.13902000000, 0.16930000000, 0.20802000000, 0.25860000000, 
  68.         0.32300000000, 0.40730000000, 0.50300000000, 0.60820000000, 
  69.         0.71000000000, 0.79320000000, 0.86200000000, 0.91485010000, 
  70.         0.95400000000, 0.98030000000, 0.99495010000, 1.00000000000, 
  71.         0.99500000000, 0.97860000000, 0.95200000000, 0.91540000000, 
  72.         0.87000000000, 0.81630000000, 0.75700000000, 0.69490000000, 
  73.         0.63100000000, 0.56680000000, 0.50300000000, 0.44120000000, 
  74.         0.38100000000, 0.32100000000, 0.26500000000, 0.21700000000, 
  75.         0.17500000000, 0.13820000000, 0.10700000000, 0.08160000000, 
  76.         0.06100000000, 0.04458000000, 0.03200000000, 0.02320000000, 
  77.         0.01700000000, 0.01192000000, 0.00821000000, 0.00572300000, 
  78.         0.00410200000, 0.00292900000, 0.00209100000, 0.00148400000, 
  79.         0.00104700000, 0.00074000000, 0.00052000000, 0.00036110000, 
  80.         0.00024920000, 0.00017190000, 0.00012000000, 0.00008480000, 
  81.         0.00006000000, 0.00004240000, 0.00003000000, 0.00002120000, 
  82.         0.00001499000, 0.00001060000, 0.00000746570, 0.00000525780, 
  83.         0.00000370290, 0.00000260780, 0.00000183660, 0.00000129340, 
  84.         0.00000091093, 0.00000064153, 0.00000045181
  85.     };
  86.     static TabulatedFunction s;
  87.     static Boolean firstTime=1;    
  88.  
  89.     if(firstTime){
  90.         s.f=V;
  91.         s.firstX=360.;
  92.         s.lastX=830.;
  93.         s.dx=5.;
  94.         s.n=sizeof(V)/sizeof(V[0]);
  95.         s.convertedToLog=0;
  96.         firstTime=0;
  97.     }
  98.     return InterpolateTableGeometrically(nm,&s);
  99. }
  100.  
  101. double VLambdaPrime(double nm)
  102. {
  103.     /*
  104.     At 5 nm intervals, from Table I(4.3.2) page 789,
  105.     G. Wyszecki and W.S.Stiles (1982) Color Science,
  106.     2nd Ed., Wiley, New York
  107.     */
  108.     static double V[]={
  109.         0.0005890000, 0.0011080000, 0.0022090000, 0.0045300000, 
  110.         0.0092900000, 0.0185200000, 0.0348400000, 0.0604000000, 
  111.         0.0966000000, 0.1436000000, 0.1998000000, 0.2625000000, 
  112.         0.3281000000, 0.3931000000, 0.4550000000, 0.5130000000, 
  113.         0.5670000000, 0.6200000000, 0.6760000000, 0.7340000000, 
  114.         0.7930000000, 0.8510000000, 0.9040000000, 0.9490000000, 
  115.         0.9820000000, 0.9980000000, 0.9970000000, 0.9750000000, 
  116.         0.9350000000, 0.8800000000, 0.8110000000, 0.7330000000, 
  117.         0.6500000000, 0.5640000000, 0.4810000000, 0.4020000000, 
  118.         0.3288000000, 0.2639000000, 0.2076000000, 0.1602000000, 
  119.         0.1212000000, 0.0899000000, 0.0655000000, 0.0469000000, 
  120.         0.0331500000, 0.0231200000, 0.0159300000, 0.0108800000, 
  121.         0.0073700000, 0.0049700000, 0.0033350000, 0.0022350000, 
  122.         0.0014970000, 0.0010050000, 0.0006770000, 0.0004590000, 
  123.         0.0003129000, 0.0002146000, 0.0001480000, 0.0001026000, 
  124.         0.0000715000, 0.0000501000, 0.0000353300, 0.0000250100, 
  125.         0.0000178000, 0.0000127300, 0.0000091400, 0.0000066000, 
  126.         0.0000047800, 0.0000034820, 0.0000025460, 0.0000018700, 
  127.         0.0000013790, 0.0000010220, 0.0000007600, 0.0000005670, 
  128.         0.0000004250, 0.0000003196, 0.0000002413, 0.0000001829, 
  129.         0.0000001390
  130.     };
  131.     static TabulatedFunction s;
  132.     static Boolean firstTime=1;    
  133.  
  134.     if(firstTime){
  135.         s.f=V;
  136.         s.firstX=380.;
  137.         s.lastX=780.;
  138.         s.dx=5.;
  139.         s.n=sizeof(V)/sizeof(V[0]);
  140.         s.convertedToLog=0;
  141.         firstTime=0;
  142.     }
  143.     return InterpolateTableGeometrically(nm,&s);
  144. }
  145.