home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Misc / OTT-PHT3.DMS / in.adf / devdocs / gio / whitenoise.c < prev   
Encoding:
C/C++ Source or Header  |  1994-11-21  |  2.2 KB  |  114 lines

  1. /* white noise loader © Almathera 1994, All Rights Reserved */
  2.  
  3.     #include <exec/types.h>
  4.     #include <clib/exec_protos.h>
  5.     #include <clib/dos_protos.h>
  6.     #include <clib/intuition_protos.h>
  7.     #include <dos/dos.h>
  8.     #include <pragmas/exec_pragmas.h>
  9.     #include <pragmas/dos_pragmas.h>
  10.     #include <pragmas/intuition_pragmas.h>
  11.     #include "pgs_protos.h"
  12.     #include "pgs_pragmas.h"
  13.  
  14.     #include "gio.h"
  15.     #include <stdio.h>
  16.     #include <stdlib.h>
  17.     #include <time.h>
  18.  
  19. /* prototypes */
  20. __asm ULONG __saveds GioExamine(register __a0 struct GIOData *giodata);
  21. __asm ULONG __saveds GioRead(register __a0 struct GIOData *giodata);
  22. __asm ULONG __saveds GioWrite(register __a0 struct GIOData *giodata);
  23. /* end of prototypes */
  24.  
  25. //------------------------ CODE COMES HERE -------------------------
  26.  
  27. __asm ULONG __saveds GioInfo(void)
  28. {
  29. //    return(GIOF_LOADER8|GIOF_LOADER24|GIOF_SAVER8|GIOF_SAVER24|GIOF_LOADFILE|GIOF_SAVEFILE)
  30.     return(GIOF_LOADER8);
  31.  
  32. }
  33.  
  34.  
  35. #define PgsBase giodata->PgsBase
  36.  
  37. __asm ULONG __saveds GioExamine(register __a0 struct GIOData *giodata)
  38. {
  39.  
  40.     giodata->Flags = GioInfo();
  41.     giodata->Width    = 320;
  42.     giodata->Height = 256;
  43.  
  44.     if(PgsBase)
  45.     {
  46.  
  47.         switch(GetDimensions("Size of new White Noise image",&giodata->Width,&giodata->Height))
  48.         {
  49.             case 1:
  50.                 break;
  51.             case 2:
  52.                 giodata->Error = LOAD_RAMERR;
  53.                 goto err;
  54.             case 0:
  55.                 giodata->Error = LOAD_ABORTED;
  56.                 goto err;
  57.             default:
  58.                 giodata->Error = LOAD_SYSERR;    
  59.                 goto err;
  60.         }
  61.     } 
  62.  
  63.     giodata->Depth = 8;
  64.     srand(time(NULL));      // seed random number
  65.     giodata->Error = LOAD_OK;
  66.  
  67. err:
  68.     return(giodata->Error);
  69. }
  70.  
  71. __asm ULONG __saveds GioRead(register __a0 struct GIOData *giodata)
  72. {
  73. int x,y;
  74. UBYTE col;
  75. UBYTE *poker;
  76.  
  77.    SetProgress("Creating image...",0);
  78.     for(y=0;y<giodata->Height;y++)
  79.     {
  80.         if(!(y%16))
  81.         if(SetProgress(0,y*100/giodata->Height)!=1)
  82.         {
  83.             giodata->Error = LOAD_ABORTED;
  84.             goto err;
  85.         }
  86.  
  87.         poker=GetLine(giodata,y);
  88.  
  89.         for(x=0;x<giodata->Width;x++)
  90.         {
  91.             col=rand()%0xff;
  92.             *poker++=col;
  93.         }
  94.         ReleaseLine(giodata,y);
  95.     }
  96.  
  97.     poker=giodata->Palette;
  98.     for(x=0;x<256;x++) 
  99.     {
  100.         *poker++=x; *poker++=x; *poker++=x;
  101.     }
  102.     
  103.     giodata->Error = NULL;
  104. err:
  105.     return(giodata->Error);
  106. }
  107.  
  108. __asm ULONG __saveds GioWrite(register __a0 struct GIOData *giodata)
  109. {
  110.     giodata->Error=LOAD_WRONGTYPE;
  111.     return(giodata->Error);
  112. }
  113.  
  114.