#ifndef _DRAWXBM
#define _DRAWXBM

#include "co.hpp"

template <Uint16 W, Uint16 H, unsigned char * BITS>
Uint8 XBM(Uint16 x, Uint16 y)
{
	if (W <= x) return 0;
	if (H <= y) return 0;
	unsigned short bytePadedW = W + 8 - (W & 7);
	unsigned int index = ((y * bytePadedW) + x);
	unsigned char bitShift = index & 7;
	unsigned int byteIndex = index >> 3;
	unsigned char byteValue = BITS[byteIndex];
	unsigned char bitMask = 1 << bitShift;
	unsigned char bitValue = bitMask & byteValue;
	return 0 != bitValue;
}

template <Uint16 W, Uint16 H, unsigned char * BITS>
void DrawXBM(Funky<Uint16,Uint16,Uint8> * plote)
{
	for (unsigned short x = 0; x < W; x++)
	for (unsigned short y = 0; y < H; y++)
	if (XBM<W,H,BITS>(x,y)) plote->Trigger(x,y,1);
	else plote->Trigger(x,y,0);
}

#endif
