home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d02xx / d0288.lha / DiskSpeed / RenderInfo.c < prev    next >
C/C++ Source or Header  |  1989-12-10  |  5KB  |  157 lines

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