aboutsummaryrefslogtreecommitdiff
path: root/Plugins/swap.cpp
blob: 28bacebd6a13116cee6b82643cfbc6400ccf8f03 (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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "plugin.h"
#include "pixels.h"

INFO("swap selected area on two images. usage: swap sourcex1 sourcey1 sourcex2 sourcey2 destx desty")
// (the selection is of equal size on both images)

void swapint(int *a, int *b)
{
	int i = *b;
	*b = *a;
	*a = i;
}

void perform_copy(_frame f1, _frame f2, _args a)
{
	if(!a.s) return;

	// get args
	int sx1, sy1, sx2, sy2, dx1, dy1;
	char *t;

	sx1 = atoi(a.s);
	if(!(t = strstr(a.s, " "))) return;
	sy1 = atoi(t);
	if(!(t = strstr(t+1, " "))) return;
	sx2 = atoi(t);
	if(!(t = strstr(t+1, " "))) return;
	sy2 = atoi(t);
	if(!(t = strstr(t+1, " "))) return;
	dx1 = atoi(t);
	if(!(t = strstr(t+1, " "))) return;
	dy1 = atoi(t);

	if(sx1>sx2) swapint(&sx1, &sx2);
	if(sy1>sy2) swapint(&sy1, &sy2);

printf("swap: %d %d %d %d - %d %d\n", sx1, sy1, sx2, sy2, dx1, dy1);

	int x, y, i, o;
	pixel16 c16;
	pixels p1(f1), p2(f2);

	for(y=sy1; y<=sy2; y++)
		for(x=sx1; x<=sx2; x++)
		{
			if(x>=f1.width || y>=f1.height) continue;
			i = dx1+(x-sx1);
			o = dy1+(y-sy1);
			if(i>=f2.width || o>=f2.height) continue;

			p1.moveto(x, y);
			p2.moveto(i, o);

			c16 = p2.dot16();
			p2.dot16(p1.dot16());
			p1.dot16(c16);
		}
}