1 #ifndef IMAGESOURCE_TYPES_H
2 #define IMAGESOURCE_TYPES_H
3 
4 #include "../support/debug.h"
5 
6 typedef unsigned short ISDataType;
7 #define IS_SAMPLEMAX 65535
8 #define EIGHTTOIS(x) (((x) << 8) | (x))
9 #define ISTOEIGHT(x) (((x) >> 8) & 0xff )
10 //#define ISTOEIGHT(x) ((((x) * 65281 + 8388608) >> 24) & 0xff)
11 
12 /* Note: 0 is Black for RGB images, but White for Greyscale and CMYK images */
13 
14 enum IS_TYPE {
15 	IS_TYPE_NULL=0,
16 	IS_TYPE_BW,
17 	IS_TYPE_GREY,
18 	IS_TYPE_RGB,
19 	IS_TYPE_CMYK,
20 	IS_TYPE_LAB,
21 	IS_TYPE_DEVICEN,
22 	IS_TYPE_NULLA=8,
23 	IS_TYPE_BWA,
24 	IS_TYPE_GREYA,
25 	IS_TYPE_RGBA,
26 	IS_TYPE_CMYKA,
27 	IS_TYPE_LABA,
28 	IS_TYPE_DEVICENA
29 };
30 
31 #define IS_TYPE_ALPHA 8
32 #define IS_MAX_SAMPLESPERPIXEL 5
33 #define STRIP_ALPHA(x) IS_TYPE(((x)&~IS_TYPE_ALPHA))
34 #define HAS_ALPHA(x) ((x)&IS_TYPE_ALPHA)
35 
36 
37 // DeviceNValue - reallly belongs in a sub-library containing all the specialised
38 // DeviceN stuff, though potentially useful for RGB or CMYK stuff too.
39 
40 class ISDeviceNValue
41 {
42 	public:
channels(channels)43 	ISDeviceNValue(int channels,ISDataType value=0) : channels(channels), values(NULL)
44 	{
45 		values=new ISDataType[channels];
46 		for(int i=0;i<channels;++i)
47 			values[i]=value;
48 	}
ISDeviceNValue(const ISDeviceNValue & other)49 	ISDeviceNValue(const ISDeviceNValue &other) : channels(other.channels), values(NULL)
50 	{
51 		values=new ISDataType[channels];
52 		for(int i=0;i<channels;++i)
53 			values[i]=other[i];
54 	}
~ISDeviceNValue()55 	~ISDeviceNValue()
56 	{
57 		if(values)
58 			delete[] values;
59 	}
60 	ISDataType &operator[](int i) const
61 	{
62 		if(i<channels && i>=0)
63 			return(values[i]);
64 		else
65 			throw "DeviceNValue - bounds check failed";
66 	}
67 	ISDeviceNValue &operator=(const ISDeviceNValue &other)
68 	{
69 		if(channels<other.channels)
70 		{
71 			if(values)
72 				delete[] values;
73 			values=NULL;
74 			channels=other.channels;
75 		}
76 		if(!values)
77 			values=new ISDataType[channels];
78 		for(int i=0;i<channels;++i)
79 			values[i]=other[i];
80 		return(*this);
81 	}
GetChannels()82 	int GetChannels()
83 	{
84 		return(channels);
85 	}
86 	protected:
87 	int channels;
88 	ISDataType *values;
89 };
90 
91 #endif
92