# include "Ximage.h"

void
DrawBitmap (graphic, x, y, dx, dy, bitmap, mode)
Graphic     graphic[];
int         x, y, dx, dy;
char        bitmap[];
int         mode;
{

  int i, j, byte_line, byte, bit, flag;
  unsigned long int black, white;

  black = graphic[0].black;
  white = graphic[0].white;

  if (mode == 0) {
    black = graphic[0].black;
    white = graphic[0].white;
    graphic[0].black = white;
    graphic[0].white = white;
  }
    
  if (mode == 2) {
    black = graphic[0].black;
    white = graphic[0].white;
    graphic[0].black = white;
    graphic[0].white = black;
  }
    
  
  byte_line = (int) ((dx + 7) / 8);
  for (i = 0; i < dy; i++) {
    for (j = 0; j < dx; j++) {
      byte = byte_line * i + (j / 8);
      bit = j % 8;
      flag = 0x01 & (bitmap[byte] >> bit);
      if (flag)
	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
      else 
	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
      XDrawPoint (graphic[0].display, graphic[0].window, 
		  graphic[0].gc, x + j, y + i);
    }
  }
  if (mode == 0) {
    graphic[0].black = black;
    graphic[0].white = white;
  }
  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
}

