home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume5 / xldimage / part01 / fill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-13  |  1.5 KB  |  69 lines

  1. /* fill.c:
  2.  *
  3.  * fill an image area with a particular pixel value
  4.  *
  5.  * jim frost 10.02.89
  6.  *
  7.  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  8.  * copyright information.
  9.  */
  10.  
  11. #include "copyright.h"
  12. #include "image.h"
  13.  
  14. void fill(image, fx, fy, fw, fh, pixval)
  15.      Image        *image;
  16.      unsigned int  fx, fy, fw, fh;
  17.      Pixel         pixval;
  18. { unsigned int  x, y;
  19.   unsigned int  linelen, start;
  20.   byte         *lineptr, *pixptr;
  21.   byte          startmask, mask;
  22.  
  23.   goodImage(image);
  24.   switch(image->type) {
  25.   case IBITMAP:
  26.  
  27.     /* this could be made a lot faster
  28.      */
  29.  
  30.     linelen= (image->width / 8) + (image->width % 8 ? 1 : 0);
  31.     lineptr= image->data + (linelen * fy);
  32.     start= (fx / 8) + (fx % 8 ? 1 : 0);
  33.     startmask= 0x80 >> (fx % 8);
  34.     for (y= fy; y < fy + fh; y++) {
  35.       mask= startmask;
  36.       pixptr= lineptr + start;
  37.       for (x= fx; x < fw; x++) {
  38.     if (pixval)
  39.       *pixptr |= mask;
  40.     else
  41.       *pixptr &= ~mask;
  42.     if (mask >>= 1) {
  43.       mask= 0x80;
  44.       pixptr++;
  45.     }
  46.       }
  47.       lineptr += linelen;
  48.     }
  49.     break;
  50.  
  51.   case IRGB:
  52.     linelen= image->width * image->pixlen;
  53.     start= image->pixlen * fx;
  54.     lineptr= image->data + (linelen * fy);
  55.     for (y= fy; y < fy + fh; y++) {
  56.       pixptr= lineptr + start;
  57.       for (x= fx; x < fw; x++) {
  58.     valToMem(pixval, pixptr, image->pixlen);
  59.     pixptr += image->pixlen;
  60.       }
  61.       lineptr += linelen;
  62.     }
  63.     break;
  64.   default:
  65.     printf("fill: Unsupported image type (ignored)\n");
  66.     return;
  67.   }
  68. }
  69.