aboutsummaryrefslogtreecommitdiff
path: root/Plugins/subtract.cpp
blob: a088146be75db3649c01114ab14ea332cc1ef986 (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
//
// subtract - subtract red/green/blue color from image
//
// 0.32
// using arguments-class
//
// 0.20
// - from c to c++
// - pixelformat-aware

#include <stdlib.h>
#include <string.h>
#include "plugin.h"
#include "pixels.h"

INFO("subtract color components");

void perform_effect(_frame f, _args a)
{
	arguments ar(a.s);

	if(ar.count()!=3)
	{
		printf("usage: subtract <red> <green> <blue>\n");
		return;
	}

	byte r, g, b;

	r = atoi(ar[0]);
	g = atoi(ar[1]);
	b = atoi(ar[2]);

	pixels p(f);
	byte tr, tg, tb;

	while(!p.eof())
	{
		tr = p.red();
		tg = p.green();
		tb = p.blue();

		p.putrgb(
		 tr>r ? tr-r : 0,
		 tg>g ? tg-g : 0,
		 tb>b ? tb-b : 0
		);

		p.next();
	}
}