aboutsummaryrefslogtreecommitdiff
path: root/Plugins/pixels.h
blob: 8ea645c6a29d5891afc1b9ac5be3111542a36144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Easy iteration thru pixels, see green.cpp and tile.cpp for examples
// NOTE: using this class could be a bit slower than manipulating the bits directly..
//
// changes to 0.20
// - pixelformat-aware functions red() green() blue() and putrgb()
// - dot16() dot24() and dot32() added
// - get/put dot() removed, use above

#ifndef _PIXELSH
#define _PIXELSH

#include <vector>
#include "plugin.h"

class pixels
{
private:
	_frame m_f;
	pixel8 *p8;	// pointer to a row of 8-bit pixels
	pixel16 *p16;
	pixel24 *p24;
	pixel32 *p32;

	__inline void updaterowp();
public:
	int x, y;

	pixels(const _frame &f)
	{
		m_f = f;
		x = -1;
		y = 0;
		p8 = 0;
		next();
	}

	__inline pixel8 dot8() { return p8[x]; }
	__inline pixel16 dot16() { return p16[x]; }
	__inline pixel24 dot24() { return p24[x]; }
	__inline pixel32 dot32() { return p32[x]; }

	__inline void dot8(pixel8 c) { p8[x] = c; }
	__inline void dot16(pixel16 c) { p16[x] = c; }
	__inline void dot24(pixel24 c) { p24[x] = c; }
	__inline void dot32(pixel32 c) { p32[x] = c; }

	__inline byte red();
	__inline byte green();
	__inline byte blue();

	__inline void putrgb(byte r, byte g, byte b);

	__inline void moveto(int tox, int toy)
	 { if(tox<m_f.width) x=tox; if(toy<m_f.height) { y=toy; updaterowp(); } }

	__inline int eof() { return y==m_f.height ? 1 : 0; }
	void next();

	__inline int width() { return m_f.width; }
	__inline int height() { return m_f.height; }
};

byte pixels::red()
{
	switch(m_f.pixelformat)
	{
		case 16: return r16(p16[x]);
		case 24: return r24(p24[x]);
		case 32: return r32(p32[x]);
		default: return 0;
	}
}

byte pixels::green()
{
	switch(m_f.pixelformat)
	{
		case 16: return g16(p16[x]);
		case 24: return g24(p24[x]);
		case 32: return g32(p32[x]);
		default: return 0;
	}
}

byte pixels::blue()
{
	switch(m_f.pixelformat)
	{
		case 16: return b16(p16[x]);
		case 24: return b24(p24[x]);
		case 32: return b32(p32[x]);
		default: return 0;
	}
}

void pixels::putrgb(byte r, byte g, byte b)
{
	switch(m_f.pixelformat)
	{
		case 16: p16[x] = rgbtocolor16(r, g, b); break;
		case 24: p24[x] = rgbtocolor24(r, g, b); break;
		case 32: p32[x] = rgbtocolor32(r, g, b); break;
	}
}

void pixels::next()
{
	x++;
	if(x==m_f.width) { y++; x=0; p8=0; }
	if(!p8) updaterowp();
}

void pixels::updaterowp()
{
	p8 = scanline(m_f, y);
	p16 = (pixel16 *)p8;
	p24 = (pixel24 *)p8;
	p32 = (pixel32 *)p8;
}

//
// arguments-class, to make it easier to parse parameters.
// using vector<char *> for this might be a bit overkill (??),
// but I like the ease of it.

class arguments
{
private:
	std::vector<char *> m_ptrs;
public:
	arguments(char *s)
	{
		char *t = s;
		if(!t || !t[0]) return;
		if(t[0]) m_ptrs.push_back(t);
		while(t = strstr(t+1, " "))
		{
			t[0]=0;
			m_ptrs.push_back(t+1);
		}
	}
	char *operator[](int i) { return m_ptrs[i]; }
	int count() { return m_ptrs.size(); }
};

#endif // #ifndef _PIXELSH