home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 1 / FishNMoreVol1.bin / more / drive_utils / benchmark / diskspeed / renderinfo.c < prev    next >
C/C++ Source or Header  |  1990-02-03  |  5KB  |  176 lines

  1. /*
  2.  *                          DiskSpeed v3.0
  3.  *                                by
  4.  *                           Michael Sinz
  5.  *
  6.  *             Copyright (c) 1989 by MKSoft Development
  7.  *
  8.  *            MKSoft Development
  9.  *            163 Appledore Drive
  10.  *            Downingtown, PA 19335
  11.  *
  12.  * Yes, this is yet another disk speed testing program, but with a few
  13.  * differences.  It was designed to give the most accurate results of the
  14.  * true disk performance in the system.  For this reason many of
  15.  * DiskSpeed's results may look either lower or higher than current disk
  16.  * performance tests.
  17.  *
  18.  * This program was thrown together in a few hours because I needed more
  19.  * accurate and consistent results for disk performance as seen from the
  20.  * application's standpoint.  This program has now served its purpose and
  21.  * I am now giving it to the rest of the Amiga world to play with as long
  22.  * as all of the files remain together in unmodified form.  (That is, the
  23.  * files DiskSpeed, DiskSpeed.info, DiskSpeed.c, DiskSpeedWindow.c,
  24.  * DiskSpeedWindow.h, MakeBoxes.c, MakeBoxes.h, StandardGadgets.c,
  25.  * StandardGadgets.h, RenderInfo.c, RenderInfo.h, DiskSpeed.doc, and
  26.  * MakeFile)
  27.  *
  28.  * Version 2.0 of this program added a few features and cleaned up the
  29.  * user interface.  I hope you like this...
  30.  *
  31.  * Version 3.0 of this program added the performance stress and cleaned up
  32.  * some parts of the older code.  (Fix to RenderInfo.c)
  33.  *
  34.  ******************************************************************************
  35.  *                                          *
  36.  *    Reading legal mush can turn your brain into guacamole!              *
  37.  *                                          *
  38.  *        So here is some of that legal mush:                  *
  39.  *                                          *
  40.  * Permission is hereby granted to distribute this program's source          *
  41.  * executable, and documentation for non-commercial purposes, so long as the  *
  42.  * copyright notices are not removed from the sources, executable or          *
  43.  * documentation.  This program may not be distributed for a profit without   *
  44.  * the express written consent of the author Michael Sinz.              *
  45.  *                                          *
  46.  * This program is not in the public domain.                      *
  47.  *                                          *
  48.  * Fred Fish is expressly granted permission to distribute this program's     *
  49.  * source and executable as part of the "Fred Fish freely redistributable     *
  50.  * Amiga software library."                              *
  51.  *                                          *
  52.  * Permission is expressly granted for this program and it's source to be     *
  53.  * distributed as part of the Amicus Amiga software disks, and the          *
  54.  * First Amiga User Group's Hot Mix disks.                      *
  55.  *                                          *
  56.  ******************************************************************************
  57.  *
  58.  * This file contains the definition of the rendering information
  59.  * for elements on the screen.  This information is used to generate
  60.  * the correct pen colours for items on the screen...
  61.  */
  62.  
  63. #include    <exec/types.h>
  64. #include    <graphics/view.h>
  65. #include    <intuition/intuition.h>
  66.  
  67. #include    <proto/intuition.h>
  68. #include    <proto/graphics.h>
  69.  
  70. #include    "RenderInfo.h"
  71.  
  72.  
  73. /*
  74.  * This returns the colour difference hamming value...
  75.  */
  76. SHORT ColourDifference(UWORD rgb0, UWORD rgb1)
  77. {
  78. register    SHORT    level;
  79. register    SHORT    tmp;
  80.  
  81.     tmp=(rgb0 & 15) - (rgb1 & 15);
  82.     level=tmp*tmp;
  83.     tmp=((rgb0>>4) & 15) - ((rgb1>>4) & 15);
  84.     level+=tmp*tmp;
  85.     tmp=((rgb0>>8) & 15) - ((rgb1>>8) & 15);
  86.     level+=tmp*tmp;
  87.     return(level);
  88. }
  89.  
  90. /*
  91.  * Calculate a rough brightness hamming value...
  92.  */
  93. SHORT ColourLevel(UWORD rgb)
  94. {
  95.     return(ColourDifference(rgb,0));
  96. }
  97.  
  98. #define    MAX_COLOURS    16
  99.  
  100. VOID FillIn_RenderInfo(struct RenderInfo *ri)
  101. {
  102. register    SHORT        numcolours;
  103. register    SHORT        loop;
  104. register    SHORT        loop1;
  105. register    SHORT        backpen;
  106. register    SHORT        tmp;
  107.         SHORT        colours[16];
  108.         SHORT        colourlevels[16];
  109.         SHORT        pens[16];
  110.     struct    Screen        screen;
  111.  
  112.     GetScreenData((UBYTE *)&screen,sizeof(struct Screen),WBENCHSCREEN,NULL);
  113.     numcolours=1 << (screen.RastPort.BitMap->Depth);
  114.     if (numcolours>16) numcolours=16;
  115.  
  116.     if (numcolours<3)
  117.     {    /* Some silly person is running with 2 colours... */
  118.         ri->BackPen=1;
  119.         ri->Highlight=0;
  120.         ri->Shadow=1;
  121.         ri->TextPen=0;
  122.     }
  123.     else
  124.     {
  125.         for (loop=0;loop<numcolours;loop++)
  126.         {
  127.             colours[loop]=GetRGB4(screen.ViewPort.ColorMap,(LONG)loop);
  128.             colourlevels[loop]=ColourLevel(colours[loop]);
  129.             pens[loop]=loop;
  130.         }
  131.  
  132.         /* Sort darkest to brightest... */
  133.         for (loop=0;loop<(numcolours-1);loop++)
  134.          for (loop1=loop+1;loop1<numcolours;loop1++)
  135.          {
  136.             if (colourlevels[loop]>colourlevels[loop1])
  137.             {
  138.                 tmp=colourlevels[loop];
  139.                 colourlevels[loop]=colourlevels[loop1];
  140.                 colourlevels[loop1]=tmp;
  141.  
  142.                 tmp=colours[loop];
  143.                 colours[loop]=colours[loop1];
  144.                 colours[loop1]=tmp;
  145.  
  146.                 tmp=pens[loop];
  147.                 pens[loop]=pens[loop1];
  148.                 pens[loop1]=tmp;
  149.             }
  150.          }
  151.  
  152.         /* Now, pick the pens... HightLight... */
  153.         loop=numcolours-1;
  154.         while (!(ri->Highlight=pens[loop--]));
  155.  
  156.         /* and Shadow... */
  157.         loop=0;
  158.         while (!(ri->Shadow=pens[loop++]));
  159.  
  160.         /* The BackGround pen... */
  161.         if (!pens[loop]) loop++;
  162.         ri->BackPen=pens[backpen=loop];
  163.  
  164.         loop1=0;
  165.         for (loop=0;loop<numcolours;loop++)
  166.         {
  167.             tmp=ColourDifference(colours[loop],colours[backpen]);
  168.             if (tmp>loop1)
  169.             {
  170.                 loop1=tmp;
  171.                 ri->TextPen=pens[loop];
  172.             }
  173.         }
  174.     }
  175. }
  176.