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

  1. /*
  2. TestAttenuator.c
  3. This produced a simple test pattern that allows a quick yes/no evaluation of the
  4. attenuator before shipping. Mainly this is a check to make sure that all the
  5. resistors were soldered correctly.
  6. HISTORY:
  7. 11/89     dgp wrote it
  8. 9/9/90    dgp    make the arrays static.
  9. 10/17/90    dgp    remove unused variable
  10. 2/16/91        dgp    added check for fpu and color quickdraw
  11. 8/24/91    dgp    Made compatible with THINK C 5.0.
  12. 3/10/92    dgp    include mc68881.h
  13. 4/27/92    dgp    call SetDepth to set screen to 8 bits.
  14. 8/27/92    dgp    replace SysEnvirons() by Gestalt()
  15. 2/7/93    dgp    updated to use SetPixelsQuickly.
  16. */
  17. #include "VideoToolbox.h"
  18. #include <math.h>
  19. #include "Luminance.h"
  20. #if (THINK_C || THINK_CPLUS)
  21.     #include <console.h>
  22. #endif
  23. #if __MWERKS__
  24.     #include <SIOUX.h>
  25. #endif
  26.  
  27. #define XMAX         640        /* Maximum horizontal coordinate */ 
  28. #define YMAX         480        /* Maxumum vertical coordinate */
  29.  
  30. void TestAttenuator(void);
  31.  
  32. void main(void)
  33. {
  34.     Require(gestalt8BitQD);
  35.     TestAttenuator();
  36. }
  37.  
  38. void TestAttenuator(void)
  39. {
  40.     register short i,j,k;
  41.     double a,A,AA;
  42.     CWindowPtr window=NULL;
  43.     WindowPtr oldWindow=NULL;
  44.     GDHandle device=NULL,oldGDHandle=NULL;
  45.     static LuminanceRecord LR;
  46.     short n,mode;
  47.     static double fy[YMAX];
  48.     double c;
  49.     static unsigned long row[XMAX];
  50.     short oldScreen;
  51.     char string[100];
  52.     
  53.     /* parameters of the screen calibration */
  54.     
  55.     MaximizeConsoleHeight();
  56.     #if (THINK_C || THINK_CPLUS)
  57.         console_options.top=YMAX/2-40;
  58.         console_options.nrows=7;
  59.         console_options.txSize=9;
  60.     #elif __MWERKS__
  61.         SIOUXSettings.toppixel=YMAX/2-40;
  62.         SIOUXSettings.rows=7;
  63.         SIOUXSettings.columns=60;
  64.         SIOUXSettings.autocloseonquit=0;
  65.     #endif
  66.     printf("Welcome to TestAttenuator.\n");
  67.     #include "LuminanceRecord1.h"                    // read at compile time
  68.     printf("%s\n",LR.notes);
  69.     oldScreen=LR.screen;
  70.     i=LR.screen;
  71.     do{
  72.         if(GetScreenDevice(1)!=NULL)i=ChooseScreen(i,"Which screen?");
  73.         else i=0;
  74.         device=GetScreenDevice(i);
  75.     }while(device==NULL);
  76.     LR.screen=i;
  77.     sprintf(string,"LuminanceRecord%d.h",LR.screen);
  78.     i=ReadLuminanceRecord(string,&LR,0);        // try to read latest LuminanceRecord
  79.     if(i<1)printf("Warning: couldn't find “%s”. Calibrating screen %d.\n"
  80.         ,string,LR.screen);
  81.     else oldScreen=LR.screen;
  82.  
  83.     /* Find device corresponding to the experimental screen. */
  84.     oldGDHandle = GetGDevice();
  85.     device = GetScreenDevice(LR.screen);
  86.     if(GDClutSize(device)!=256 && NewPaletteManager()){
  87.         mode=HasDepth(device,8,1,1);
  88.         if(mode!=0)SetDepth(device,mode,1,1);        // 8-bit pixelSize, color
  89.     }
  90.     if(GDClutSize(device)!=256){
  91.         PrintfExit("Sorry, I require a screen with 256 colors.\n");
  92.     }
  93.     
  94.     GetPort(&oldWindow);
  95.     window = GDOpenWindow(device);
  96.     SetPort((WindowPtr)window);
  97.     
  98.     for(j=0;j<YMAX/2;j++){
  99.         fy[j]=cos(j*2.0*PI/80.0);
  100.     }
  101.     c=1.0;
  102.     SetLuminances(device,&LR,11,90,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  103.     c/=6.0;
  104.     SetLuminances(device,&LR,91,170,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  105.     c/=6.0;
  106.     SetLuminances(device,&LR,171,250,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  107.     /* Display a swept-contrast sinusoid */
  108.     for(j=0;j<YMAX/2;j++){
  109.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  110.         k+=11;
  111.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  112.         SetPixelsQuickly(0,j,row,1+XMAX/3);
  113.     }
  114.     c *=6.0;
  115.     for(j=0;j<YMAX/2;j++){
  116.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  117.         k+=91;
  118.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  119.         SetPixelsQuickly(XMAX/3,j,row,1+XMAX/3);
  120.     }
  121.     c *=6.0;
  122.     for(j=0;j<YMAX/2;j++){
  123.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  124.         k+=171;
  125.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  126.         SetPixelsQuickly(2*XMAX/3,j,row,1+XMAX/3);
  127.     }
  128.  
  129.     /* compute three clut entries that ought to produce equal luminances */
  130.     AA=LToV(&LR,LR.LMax/4.0);
  131.     printf("%f cd/m^2 equivalent number is %f\n",VToL(&LR,AA),AA);
  132.     i=251;
  133.     A=AA;
  134.     a=A/LR.r;
  135.     if(a>255.) n=255;
  136.     else n=a;
  137.     LR.table[i].rgb.red=n<<8;
  138.     A -= n*LR.r;
  139.     a=A/LR.g;
  140.     if(a>255.) n=255;
  141.     else n=a;
  142.     LR.table[i].rgb.green=n<<8;
  143.     A -= n*LR.g;
  144.     a=A/LR.b;
  145.     if(a>255.) n=255;
  146.     else n=a;
  147.     LR.table[i].rgb.blue=n<<8;
  148.     A -= n*LR.b;
  149.     i++;
  150.     A=AA;
  151.     a=A/LR.g;
  152.     if(a>255.) n=255;
  153.     else n=a;
  154.     LR.table[i].rgb.green=n<<8;
  155.     A -= n*LR.g;
  156.     a=A/LR.b;
  157.     if(a>255.) n=255;
  158.     else n=a;
  159.     LR.table[i].rgb.blue=n<<8;
  160.     A -= n*LR.b;
  161.     a=A/LR.r;
  162.     if(a>255.) n=255;
  163.     else n=a;
  164.     LR.table[i].rgb.red=n<<8;
  165.     A -= n*LR.r;
  166.     i++;
  167.     A=AA;
  168.     a=A/LR.b;
  169.     if(a>255.) n=255;
  170.     else n=a;
  171.     LR.table[i].rgb.blue=n<<8;
  172.     A -= n*LR.b;
  173.     a=A/LR.r;
  174.     if(a>255.) n=255;
  175.     else n=a;
  176.     LR.table[i].rgb.red=n<<8;
  177.     A -= n*LR.r;
  178.     a=A/LR.g;
  179.     if(a>255.) n=255;
  180.     else n=a;
  181.     LR.table[i].rgb.green=n<<8;
  182.     A -= n*LR.g;
  183.     i++;
  184.     for(i=251;i<254;i++) printf("%4d,%4d,%4d = %6.2f == %7.3f cd/m^2\n",
  185.         LR.table[i].rgb.red/256,LR.table[i].rgb.green/256,LR.table[i].rgb.blue/256,
  186.         LToV(&LR,GetLuminance(NULL,&LR,i)), GetLuminance(NULL,&LR,i));
  187.     LoadLuminances(device,&LR,251,253);
  188.     
  189.     /* Display stripes */
  190.     for(i=0;i<XMAX;) {
  191.         for(k=0;k<10;k++)row[i++]=251;
  192.         for(k=0;k<10;k++)row[i++]=252;
  193.         for(k=0;k<10;k++)row[i++]=253;
  194.     }
  195.     for(j=YMAX/2;j<YMAX;j++)SetPixelsQuickly(0,j,row,XMAX);
  196.     
  197.     printf("Hit return to quit.");
  198.     getchar();
  199.     SetPort(oldWindow);
  200.     SetGDevice(oldGDHandle);
  201.     GDDisposeWindow(window);
  202.     RestoreCluts();
  203.     #if (THINK_C || THINK_CPLUS)
  204.         abort();
  205.     #elif __MWERKS__
  206.         SIOUXSettings.autocloseonquit=1;
  207.     #endif
  208. }
  209.