#include <exec/types.h>
#include <graphics/gfx.h>
#include <proto/graphics.h>

#define MINX        0
#define MINY        0
#define SIZEX       320
#define SIZEY       200

#define BLT_VANILLA 0x0c0
#define BLT_INVERT  0x030
#define BLT_FLAT    0x088       /* B & C */
#define BLT_PRE_INV 0x022       /* !B & C */
#define BLT_KILL    0x022       /* !B & C */
#define BLT_OR      0x0ee       /* B | C */

void    killcolor(src,col,dst,rep) /*====================================*/
struct BitMap   *src;          /* Display bitmap */
register UWORD  col;           /* Kill color */
register struct BitMap   *dst; /* Mask bitmap. Assumed same rect as bm */
register UWORD  rep;           /* Replacement color */
{
register int     j;
register UBYTE   minterm;
struct BitMap   tempBM;

    tempBM = *src;  tempBM.Depth = 1;
    minterm = (col & 1) ? BLT_VANILLA : BLT_INVERT;
    BltBitMap(&tempBM,MINX,MINY,dst,MINX,MINY,SIZEX,SIZEY,minterm,0x01,NULL);
    for (j = 1; j < src->Depth; j++) {
        tempBM.Planes[0] = src->Planes[j];
        minterm = (col & (UWORD)(1<<j)) ? BLT_FLAT : BLT_PRE_INV;
        BltBitMap(&tempBM,MINX,MINY,dst,MINX,MINY,SIZEX,SIZEY,minterm,0x01,NULL);
    }
    for (j = 0; j < src->Depth; j++) {
        tempBM.Planes[0] = src->Planes[j];
        minterm = (rep & (UWORD)(1<<j)) ? BLT_OR : BLT_KILL;
        BltBitMap(dst,MINX,MINY,&tempBM,MINX,MINY,SIZEX,SIZEY,minterm,0x01,NULL);
    }
}

/*  10 blits all told. This HAS to be the way dpaint does stencils and
 *  color remapping! */
