home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 015.lha / tracer_source / showpat.c < prev    next >
C/C++ Source or Header  |  1986-11-10  |  4KB  |  166 lines

  1. #include <graphics/gfxbase.h>
  2. #include <graphics/display.h>
  3. #include <intuition/intuition.h>
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. struct    GfxBase        *GfxBase;    /* Export the library pointers */
  8. struct    IntuitionBase    *IntuitionBase;
  9. struct    RastPort    *rp;        /* Graphics structures           */
  10. struct    ViewPort    *vp;
  11. struct    Window        *w;        /* Intuition structures        */ 
  12. struct    Screen        *screen;
  13.  
  14. struct    NewScreen    ns = {
  15.     0, 0,                /* start position                */
  16.     320, 400, 4,            /* width, height, depth          */
  17.     15, 0,                /* detail pen, block pen         */
  18.     INTERLACE,            /* Hires ViewMode                */
  19.     CUSTOMSCREEN,            /* screen type                   */
  20.     NULL,                /* font to use                   */
  21.     NULL,                /* default title for screen      */
  22.     NULL                /* pointer to additional gadgets */
  23. };
  24.  
  25. struct NewWindow nw = {
  26.     0, 0,                /* start position                */
  27.     320, 400,            /* width, height                 */
  28.     15, 0,                /* detail pen, block pen         */
  29.     NULL,                /* IDCMP flags                   */
  30.     BORDERLESS,            /* window flags                  */
  31.     NULL,                /* pointer to first user gadget  */
  32.     NULL,                /* pointer to user checkmark     */
  33.     NULL,                /* window title                  */
  34.     NULL,                /* pointer to screen (set below) */
  35.     NULL,                /* pointer to superbitmap        */
  36.     0, 0, 320, 400,            /* ignored since not sizeable    */
  37.     CUSTOMSCREEN            /* type of screen desired        */
  38. };
  39.  
  40.  
  41. char    suzie[300][250];
  42. FILE    *in;
  43.  
  44. main(argc, argv)
  45. int    argc;
  46. char    **argv;
  47. {
  48.     char    wait[10];
  49.  
  50.     if( !(in=fopen(argv[1], "r")) ) {
  51.         printf("no input file\n");
  52.         exit(-1);
  53.     }
  54.     if ( !(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library") ) ) {
  55.         cleanup();
  56.         exit(103);
  57.     }
  58.  
  59.     if ( !( IntuitionBase
  60.         =(struct IntuitionBase *)OpenLibrary("intuition.library") )
  61.      ) {
  62.         cleanup();
  63.         exit(103);
  64.     }
  65.     if ( !(screen = (struct Screen *)OpenScreen(&ns) ) ) { 
  66.         cleanup();
  67.         exit(103);
  68.     }
  69.  
  70.     nw.Screen = screen;                /* Open window in our new screen */
  71.     if ( ! (w = (struct Window *)OpenWindow(&nw) ) ) {
  72.         cleanup();
  73.         exit(103);
  74.     }
  75.  
  76.     vp = &screen->ViewPort;             /* Set colors in screen's VP    */
  77.     rp = w->RPort;                      /* Render into the window's RP  */
  78.  
  79.     /*  Set the color registers */
  80.     SetRGB4(vp, 0, 00, 00, 00);
  81.     SetRGB4(vp, 1, 01, 00, 01);    
  82.     SetRGB4(vp, 2, 02, 01, 02);   
  83.     SetRGB4(vp, 3, 03, 02, 03);
  84.     SetRGB4(vp, 4, 04, 03, 04);
  85.     SetRGB4(vp, 5, 05, 04, 05);
  86.     SetRGB4(vp, 6, 06, 05, 06);
  87.     SetRGB4(vp, 7, 07, 06, 07);
  88.     SetRGB4(vp, 8, 08, 07, 08);
  89.     SetRGB4(vp, 9, 09, 08, 09);
  90.     SetRGB4(vp,10, 10, 09, 10);
  91.     SetRGB4(vp,11, 11, 10, 11);
  92.     SetRGB4(vp,12, 12, 11, 12);
  93.     SetRGB4(vp,13, 13, 12, 13);
  94.     SetRGB4(vp,14, 14, 13, 14);
  95.     SetRGB4(vp,15, 15, 15, 15);
  96.  
  97.     show(in);
  98.     
  99.     gets(wait);
  100.  
  101.     cleanup();
  102. }
  103.  
  104. cleanup()
  105. {
  106.     fclose(in);
  107.  
  108.     if (w)
  109.         CloseWindow(w);
  110.  
  111.     if (screen)
  112.         CloseScreen(screen);
  113.  
  114.     if (IntuitionBase)
  115.         CloseLibrary(IntuitionBase);
  116.  
  117.     if (GfxBase)
  118.         CloseLibrary(GfxBase);
  119. }
  120.  
  121. show(in)
  122. FILE    *in;
  123. {
  124.     register    int    k, x, y, xsue, ysue;
  125.     char    buf[512];
  126.     float    big, little;
  127.  
  128.     big = 0.0;
  129.     little = HUGE;
  130.  
  131.     for (ysue = 0; ysue<250; ysue++) {
  132.         if (fgets (buf, 512, in) == NULL)
  133.             break;
  134.  
  135.         /*get rid of EOL that leaves nasty black dots*/
  136.         xsue = strlen (buf) - 1;
  137.  
  138.         for (x = 0; x < xsue; x++) {
  139.  
  140.             k = buf[x];
  141.  
  142.             suzie[x][ysue] = k;
  143.  
  144.             if ( big < (float) k)
  145.                 big = (float) k;
  146.  
  147.             if ( little > (float) k)
  148.                 little = (float) k;
  149.         }
  150.     }
  151.  
  152.     /* expand dynamic range */
  153.     big -= little;
  154.     big /= 16.0;    /* because we only have 16 grey levels */
  155.  
  156.     for (y = 0; y < ysue; y++) {
  157.         for (x = 0; x < xsue; x++) {
  158.             SetAPen(
  159.                 rp,
  160.                 (int) ( ((float)(suzie[x][y])-little) / big )
  161.             );
  162.             WritePixel(rp, x, y);
  163.         }
  164.     }
  165. }
  166.