home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 576.lha / DiskSpeed_v4.0 / renderinfo.c < prev    next >
C/C++ Source or Header  |  1991-09-11  |  5KB  |  201 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.0
  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.     numcolours=1 << (TheScreen->RastPort.BitMap->Depth);
  117.     if (numcolours>MAX_COLOURS) numcolours=MAX_COLOURS;
  118.  
  119.     if (numcolours<3)
  120.     {    /* Some silly person is running with 2 colours... */
  121.         ri->BackPen=0;
  122.         ri->Highlight=1;
  123.         ri->Shadow=1;
  124.         ri->TextPen=1;
  125.     }
  126.     else
  127.     {
  128.         for (loop=0;loop<numcolours;loop++)
  129.         {
  130.             colours[loop]=GetRGB4(TheScreen->ViewPort.ColorMap,(LONG)loop);
  131.             colourlevels[loop]=ColourLevel(colours[loop]);
  132.             pens[loop]=loop;
  133.         }
  134.  
  135.         /* Sort darkest to brightest... */
  136.         for (loop=0;loop<(numcolours-1);loop++)
  137.         {
  138.             for (loop1=loop+1;loop1<numcolours;loop1++)
  139.             {
  140.                 if (colourlevels[loop]>colourlevels[loop1])
  141.                 {
  142.                     tmp=colourlevels[loop];
  143.                     colourlevels[loop]=colourlevels[loop1];
  144.                     colourlevels[loop1]=tmp;
  145.  
  146.                     tmp=colours[loop];
  147.                     colours[loop]=colours[loop1];
  148.                     colours[loop1]=tmp;
  149.  
  150.                     tmp=pens[loop];
  151.                     pens[loop]=pens[loop1];
  152.                     pens[loop1]=tmp;
  153.                 }
  154.             }
  155.         }
  156.  
  157.         /* Now, pick the pens... HightLight... */
  158.         loop=numcolours-1;
  159.         while (!(ri->Highlight=pens[loop--]));
  160.  
  161.         /* and Shadow... */
  162.         loop=0;
  163.         while (!(ri->Shadow=pens[loop++]));
  164.  
  165.         /* The BackGround pen... */
  166.         if (!pens[loop]) loop++;
  167.         ri->BackPen=pens[backpen=loop];
  168.  
  169.         loop1=0;
  170.         for (loop=0;loop<numcolours;loop++)
  171.         {
  172.             tmp=ColourDifference(colours[loop],colours[backpen]);
  173.             if (tmp>loop1)
  174.             {
  175.                 loop1=tmp;
  176.                 ri->TextPen=pens[loop];
  177.             }
  178.         }
  179.     }
  180. }
  181.  
  182. VOID CleanUp_RenderInfo(struct RenderInfo *ri)
  183. {
  184.     if (ri) FreeMem(ri,sizeof(struct RenderInfo));
  185. }
  186.  
  187. /*
  188.  * Use this screen for the render information.  If the screen is NULL
  189.  * it will use the WorkBench screen...
  190.  */
  191. struct RenderInfo *Get_RenderInfo(struct Screen *TheScreen)
  192. {
  193. register    struct    RenderInfo    *ri;
  194.  
  195.     if (ri=AllocMem(sizeof(struct RenderInfo),MEMF_PUBLIC|MEMF_CLEAR))
  196.     {
  197.         NewFillIn_RenderInfo(ri,TheScreen);
  198.     }
  199.     return (ri);
  200. }
  201.