home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Converter / PHOGEN3.DMS / in.adf / DevDocs.lha / examples / noise / noise.c < prev   
Encoding:
C/C++ Source or Header  |  1995-03-30  |  3.0 KB  |  146 lines

  1. /* Old V1.1 colournoise and whitenoise loaders combined into one.
  2. Jolyon - 19-1-95
  3.  
  4. Updated for devdoc examples 30-3-95.
  5.  
  6. */
  7.  
  8.     #include <exec/types.h>
  9.     #include <clib/exec_protos.h>
  10.     #include <clib/dos_protos.h>
  11.     #include <clib/intuition_protos.h>
  12.     #include <dos/dos.h>
  13.     #include <pragmas/exec_pragmas.h>
  14.     #include <pragmas/dos_pragmas.h>
  15.     #include <pragmas/intuition_pragmas.h>
  16.     #include <clib/pgs_protos.h>
  17.     #include <pragmas/pgs_pragmas.h>
  18.     #include <photogenics/gio.h>
  19.  
  20. /* prototypes */
  21. __asm ULONG GioExamine(register __a0 struct GIOData *giodata);
  22. __asm ULONG GioRead(register __a0 struct GIOData *giodata);
  23. __asm ULONG GioWrite(register __a0 struct GIOData *giodata);
  24. /* end of prototypes */
  25.  
  26. //------------------------ CODE COMES HERE -------------------------
  27.  
  28. __asm ULONG  GioInfo(void)
  29. {
  30. //    return(GIOF_LOADER8|GIOF_LOADER24|GIOF_SAVER8|GIOF_SAVER24|GIOF_LOADFILE|GIOF_SAVEFILE)
  31.     return(GIOF_LOADER24|GIOF_EXTENDED|GIOF_LOADPREFS);
  32. }
  33.  
  34. #define PgsBase giodata->PgsBase
  35.  
  36. ULONG width = 320;
  37. ULONG height = 256;
  38. ULONG cmode = 0;
  39.  
  40. __asm ULONG  GioExamine(register __a0 struct GIOData *giodata)
  41. {
  42.     giodata->Flags = GioInfo();
  43.  
  44.     switch(cmode = ThreeButtonReq("Noise loader","Type of Noise image to create","Colour Noise","White Noise","Cancel"))
  45.     {
  46.         case 3:
  47.             giodata->Error = LOAD_ABORTED;
  48.             goto err;
  49.             break;
  50.         case 0:
  51.             giodata->Error = LOAD_ABORTED;
  52.             goto err;
  53.             break;
  54.     }
  55.  
  56.     switch(GetDimensions("Size of new Noise image",&width,&height))
  57.     {
  58.         case 1:
  59.             break;
  60.         case 2:
  61.             giodata->Error = LOAD_RAMERR;
  62.             goto err;
  63.         case 0:
  64.             giodata->Error = LOAD_ABORTED;
  65.             goto err;
  66.         default:
  67.             giodata->Error = LOAD_SYSERR;    
  68.             goto err;
  69.     } 
  70.  
  71.     giodata->Width = width;
  72.     giodata->Height = height;
  73.     giodata->Depth = 24;
  74.     giodata->Error = LOAD_OK;
  75. err:
  76.     return(giodata->Error);
  77. }
  78.  
  79. __asm ULONG  GioRead(register __a0 struct GIOData *giodata)
  80. {
  81. int x,y;
  82. UBYTE colr;
  83. UBYTE *poker;
  84.  
  85.     InitRandom(0);  // initialise random number generator
  86.  
  87.     SetProgress("Creating Noise image...",0);
  88.  
  89.     for(y=0;y<giodata->Height;y++)
  90.     {
  91.         if(!(y%16))
  92.         if(SetProgress(0,y*100/giodata->Height)!=1)
  93.         {
  94.             giodata->Error = LOAD_ABORTED;
  95.             goto err;
  96.         }
  97.  
  98.         poker=GetLine(giodata,y);
  99.         if(cmode==1)
  100.         {
  101.             for(x=0;x<giodata->Width;x++)
  102.             {
  103.                 *poker++=Random(1)%0xff;
  104.                 *poker++=Random(1)%0xff;
  105.                 *poker++=Random(1)%0xff;
  106.             }
  107.         } else {
  108.             for(x=0;x<giodata->Width;x++)
  109.             {
  110.                 colr=Random(1)%0xff;
  111.                 *poker++=colr;
  112.                 *poker++=colr;
  113.                 *poker++=colr;
  114.             }
  115.         }
  116.         ReleaseLine(giodata,y);
  117.     }
  118.     giodata->Error = NULL;
  119. err:
  120.     return(giodata->Error);
  121. }
  122.  
  123. __asm ULONG  GioWrite(register __a0 struct GIOData *giodata)
  124. {
  125. /* we can't write a noise file! */
  126.  
  127.     giodata->Error=LOAD_WRONGTYPE;
  128.     return(giodata->Error);
  129. }
  130.  
  131.  
  132. __asm void  GioCleanUp(register __a0 struct GIOData *giodata)
  133. {
  134. }
  135.  
  136. __asm void  GioSavePrefs(register __a0 struct GIOData *giodata)
  137. {
  138. }
  139.  
  140. __asm void  GioLoadPrefs(register __a0 struct GIOData *giodata)
  141. {
  142. // This allows user to set default dimensions.
  143.     GetDimensions("Select default size for Noise Loader",&width,&height);
  144. }
  145.  
  146.