home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / miscutil / disksped.lzh / DiskSpeed / src / renderinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-01  |  5.4 KB  |  203 lines

  1. /*
  2.  * MKSoft Development Amiga ToolKit V1.0
  3.  *
  4.  * Copyright (c) 1985,86,87,88,89,90 by MKSoft Development
  5.  *
  6.  *                          DiskSpeed v4.1
  7.  *                                by
  8.  *                           Michael Sinz
  9.  *
  10.  *             Copyright (c) 1989 by MKSoft Development
  11.  *
  12.  *            MKSoft Development
  13.  *            163 Appledore Drive
  14.  *            Downingtown, PA 19335
  15.  *
  16.  * Yes, this is yet another disk speed testing program, but with a few
  17.  * differences.  It was designed to give the most accurate results of the
  18.  * true disk performance in the system.  For this reason many of
  19.  * DiskSpeed's results may look either lower or higher than current disk
  20.  * performance tests.
  21.  *
  22.  ******************************************************************************
  23.  *                                          *
  24.  *    Reading legal mush can turn your brain into guacamole!              *
  25.  *                                          *
  26.  *        So here is some of that legal mush:                  *
  27.  *                                          *
  28.  * Permission is hereby granted to distribute this program's source          *
  29.  * executable, and documentation for non-commercial purposes, so long as the  *
  30.  * copyright notices are not removed from the sources, executable or          *
  31.  * documentation.  This program may not be distributed for a profit without   *
  32.  * the express written consent of the author Michael Sinz.              *
  33.  *                                          *
  34.  * This program is not in the public domain.                      *
  35.  *                                          *
  36.  * Fred Fish is expressly granted permission to distribute this program's     *
  37.  * source and executable as part of the "Fred Fish freely redistributable     *
  38.  * Amiga software library."                              *
  39.  *                                          *
  40.  * Permission is expressly granted for this program and it's source to be     *
  41.  * distributed as part of the Amicus Amiga software disks, and the          *
  42.  * First Amiga User Group's Hot Mix disks.                      *
  43.  *                                          *
  44.  ******************************************************************************
  45.  */
  46.  
  47. /*
  48.  * This file contains the definition of the rendering information
  49.  * for elements on the screen.  This information is used to generate
  50.  * the correct pen colours for items on the screen...
  51.  */
  52.  
  53. #include    <exec/types.h>
  54. #include    <exec/memory.h>
  55. #include    <graphics/view.h>
  56. #include    <graphics/text.h>
  57. #include    <intuition/intuition.h>
  58. #include    <intuition/screens.h>
  59.  
  60. #include    <proto/exec.h>
  61. #include    <proto/intuition.h>
  62. #include    <proto/graphics.h>
  63.  
  64. #include    "RenderInfo.h"
  65.  
  66. /*
  67.  * These define the amount of Red, Green, and Blue scaling used
  68.  * to help take into account the different visual impact of those
  69.  * colours on the screen.
  70.  */
  71. #define    BLUE_SCALE    2
  72. #define    GREEN_SCALE    6
  73. #define    RED_SCALE    3
  74.  
  75. #define    MAX_COLOURS    16
  76.  
  77. /*
  78.  * This returns the colour difference hamming value...
  79.  */
  80. SHORT ColourDifference(UWORD rgb0, UWORD rgb1)
  81. {
  82. register    SHORT    level;
  83. register    SHORT    tmp;
  84.  
  85.     tmp=(rgb0 & 15) - (rgb1 & 15);
  86.     level=tmp*tmp*BLUE_SCALE;
  87.     tmp=((rgb0>>4) & 15) - ((rgb1>>4) & 15);
  88.     level+=tmp*tmp*GREEN_SCALE;
  89.     tmp=((rgb0>>8) & 15) - ((rgb1>>8) & 15);
  90.     level+=tmp*tmp*RED_SCALE;
  91.     return(level);
  92. }
  93.  
  94. /*
  95.  * Calculate a rough brightness hamming value...
  96.  */
  97. #define    ColourLevel(x)    ColourDifference(x,0)
  98.  
  99. /*
  100.  * For new programs, this also opens fonts...
  101.  */
  102. static VOID NewFillIn_RenderInfo(struct RenderInfo *ri,struct Screen *TheScreen)
  103. {
  104. register    SHORT        numcolours;
  105. register    SHORT        loop;
  106. register    SHORT        loop1;
  107. register    SHORT        backpen;
  108. register    SHORT        tmp;
  109.         SHORT        colours[MAX_COLOURS];
  110.         SHORT        colourlevels[MAX_COLOURS];
  111.         SHORT        pens[MAX_COLOURS];
  112.     struct    Screen        screen;
  113.  
  114.     if (!TheScreen) GetScreenData((APTR)(TheScreen=&screen),sizeof(struct Screen),WBENCHSCREEN,NULL);
  115.  
  116.     ri->WindowTitle=TheScreen->BarHeight-TheScreen->BarVBorder+TheScreen->WBorTop;
  117.  
  118.     numcolours=1 << (TheScreen->RastPort.BitMap->Depth);
  119.     if (numcolours>MAX_COLOURS) numcolours=MAX_COLOURS;
  120.  
  121.     if (numcolours<3)
  122.     {    /* Some silly person is running with 2 colours... */
  123.         ri->BackPen=0;
  124.         ri->Highlight=1;
  125.         ri->Shadow=1;
  126.         ri->TextPen=1;
  127.     }
  128.     else
  129.     {
  130.         for (loop=0;loop<numcolours;loop++)
  131.         {
  132.             colours[loop]=GetRGB4(TheScreen->ViewPort.ColorMap,(LONG)loop);
  133.             colourlevels[loop]=ColourLevel(colours[loop]);
  134.             pens[loop]=loop;
  135.         }
  136.  
  137.         /* Sort darkest to brightest... */
  138.         for (loop=0;loop<(numcolours-1);loop++)
  139.         {
  140.             for (loop1=loop+1;loop1<numcolours;loop1++)
  141.             {
  142.                 if (colourlevels[loop]>colourlevels[loop1])
  143.                 {
  144.                     tmp=colourlevels[loop];
  145.                     colourlevels[loop]=colourlevels[loop1];
  146.                     colourlevels[loop1]=tmp;
  147.  
  148.                     tmp=colours[loop];
  149.                     colours[loop]=colours[loop1];
  150.                     colours[loop1]=tmp;
  151.  
  152.                     tmp=pens[loop];
  153.                     pens[loop]=pens[loop1];
  154.                     pens[loop1]=tmp;
  155.                 }
  156.             }
  157.         }
  158.  
  159.         /* Now, pick the pens... HightLight... */
  160.         loop=numcolours-1;
  161.         while (!(ri->Highlight=pens[loop--]));
  162.  
  163.         /* and Shadow... */
  164.         loop=0;
  165.         while (!(ri->Shadow=pens[loop++]));
  166.  
  167.         /* The BackGround pen... */
  168.         if (!pens[loop]) loop++;
  169.         ri->BackPen=pens[backpen=loop];
  170.  
  171.         loop1=0;
  172.         for (loop=0;loop<numcolours;loop++)
  173.         {
  174.             tmp=ColourDifference(colours[loop],colours[backpen]);
  175.             if (tmp>loop1)
  176.             {
  177.                 loop1=tmp;
  178.                 ri->TextPen=pens[loop];
  179.             }
  180.         }
  181.     }
  182. }
  183.  
  184. VOID CleanUp_RenderInfo(struct RenderInfo *ri)
  185. {
  186.     if (ri) FreeMem(ri,sizeof(struct RenderInfo));
  187. }
  188.  
  189. /*
  190.  * Use this screen for the render information.  If the screen is NULL
  191.  * it will use the WorkBench screen...
  192.  */
  193. struct RenderInfo *Get_RenderInfo(struct Screen *TheScreen)
  194. {
  195. register    struct    RenderInfo    *ri;
  196.  
  197.     if (ri=AllocMem(sizeof(struct RenderInfo),MEMF_PUBLIC|MEMF_CLEAR))
  198.     {
  199.         NewFillIn_RenderInfo(ri,TheScreen);
  200.     }
  201.     return (ri);
  202. }
  203.