home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / atomart.tar.gz / atomart.tar / tile.c < prev    next >
C/C++ Source or Header  |  1990-06-17  |  1KB  |  59 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #ifdef MSC
  4. #include <fcntl.h>
  5. #else
  6. #ifdef SYSV
  7. #include <fcntl.h>
  8. #else
  9. #include <sys/file.h>
  10. #endif
  11. #endif
  12. #include "atomart.h"
  13. #include "gram.h"
  14. #include "macro.h"
  15.  
  16. extern attr    *astackp;
  17.  
  18. /*
  19.  * tileinit
  20.  *
  21.  *    initialise the function pointers and fields for a tile pattern. 
  22.  */
  23. void
  24. tileinit(txt, name, wdim, hdim)
  25.     texture        *txt;
  26.     char        *name;
  27.     double        wdim, hdim;
  28. {
  29.     int    i;
  30.     image    *im;
  31.     char    *cp, *red, *green, *blue, buf[BUFSIZ];
  32.  
  33.     if ((im = openimage(name, "r")) == (image *)NULL) {
  34.         sprintf(buf, "atomart: error opening tile file %s.\n", name);
  35.         fatal(buf);
  36.     }
  37.  
  38.     txt->scalew *= imagewidth(im) / wdim;
  39.     txt->scaleh *= imageheight(im) / hdim;
  40.  
  41.     txt->pixw = imagewidth(im);
  42.     txt->pixh = imageheight(im);
  43.  
  44.     red = (char *)smalloc(imagewidth(im));
  45.     green = (char *)smalloc(imagewidth(im));
  46.     blue = (char *)smalloc(imagewidth(im));
  47.  
  48.     cp = txt->map = (char *)smalloc(imagewidth(im) * imageheight(im) * 3);
  49.  
  50.     while (readrgbline(im, red, green, blue))
  51.         for (i = 0; i < imagewidth(im); i++) {
  52.             *cp++ = red[i];
  53.             *cp++ = green[i];
  54.             *cp++ = blue[i];
  55.         }
  56.  
  57.     closeimage(im);
  58. }
  59.