summaryrefslogtreecommitdiffstats
path: root/chalk/doc/colorstrategyAPI
blob: cc0b1f50dafcce2463f7928f000ff122f9d69df4 (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
This is a working document. It list the places where pixels are mangled and requested functions to do it in an colorstrategy independent way

The purpose is to find out which functions an API in colorstrategy must have to support pixelmangling in a colorstretegy independent manner.


Requested function: apply an alpha mask to pixels
Problem: alpha is hard-coded 8-bit in KisPixel, when it should be free

void KisPaintDevice::clearSelection()
{
	if (!hasSelection()) return;

	QRect r = m_selection -> selectedRect();
	r = r.normalize();

	for (TQ_INT32 y = 0; y < r.height(); y++) {
		KisHLineIterator devIt = createHLineIterator(r.x(), r.y() + y, r.width(), true);
		KisHLineIterator selectionIt = m_selection -> createHLineIterator(r.x(), r.y() + y, r.width(), false);

		while (!devIt.isDone()) {
			KisPixel p = toPixel(devIt.rawData());
			KisPixel s = m_selection -> toPixel(selectionIt.rawData());
			// XXX: Why Q_UIN16 here? Doesn't that clash with UINT8_MULT later on?
			TQ_UINT16 p_alpha, s_alpha;
			p_alpha = p.alpha();
			s_alpha = MAX_SELECTED - s.alpha();

			p.alpha() = UINT8_MULT(p_alpha, s_alpha);

			++devIt;
			++selectionIt;
		}
	}
}

void KisPaintDevice::applySelectionMask(KisSelectionSP mask)
{
	QRect r = mask -> extent();
	crop(r);

	for (TQ_INT32 y = r.top(); y <= r.bottom(); ++y) {

		KisHLineIterator pixelIt = createHLineIterator(r.x(), y, r.width(), true);
		KisHLineIterator maskIt = mask -> createHLineIterator(r.x(), y, r.width(), false);

		while (!pixelIt.isDone()) {

			KisPixel pixel = toPixel(pixelIt.rawData());
			KisPixel maskValue = mask -> toPixel(maskIt.rawData());

			pixel.alpha() = (pixel.alpha() * maskValue.alpha()) / MAX_SELECTED;

			++pixelIt;
			++maskIt;
		}
	}
}