1 #ifndef IMAGESOURCE_COLORIZE_H
2 #define IMAGESOURCE_COLORIZE_H
3 
4 class ImageSource_Colorize : public ImageSource
5 {
6 	public:
ImageSource_Colorize(ImageSource * src,IS_TYPE type,ISDeviceNValue & colour)7 	ImageSource_Colorize(ImageSource *src,IS_TYPE type,ISDeviceNValue &colour) : ImageSource(src), src(src), colour(colour)
8 	{
9 		this->type=type;
10 		samplesperpixel=colour.GetChannels();
11 		MakeRowBuffer();
12 		if(STRIP_ALPHA(src->type)!=IS_TYPE_GREY)
13 			throw "ImageSource_Colorize currently only supports greyscale input";
14 		currentrow=-1;
15 	}
~ImageSource_Colorize()16 	~ImageSource_Colorize()
17 	{
18 		if(src)
19 			delete src;
20 	}
GetRow(int row)21 	ISDataType *GetRow(int row)
22 	{
23 		if(row==currentrow)
24 			return(rowbuffer);
25 		ISDataType *srcdata=src->GetRow(row);
26 
27 		if(HAS_ALPHA(src->type))
28 		{
29 			for(int x=0;x<width;++x)
30 			{
31 				unsigned int t=srcdata[x*2];
32 				for(int s=0;s<samplesperpixel;++s)
33 				{
34 					rowbuffer[x*samplesperpixel+s]=(t*colour[s])/IS_SAMPLEMAX;
35 				}
36 			}
37 		}
38 		else
39 		{
40 			for(int x=0;x<width;++x)
41 			{
42 				unsigned int t=srcdata[x];
43 				for(int s=0;s<samplesperpixel;++s)
44 				{
45 					rowbuffer[x*samplesperpixel+s]=(t*colour[s])/IS_SAMPLEMAX;
46 				}
47 			}
48 		}
49 		currentrow=row;
50 		return(rowbuffer);
51 	}
52 	protected:
53 	ImageSource *src;
54 	ISDeviceNValue &colour;
55 };
56 
57 #endif
58 
59