home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / icons / fixicon.lha / fixicon.c < prev    next >
C/C++ Source or Header  |  1992-08-20  |  5KB  |  156 lines

  1.  
  2. /* --------------------------------------------------------------------------
  3.  *
  4.  * Program Title :
  5.  *
  6.  *      FixIcon - by Robert Lang 15/6/91.
  7.  *
  8.  * Description :
  9.  *
  10.  *      Fixes an icon so that it doesn't show as messy when used on a
  11.  *      more than 4 colour screen. (Particularly since WB2 has this option).
  12.  *
  13.  * Notes :
  14.  *
  15.  *      Compiled on an Amiga 3000UX using Lattice/SAS C V5.10a !
  16.  *
  17.  *      This source is supplied with the program for reference or learning
  18.  *      only, and may not be used within a commercial program or any money-
  19.  *      making project that makes any more than the current Megadisc PD
  20.  *      prices (about $5 a disk).
  21.  *
  22.  *      FixIcon may be distributed freely (ie. not on ANY commercial product
  23.  *      without written consent from the author), provided that the document
  24.  *      file, source file, and executable are all included UNALTERED.
  25.  *
  26.  *      This program does not check what sort of image rendering etc. is
  27.  *      ocurring for this icon...could be a problem with some icons ???
  28.  *
  29.  *      PlaneOnOff may be the source of problems as well, although rare,
  30.  *      so its left out of this program...easy to modify.
  31.  *
  32.  *              Robert Lang
  33.  *              EdgeWare
  34.  *              P.O. Box 127
  35.  *              CARDIFF NSW 2285
  36.  *              AUSTRALIA
  37.  *
  38.  * Revision :
  39.  *
  40.  * 15th June 1991 - V1.0 Release, Robert Lang.
  41.  * 7th July 1991  - V1.1 Fixed...was setting PlanePick wrong... Robert Lang.
  42.  *
  43.  * -------------------------------------------------------------------------*/
  44.  
  45. #include <workbench/workbench.h>
  46. #include <workbench/icon.h>
  47. #include <clib/icon_protos.h>
  48. #include <clib/exec_protos.h>
  49. #include <dos.h>
  50.  
  51. struct Library __chip *IconBase = NULL;
  52.  
  53. #define TODAY "15th June 1991"
  54. #define VERSION "V1.1"
  55.  
  56. /* a simple macro */
  57.  
  58. #define GAD(f) ((f)->do_Gadget)
  59. #define IMG(f) (((f)->do_Gadget).GadgetRender)
  60.  
  61. main(int argc, int *argv[])
  62. {
  63.     struct DiskObject __chip *infofile;
  64.     struct Image __chip *iconimage,*backimage;
  65.     BOOL stat, write_out = FALSE;
  66.     int power,i;
  67.  
  68.     /* a little brag */
  69.     printf("\nFixIcon "VERSION" by Robert Lang, "TODAY". © Edgeware 1991.\n\n");
  70.  
  71.     if ((argc == 1) || ((strcmp(argv[1],"?")) == 0)) /* usage output */
  72.     {
  73.         printf("Usage : %s icon\n"
  74.                "\nWhere icon is the icon with the graphical problem "
  75.                "(without the .info extension).\n"
  76.                "FixIcon will attempt to repair the problem.\n"
  77.                "\n\tRobert Lang\n\tP.O. Box 127\n\tEdgeWorth NSW 2285\n\t"
  78.                "AUSTRALIA\n\n",argv[0]);
  79.         exit(RETURN_OK);
  80.     }
  81.  
  82.     if ((IconBase = OpenLibrary(ICONNAME,0L)) == NULL)
  83.     {
  84.         printf("Error...can't open library "ICONNAME" !\n");
  85.         exit(RETURN_ERROR);
  86.     }
  87.  
  88.     infofile = GetDiskObject((UBYTE *)argv[1]); /* load the .info file */
  89.  
  90.     if (!infofile)
  91.     {
  92.         printf("Error...can't open %s.info file !\n",argv[1]);
  93.         CloseLibrary(IconBase);
  94.         exit(RETURN_ERROR);
  95.     }
  96.  
  97.     iconimage = GAD(infofile).GadgetRender; /* these are the actual images */
  98.     backimage = GAD(infofile).SelectRender;
  99.  
  100.     if (iconimage == NULL) /* what ? no image ?? */
  101.     {
  102.         printf("Error...Icon has no image !\n");
  103.         goto abort;
  104.     }
  105.  
  106.     for (power = 0, i = 0; i<=iconimage->Depth; i++)
  107.         power += 2;
  108.  
  109.     printf("%d,%d\n",iconimage->Depth,power);
  110.  
  111.     if (iconimage->PlanePick != (power-1)) /* do the repair */
  112.     {
  113.         printf("Front Image PlanePick has an error...fixed !\n");
  114. /*        iconimage->PlanePick = iconimage->Depth; */
  115.         iconimage->PlanePick = power-1; /* RL 3rd July 1991 */
  116.         iconimage->PlaneOnOff = 0;
  117.         write_out = TRUE;
  118.     }
  119.     else
  120.     {
  121.         printf("No error found with PlanePick for front image, no action taken.\n");
  122.     }
  123.  
  124.     if (backimage == NULL) goto exit; /* no second image */
  125.  
  126.     for (power = 0, i = 0; i<=backimage->Depth; i++)
  127.         power += 2;
  128.  
  129.     if (backimage->PlanePick != (power-1)) /* repair second image */
  130.     {
  131.         printf("Back Image PlanePick has an error...fixed !\n");
  132.         backimage->PlanePick  = backimage->Depth;
  133.         backimage->PlaneOnOff = 0;
  134.         write_out = TRUE;
  135.     }
  136.     else
  137.     {
  138.         printf("No error found with PlanePick for back image, no action taken.\n");
  139.     }
  140.  
  141. exit:
  142.     if (write_out) /* write the .info file back to disk ! */
  143.     {
  144.         stat = PutDiskObject((UBYTE *)argv[1],infofile);
  145.         if (!stat)
  146.             printf("Error ocurred in writing %s.info file...change may not be successful.\n",argv[1]);
  147.     }
  148.  
  149. abort:
  150.     FreeDiskObject(infofile);
  151.     CloseLibrary(IconBase);
  152.  
  153.     printf("\n");
  154. }
  155.  
  156. /* end of fixicon.c --------------------------------------------------------*/