1 /*
2  * imagesource_Chequerboard.cpp - renders a chequerboard pattern.
3  * Supports Random Access
4  *
5  * Copyright (c) 2008 by Alastair M. Robinson
6  * Distributed under the terms of the GNU General Public License -
7  * see the file named "COPYING" for more details.
8  *
9  */
10 
11 
12 #include <iostream>
13 
14 #include "imagesource_chequerboard.h"
15 
GetRow(int row)16 ISDataType *ImageSource_Chequerboard::GetRow(int row)
17 {
18 	if(currentrow==row)
19 		return(rowbuffer);
20 
21 	int vphase=(row/size)&1;
22 
23 	for(int x=0;x<width;++x)
24 	{
25 		int hphase=(x/size)&1;
26 
27 		if(hphase^vphase)
28 		{
29 			for(int s=0;s<samplesperpixel;++s)
30 				rowbuffer[x*samplesperpixel+s]=fg[s];
31 		}
32 		else
33 		{
34 			for(int s=0;s<samplesperpixel;++s)
35 				rowbuffer[x*samplesperpixel+s]=bg[s];
36 		}
37 	}
38 
39 	currentrow=row;
40 	return(rowbuffer);
41 }
42 
43 
ImageSource_Chequerboard(int width,int height,IS_TYPE type,int samplesperpixel,int size)44 ImageSource_Chequerboard::ImageSource_Chequerboard(int width,int height,IS_TYPE type,int samplesperpixel,int size)
45 	: ImageSource(), size(size), fg(samplesperpixel,IS_SAMPLEMAX), bg(samplesperpixel,0)
46 {
47 	this->type=type;
48 	this->width=width;
49 	this->height=height;
50 	this->samplesperpixel=samplesperpixel;
51 	randomaccess=true;
52 	MakeRowBuffer();
53 }
54 
~ImageSource_Chequerboard()55 
56 ImageSource_Chequerboard::~ImageSource_Chequerboard()
57 {
58 }
59 
SetFG(ISDeviceNValue & col)60 
61 void ImageSource_Chequerboard::SetFG(ISDeviceNValue &col)
62 {
63 	fg=col;
64 }
65 
SetBG(ISDeviceNValue & col)66 
67 void ImageSource_Chequerboard::SetBG(ISDeviceNValue &col)
68 {
69 	bg=col;
70 }
71 
72