/* Copyright 2008 Jeffrey Lee
   This file is part of GnarlPlot.
   GnarlPlot is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   GnarlPlot is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   along with GnarlPlot.  If not, see <http://www.gnu.org/licenses/>. */

#include <stdio.h>
#include <stdlib.h>

#include "screen.h"
#include "spr.h"

/* Simple GnarlPlot test program. Link it with libgp and libwoum to get it to work. */

int doody(int c, int v)
{
	int r,g,b;
	v+=v >> 7;
	r = c & 255;
	g = (c & 0xFF00) >> 8;
	b = (c & 0xFF0000) >> 16;
	r*=v;
	g*=v;
	b*=v;
	r = r >> 8;
	g = g >> 8;
	b = b >> 8;
	return r + (g << 8) + (b << 16);
}

int main(int argc,char **argv)
{
	gp_screen *scr;
	gp_spr *spr;
	gp_sprfmt *f;
	int x,y;
	scr = gp_screen_new_fromvdu();
	if (scr == 0)
		printf("scr fail\n");
	scr->bank1 = scr->bank0;
	f = &gp_spr_01;
	spr = (f->fromscreen)(f,scr,0,0,scr->width/2,scr->height/2,0,0);
/*	scr->mt = GP_MT_GREY;*/
/*	spr = (gp_spr_20.create)(&gp_spr_20,256,256,0,0);*/
	if (spr == 0)
		printf("spr fail\n");
/*	printf("%dx%d, ps %d, mt %d\n",(spr->f->getw)(spr),(spr->f->geth)(spr),(spr->f->getps)(spr),(spr->f->getmt)(spr));*/
	for (x=0;x<256;x++)
		for (y=0;y<(spr->f->geth)(spr);y++)
		{
			(spr->f->setmask)(spr,x,y,GP_MT_GREY,2,255-x);
			(spr->f->setpix)(spr,x,y,2,doody((spr->f->getpix)(spr,x,y,2),x));
		}
/*	for (x=0;x<256;x++)
		for (y=0;y<256;y++)
			if ((spr->f->setpix)(spr,x,y,2,x+256*y))
				printf("write fail\n");*/
	if ((spr->f->plot)(spr,scr->width/4,scr->height/4,scr))
		printf("plot fail\n");
	return 0;
}
