#include "display.h"

/*
  モノクロ変換 (32k色用)
*/
int	DSP_mono(box_t *b)
{
    int	x, y, a, c;

    for(y = b->y; y <= b->my; y++)
	for(x = b->x; x <= b->mx; x++) {
	    c = DSP_point(1, x, y);
	    a = 0.3 * R(c) + 0.59 * G(c) + 0.11 * B(c);
	    DSP_foreColorIGRB(IGRB(0, a, a, a));
	    DSP_pset(x, y);
	}
}

/*
  モノクロ変換その２ (32k色用)
*/
int	DSP_mono2(box_t *b)
{
    int	 size_x = abs(b->mx - b->x),
	size_y = abs(b->my - b->y),
	data_size, i, c;
    unsigned short int *buf;
    
    data_size = DSP_pic_size(32768, size_x, size_y);
    if((buf = (unsigned short int *)malloc(data_size)) == NULL) return 1;
    
    DSP_get(buf, b);
    
    for(i = 0; i <= data_size; i++) {
	c = 0.3 * ((*(buf + i) & 0x3e0) >> 5) +
	    0.59 * ((*(buf + i) & 0x7c00) >> 10) + 
	    0.11 * (*(buf + i) & 0x1f);
	*(buf + i) = c | (c << 5) | (c << 10);
    }

    DSP_put(buf, b);
    
    free(buf);
    return 0;
}
