home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / Utilities / TestLuminance / TestLuminance.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-24  |  6.2 KB  |  241 lines  |  [TEXT/MMCC]

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