home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / Utilities / TestLuminance / TestLuminance.c next >
Encoding:
C/C++ Source or Header  |  1994-10-17  |  6.0 KB  |  232 lines  |  [TEXT/KAHL]

  1. /*
  2. TestLuminance.c
  3. a simple driver to test some of the functionality of Luminance.c
  4. HISTORY:
  5. 8/15/89 dgp wrote it.
  6. 10/12/90 dgp    updated it.
  7. 10/17/90 dgp    tidied up the timing print out.
  8. 8/24/91    dgp    Made compatible with THINK C 5.0.
  9. 8/27/92    dgp    replace SysEnvirons() by Gestalt()
  10. 12/21/92 dgp don't assume 8-bit dacs.
  11. */
  12. #include "VideoToolbox.h"
  13. #include <math.h>
  14. #include <assert.h>
  15. #include "Luminance.h"
  16. #include <Fonts.h>
  17. #if (THINK_C || THINK_CPLUS)
  18.     #include <console.h>
  19.     #include <profile.h>
  20. #endif
  21.  
  22. void TestLuminance(void);
  23.  
  24. void main(void)
  25. {
  26.     Require(gestalt8BitQD);
  27.     TestLuminance();
  28. }
  29.  
  30. void TestLuminance(void)
  31. {
  32.     register int i;
  33.     static LuminanceRecord LR;
  34.     register double L,V;
  35.     register double dL,dV;
  36.     unsigned long t,reps=100;
  37.     double tolerance;
  38.     double L0,L1;
  39.     int n;
  40.     double c,bits;
  41.     double e[512],mean,sd,max,LGot;
  42.  
  43.     /* Luminance.c includes a recursive routine that requires lots of stack space */
  44.     StackGrow(10000);        /* Increase stack */
  45.     assert(StackSpace()>10000);
  46.     MaxApplZone();            /* Expand heap to the limit. */
  47.  
  48.     #if (THINK_C || THINK_CPLUS)
  49.         console_options.ncols=100;
  50.         printf("\n");
  51.         InitProfile(200,2);
  52.     #else
  53.            /* INITIALIZE QuickDraw */
  54.         InitGraf(&qd.thePort);
  55.         InitFonts();
  56.         InitWindows();
  57.         InitCursor();
  58.     #endif
  59.     
  60.     #include "LuminanceRecord1.h"    
  61.     printf("Test SetRange and SetLuminance\n");
  62.     c=1.0;
  63.     L=(LR.LMin+LR.LMax)/2.0;
  64.     for(i=0;i<15;i++){
  65.         L0=L*(1.0-c);
  66.         L1=L*(1.0+c);
  67.         tolerance=SetLuminance(NULL,&LR,0,L,L0,L1);
  68.         printf("c%9.6f, ",c);
  69.         printf("Range%5.1f%5.1f, ",L0,L1);
  70.         printf("fixed %1d/%1d, ",LR.fixed,LR.dacs);
  71.         printf("L(VFixed)=%5.1f cd/m^2, ",VToL(&LR,LR.VFixed));
  72.         bits=log((LR.LMax-LR.LMin)/tolerance)/log(2.0);
  73.         printf("tolerance%6.3f=%4.1f bits\n",tolerance,bits);
  74.         c *= 0.5;
  75.     }
  76.  
  77.     printf("Test SetLuminancesAndRange & GetLuminance\n");
  78.     L0=LR.LMin;
  79.     L1=LR.LMax;
  80.     tolerance=SetLuminancesAndRange(NULL,&LR,0,LR.VMax,L0,L1,L0,L1);
  81.     printf("Range %5.1f %5.1f, ",L0,L1);
  82.     printf("fixed %1d/%1d, ",LR.fixed,LR.dacs);
  83.     printf("L(VFixed)=%5.1f cd/m^2, ",VToL(&LR,LR.VFixed));
  84.     bits=log((LR.LMax-LR.LMin)/tolerance)/log(2.0);
  85.     printf("tolerance %10.3f = %10.3f bits\n",tolerance,bits);
  86.     dL=(L1-L0)/LR.VMax;
  87.     printf("%10s %10s %10s\n","L requested","L received","Error");
  88.     n=LR.VMax+1;
  89.     if(n>sizeof(e)/sizeof(e[0]))n=sizeof(e)/sizeof(e[0]);
  90.     for(i=0,L=L0;i<n;i++,L+=dL){
  91.         LGot=GetLuminance(NULL,&LR,i);
  92.         e[i]=LGot-L;
  93.         if(i%16==0)printf("%10.3f %10.3f %10.3f\n",L,LGot,LGot-L);
  94.     }
  95.     mean=Mean(e,n,&sd);
  96.     max=0.0;
  97.     for(i=0;i<n;i++)if(fabs(max)<fabs(e[i]))max=e[i];
  98.     printf("Error mean %f sd %f max %f\n\n",mean,sd,max);
  99.     
  100.     printf("Test VToL and LToV\n");
  101.     printf("%10s %10s %10s\n","L requested","V received","L received");
  102.     for(L=-10.0;L<100.0;L+=20.0){
  103.         V=LToV(&LR,L);
  104.         printf("%9.0f %9.1f %12.6f\n",L,V,VToL(&LR,V));
  105.     }
  106.  
  107.     reps=1000;
  108.     t=TickCount();
  109.     V=LR.VMin;
  110.     dV=(LR.VMax-V)/reps/4;
  111.     for(i=reps/4;i>0;i--) {
  112.         V=VToL(&LR,V);
  113.         V=VToL(&LR,V);
  114.         V=VToL(&LR,V);
  115.         V=VToL(&LR,V);
  116.         V+=dV;
  117.     }
  118.     t=TickCount()-t;
  119.     printf("VToL takes %.1f µs\n",1e6*t/(60.15*reps));
  120.  
  121.     reps=1000;
  122.     t=TickCount();
  123.     L=LR.LMin;
  124.     dL=(LR.LMax-L)/reps/4;
  125.     for(i=reps/4;i>0;i--) {
  126.         V=LToV(&LR,L);
  127.         V=LToV(&LR,L);
  128.         V=LToV(&LR,L);
  129.         V=LToV(&LR,L);
  130.         L+=dL;
  131.     }
  132.     t=TickCount()-t;
  133.     printf("LToV takes %.1f µs\n",1e6*t/(60.15*reps));
  134.  
  135.     reps=1000;
  136.     L0=(LR.LMin+LR.LMax)/2.0;
  137.     L1=1.01*L0;
  138.     SetLuminance(NULL,&LR,0,50.,L0,L1);
  139.     L=L0;
  140.     dL=(L1-L)/reps/4;
  141.     t=TickCount();
  142.     for(i=reps/4;i>0;i--) {
  143.         SetLuminance(NULL,&LR,0,L,L0,L1);
  144.         SetLuminance(NULL,&LR,0,L,L0,L1);
  145.         SetLuminance(NULL,&LR,0,L,L0,L1);
  146.         SetLuminance(NULL,&LR,0,L,L0,L1);
  147.         L+=dL;
  148.     }
  149.     t=TickCount()-t;
  150.     printf("SetLuminance takes %.1f µs with small old range\n",1e6*t/(60.15*reps));
  151.  
  152.     reps=1000;
  153.     SetLuminance(NULL,&LR,0,50.,LR.LMin,LR.LMax);
  154.     L=LR.LMin;
  155.     dL=(LR.LMax-L)/reps/4;
  156.     t=TickCount();
  157.     for(i=reps/4;i>0;i--) {
  158.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  159.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  160.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  161.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  162.         L+=dL;
  163.     }
  164.     t=TickCount()-t;
  165.     printf("SetLuminance takes %.1f µs with large old range\n",1e6*t/(60.15*reps));
  166.  
  167.     reps=200;
  168.     SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  169.     L=LR.LMin;
  170.     dL=(LR.LMax-L)/reps/4;
  171.     t=TickCount();
  172.     for(i=reps/4;i>0;i--) {
  173.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax-1.0);
  174.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  175.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax-1.0);
  176.         SetLuminance(NULL,&LR,0,L,LR.LMin,LR.LMax);
  177.         L+=dL;
  178.     }
  179.     t=TickCount()-t;
  180.     printf("SetLuminance takes %.1f µs with large new range\n",1e6*t/(60.15*reps));
  181.  
  182.     reps=200;
  183.     SetLuminance(NULL,&LR,0,L0,L0,L1);
  184.     t=TickCount();
  185.     for(i=0;i<reps/4;i++) {
  186.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1);
  187.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1);
  188.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1);
  189.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1);
  190.     }
  191.     t=TickCount()-t;
  192.     printf("SetLuminancesAndRange(0..255) takes %.1f ms with small old range\n",1000.0*t/(60.15*reps));
  193.  
  194. #if 1
  195.     reps=48;
  196.     SetLuminance(NULL,&LR,0,L0,L0,L1);
  197.     t=TickCount();
  198.     for(i=0;i<reps/4;i++) {
  199.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1*1.001);
  200.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1);
  201.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1*1.001);
  202.         SetLuminancesAndRange(NULL,&LR,0,255,L0,L1,L0,L1);
  203.     }
  204.     t=TickCount()-t;
  205.     printf("SetLuminancesAndRange(0..255) takes %.1f ms with small new range\n",1000.0*t/(60.15*reps));
  206. #endif
  207.  
  208.     reps=48;
  209.     SetLuminance(NULL,&LR,0,50.,LR.LMin,LR.LMax);
  210.     t=TickCount();
  211.     for(i=0;i<reps/2;i++) {
  212.         SetLuminancesAndRange(NULL,&LR,0,255,LR.LMin,LR.LMax,LR.LMin,LR.LMax);
  213.         SetLuminancesAndRange(NULL,&LR,0,255,LR.LMin,LR.LMax,LR.LMin,LR.LMax);
  214.     }
  215.     t=TickCount()-t;
  216.     printf("SetLuminancesAndRange(0..255) takes %.1f ms with large old range\n",1000.0*t/(60.15*reps));
  217.  
  218. #if 1
  219.     reps=48;
  220.     SetLuminance(NULL,&LR,0,50.,LR.LMin,LR.LMax);
  221.     t=TickCount();
  222.     for(i=0;i<reps/2;i++) {
  223.         SetLuminancesAndRange(NULL,&LR,0,255,LR.LMin,LR.LMax-1.0,LR.LMin,LR.LMax-1.0);
  224.         SetLuminancesAndRange(NULL,&LR,0,255,LR.LMin,LR.LMax-1.0,LR.LMin,LR.LMax);
  225.     }
  226.     t=TickCount()-t;
  227.     printf("SetLuminancesAndRange(0..255) takes %.1f ms with large new range\n",1000.0*t/(60.15*reps));
  228. #endif
  229. }    
  230.  
  231.  
  232.