home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / xloadimg.zip / xloadimage.4.1 / fill.c < prev    next >
C/C++ Source or Header  |  1993-10-21  |  2KB  |  70 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, 1991 Jim Frost.
  8.  * See included file "copyright.h" for complete 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, "fill");
  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.   case ITRUE:
  53.     linelen= image->width * image->pixlen;
  54.     start= image->pixlen * fx;
  55.     lineptr= image->data + (linelen * fy);
  56.     for (y= fy; y < fy + fh; y++) {
  57.       pixptr= lineptr + start;
  58.       for (x= fx; x < fw; x++) {
  59.     valToMem(pixval, pixptr, image->pixlen);
  60.     pixptr += image->pixlen;
  61.       }
  62.       lineptr += linelen;
  63.     }
  64.     break;
  65.   default:
  66.     printf("fill: Unsupported image type (ignored)\n");
  67.     return;
  68.   }
  69. }
  70.