File size: 1,710 Bytes
7c6501b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include "union.h"

void unionOfImages(qtNode *t1, qtNode *t2, qtNode **res)
{
    (*res) = malloc(sizeof(qtNode));
    if (t1->topLeft != NULL && t2->topLeft != NULL)
    {
        unionOfImages(t1->topLeft, t2->topLeft, &(*res)->topLeft);
        unionOfImages(t1->topRight, t2->topRight, &(*res)->topRight);
        unionOfImages(t1->bottomLeft, t2->bottomLeft, &(*res)->bottomLeft);
        unionOfImages(t1->bottomRight, t2->bottomRight, &(*res)->bottomRight);
    }
    else
    {
        if (t1->topLeft == NULL && t2->topLeft != NULL)
        {
            unionOfImages(t1, t2->topLeft, (&(*res)->topLeft));
            unionOfImages(t1, t2->topRight, &(*res)->topRight);
            unionOfImages(t1, t2->bottomLeft, &(*res)->bottomLeft);
            unionOfImages(t1, t2->bottomRight, &(*res)->bottomRight);
        }
        else
        {
            if (t1->topLeft != NULL && t2->topLeft == NULL)
            {
                unionOfImages(t1->topLeft, t2, &(*res)->topLeft);
                unionOfImages(t1->topRight, t2, &(*res)->topRight);
                unionOfImages(t1->bottomLeft, t2, &(*res)->bottomLeft);
                unionOfImages(t1->bottomRight, t2, &(*res)->bottomRight);
            }
            else
            {

                (*res)->topRight = NULL;
                (*res)->topLeft = NULL;
                (*res)->bottomLeft = NULL;
                (*res)->bottomRight = NULL;
            }
        }
    }
    (*res)->area = min(t1->area, t2->area);
    (*res)->p.blue = (t1->p.blue + t2->p.blue) / 2;
    (*res)->p.red = (t1->p.red + t2->p.red) / 2;
    (*res)->p.green = (t1->p.green + t2->p.green) / 2;

    return;
}