Upload 27 files
Browse files- .gitattributes +4 -0
- src/c_project_files/Makefile +16 -0
- src/c_project_files/a.out +0 -0
- src/c_project_files/coep.ppm +3 -0
- src/c_project_files/compress.c +49 -0
- src/c_project_files/compress.h +3 -0
- src/c_project_files/compress.o +0 -0
- src/c_project_files/decompress.c +31 -0
- src/c_project_files/decompress.h +3 -0
- src/c_project_files/decompress.o +0 -0
- src/c_project_files/filters.c +127 -0
- src/c_project_files/filters.h +5 -0
- src/c_project_files/filters.o +0 -0
- src/c_project_files/main.c +423 -0
- src/c_project_files/main.o +0 -0
- src/c_project_files/mona_lisa.ppm +0 -0
- src/c_project_files/rcb.ppm +3 -0
- src/c_project_files/rotate.c +149 -0
- src/c_project_files/rotate.h +6 -0
- src/c_project_files/rotate.o +0 -0
- src/c_project_files/sailboat.ppm +3 -0
- src/c_project_files/squares.ppm +3 -0
- src/c_project_files/suppl.c +206 -0
- src/c_project_files/suppl.h +59 -0
- src/c_project_files/suppl.o +0 -0
- src/c_project_files/union.c +47 -0
- src/c_project_files/union.h +4 -0
- src/c_project_files/union.o +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
src/c_project_files/coep.ppm filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
src/c_project_files/rcb.ppm filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
src/c_project_files/sailboat.ppm filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
src/c_project_files/squares.ppm filter=lfs diff=lfs merge=lfs -text
|
src/c_project_files/Makefile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
final: rotate.o suppl.o decompress.o compress.o main.o filters.o union.o
|
| 2 |
+
cc rotate.o suppl.o decompress.o compress.o main.o filters.o union.o -o final -lm
|
| 3 |
+
rotate.o: rotate.c rotate.h
|
| 4 |
+
cc -c rotate.c
|
| 5 |
+
suppl.o: suppl.c suppl.h
|
| 6 |
+
cc -c suppl.c
|
| 7 |
+
decompress.o: decompress.c decompress.h
|
| 8 |
+
cc -c decompress.c
|
| 9 |
+
compress.o: compress.c compress.h
|
| 10 |
+
cc -c compress.c
|
| 11 |
+
main.o: main.c filters.h
|
| 12 |
+
cc -c main.c
|
| 13 |
+
filters.o: filters.c filters.h
|
| 14 |
+
cc -c filters.c
|
| 15 |
+
union.o: union.c union.h
|
| 16 |
+
cc -c union.c
|
src/c_project_files/a.out
ADDED
|
Binary file (30.2 kB). View file
|
|
|
src/c_project_files/coep.ppm
ADDED
|
|
Git LFS Details
|
src/c_project_files/compress.c
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "compress.h"
|
| 2 |
+
|
| 3 |
+
//------------------------COMPRESSION FUNCTION-------------------------------//
|
| 4 |
+
void compressImage(pixels **matrix, qtNode **t, int x, int y, int size, int reqFactor)
|
| 5 |
+
{
|
| 6 |
+
int mean = getMean(matrix, t, x, y, size);
|
| 7 |
+
int i, j;
|
| 8 |
+
unsigned long long int blue = 0, green = 0, red = 0;
|
| 9 |
+
|
| 10 |
+
(*t) = malloc(sizeof(qtNode));
|
| 11 |
+
(*t)->area = size * size;
|
| 12 |
+
|
| 13 |
+
for (i = y; i < y + size; i++)
|
| 14 |
+
{
|
| 15 |
+
for (j = x; j < x + size; j++)
|
| 16 |
+
{
|
| 17 |
+
blue = blue + matrix[i][j].blue;
|
| 18 |
+
green = green + matrix[i][j].green;
|
| 19 |
+
red = red + matrix[i][j].red;
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
blue = blue / ((*t)->area);
|
| 24 |
+
red = red / ((*t)->area);
|
| 25 |
+
green = green / ((*t)->area);
|
| 26 |
+
|
| 27 |
+
(*t)->p.blue = blue;
|
| 28 |
+
(*t)->p.red = red;
|
| 29 |
+
(*t)->p.green = green;
|
| 30 |
+
|
| 31 |
+
// Traversal condition
|
| 32 |
+
if (mean > reqFactor)
|
| 33 |
+
{
|
| 34 |
+
compressImage(matrix, &(*t)->topLeft, x, y, size / 2, reqFactor);
|
| 35 |
+
compressImage(matrix, &(*t)->topRight, x + (size / 2), y, size / 2, reqFactor);
|
| 36 |
+
compressImage(matrix, &(*t)->bottomRight, x + (size / 2), y + (size / 2), size / 2, reqFactor);
|
| 37 |
+
compressImage(matrix, &(*t)->bottomLeft, x, y + (size / 2), size / 2, reqFactor);
|
| 38 |
+
|
| 39 |
+
return;
|
| 40 |
+
}
|
| 41 |
+
else
|
| 42 |
+
{
|
| 43 |
+
(*t)->topRight = NULL;
|
| 44 |
+
(*t)->topLeft = NULL;
|
| 45 |
+
(*t)->bottomLeft = NULL;
|
| 46 |
+
(*t)->bottomRight = NULL;
|
| 47 |
+
return;
|
| 48 |
+
}
|
| 49 |
+
}
|
src/c_project_files/compress.h
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "suppl.h"
|
| 2 |
+
|
| 3 |
+
void compressImage(pixels **matrix, qtNode **node, int x, int y, int size, int threshold);
|
src/c_project_files/compress.o
ADDED
|
Binary file (2.36 kB). View file
|
|
|
src/c_project_files/decompress.c
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "decompress.h"
|
| 2 |
+
|
| 3 |
+
//--------------------DECOMPRESSION FUNCTION----------------------------------//
|
| 4 |
+
|
| 5 |
+
void decompressImage(qtNode *node, pixels ***imageMatrix, int startX, int startY, int blockSize)
|
| 6 |
+
{
|
| 7 |
+
int i, j;
|
| 8 |
+
|
| 9 |
+
// already optimized tree
|
| 10 |
+
if (node->topLeft == NULL && node->topRight == NULL && node->bottomLeft == NULL && node->bottomRight == NULL)
|
| 11 |
+
{
|
| 12 |
+
for (i = startY; i < startY + blockSize; i++)
|
| 13 |
+
{
|
| 14 |
+
for (j = startX; j < startX + blockSize; j++)
|
| 15 |
+
{
|
| 16 |
+
(*imageMatrix)[i][j].red = node->p.red;
|
| 17 |
+
(*imageMatrix)[i][j].green = node->p.green;
|
| 18 |
+
(*imageMatrix)[i][j].blue = node->p.blue;
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
// decompress till tree is optimized
|
| 23 |
+
else
|
| 24 |
+
{
|
| 25 |
+
decompressImage(node->topLeft, imageMatrix, startX, startY, blockSize / 2);
|
| 26 |
+
decompressImage(node->topRight, imageMatrix, startX + (blockSize / 2), startY, blockSize / 2);
|
| 27 |
+
decompressImage(node->bottomRight, imageMatrix, startX + (blockSize / 2), startY + (blockSize / 2), blockSize / 2);
|
| 28 |
+
decompressImage(node->bottomLeft, imageMatrix, startX, startY + (blockSize / 2), blockSize / 2);
|
| 29 |
+
}
|
| 30 |
+
}
|
| 31 |
+
|
src/c_project_files/decompress.h
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "compress.h"
|
| 2 |
+
|
| 3 |
+
void decompressImage(qtNode *node, pixels ***matrix, int x, int y, int size);
|
src/c_project_files/decompress.o
ADDED
|
Binary file (1.96 kB). View file
|
|
|
src/c_project_files/filters.c
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "filters.h"
|
| 2 |
+
|
| 3 |
+
void grayScale(qtNode *t1, qtNode **res)
|
| 4 |
+
{
|
| 5 |
+
(*res) = malloc(sizeof(qtNode));
|
| 6 |
+
if (t1->topLeft != NULL)
|
| 7 |
+
{
|
| 8 |
+
grayScale(t1->topLeft, &(*res)->topLeft);
|
| 9 |
+
grayScale(t1->topRight, &(*res)->topRight);
|
| 10 |
+
grayScale(t1->bottomLeft, &(*res)->bottomLeft);
|
| 11 |
+
grayScale(t1->bottomRight, &(*res)->bottomRight);
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
else
|
| 15 |
+
{
|
| 16 |
+
|
| 17 |
+
(*res)->topRight = NULL;
|
| 18 |
+
(*res)->topLeft = NULL;
|
| 19 |
+
(*res)->bottomLeft = NULL;
|
| 20 |
+
(*res)->bottomRight = NULL;
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
(*res)->area = t1->area;
|
| 24 |
+
(*res)->p.red = t1->p.red * 0.3;
|
| 25 |
+
(*res)->p.blue = t1->p.green * 0.59;
|
| 26 |
+
(*res)->p.green = t1->p.blue * 0.11;
|
| 27 |
+
(*res)->area = t1->area;
|
| 28 |
+
|
| 29 |
+
return;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
void brighten(qtNode *t1, qtNode **res)
|
| 33 |
+
{
|
| 34 |
+
(*res) = malloc(sizeof(qtNode));
|
| 35 |
+
if (t1->topLeft != NULL)
|
| 36 |
+
{
|
| 37 |
+
brighten(t1->topLeft, &(*res)->topLeft);
|
| 38 |
+
brighten(t1->topRight, &(*res)->topRight);
|
| 39 |
+
brighten(t1->bottomLeft, &(*res)->bottomLeft);
|
| 40 |
+
brighten(t1->bottomRight, &(*res)->bottomRight);
|
| 41 |
+
}
|
| 42 |
+
else
|
| 43 |
+
{
|
| 44 |
+
(*res)->topRight = NULL;
|
| 45 |
+
(*res)->topLeft = NULL;
|
| 46 |
+
(*res)->bottomLeft = NULL;
|
| 47 |
+
(*res)->bottomRight = NULL;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
(*res)->area = t1->area;
|
| 51 |
+
// Brighten the image by increasing the color channels
|
| 52 |
+
double brightnessFactor = 1.2; // Adjust this factor to control the brightness
|
| 53 |
+
(*res)->p.red = t1->p.red * brightnessFactor;
|
| 54 |
+
(*res)->p.green = t1->p.green * brightnessFactor;
|
| 55 |
+
(*res)->p.blue = t1->p.blue * brightnessFactor;
|
| 56 |
+
|
| 57 |
+
return;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
void negativeImage(qtNode *t1, qtNode **res)
|
| 64 |
+
{
|
| 65 |
+
(*res) = malloc(sizeof(qtNode));
|
| 66 |
+
if (t1->topLeft != NULL)
|
| 67 |
+
{
|
| 68 |
+
negativeImage(t1->topLeft, &(*res)->topLeft);
|
| 69 |
+
negativeImage(t1->topRight, &(*res)->topRight);
|
| 70 |
+
negativeImage(t1->bottomLeft, &(*res)->bottomLeft);
|
| 71 |
+
negativeImage(t1->bottomRight, &(*res)->bottomRight);
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
else
|
| 75 |
+
{
|
| 76 |
+
|
| 77 |
+
(*res)->topRight = NULL;
|
| 78 |
+
(*res)->topLeft = NULL;
|
| 79 |
+
(*res)->bottomLeft = NULL;
|
| 80 |
+
(*res)->bottomRight = NULL;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
(*res)->area = t1->area;
|
| 84 |
+
(*res)->p.red = (t1->p.red <= 255) ? 255 - t1->p.red : 0;
|
| 85 |
+
(*res)->p.blue = (t1->p.blue <= 255) ? 255 - t1->p.blue : 0;
|
| 86 |
+
(*res)->p.green = (t1->p.green <= 255) ? 255 - t1->p.green : 0;
|
| 87 |
+
(*res)->area = t1->area;
|
| 88 |
+
|
| 89 |
+
return;
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
void sepia(qtNode* t1,qtNode** res)
|
| 93 |
+
{
|
| 94 |
+
(*res) = malloc(sizeof(qtNode));
|
| 95 |
+
|
| 96 |
+
if (t1->topLeft != NULL)
|
| 97 |
+
{
|
| 98 |
+
sepia(t1->topLeft, &(*res)->topLeft);
|
| 99 |
+
sepia(t1->topRight, &(*res)->topRight);
|
| 100 |
+
sepia(t1->bottomLeft, &(*res)->bottomLeft);
|
| 101 |
+
sepia(t1->bottomRight, &(*res)->bottomRight);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
else
|
| 105 |
+
{
|
| 106 |
+
|
| 107 |
+
(*res)->topRight = NULL;
|
| 108 |
+
(*res)->topLeft = NULL;
|
| 109 |
+
(*res)->bottomLeft = NULL;
|
| 110 |
+
(*res)->bottomRight = NULL;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
(*res)->area = t1->area;
|
| 114 |
+
(*res)->p.red = 0.393 * t1->p.red + 0.769 * t1->p.green + 0.189 * t1->p.blue;
|
| 115 |
+
(*res)->p.blue = 0.349 * t1->p.red + 0.686 * t1->p.green + 0.168 * t1->p.blue;
|
| 116 |
+
(*res)->p.green = 0.272 * t1->p.red + 0.534 * t1->p.green + 0.131 * t1->p.blue;
|
| 117 |
+
|
| 118 |
+
// Ensure that the color values don't exceed 255
|
| 119 |
+
(*res)->p.red = (*res)->p.red <= 255 ? (*res)->p.red : 255;
|
| 120 |
+
(*res)->p.blue = (*res)->p.blue <= 255 ? (*res)->p.blue : 255;
|
| 121 |
+
(*res)->p.green = (*res)->p.green <= 255 ? (*res)->p.green : 255;
|
| 122 |
+
|
| 123 |
+
(*res)->area = t1->area;
|
| 124 |
+
|
| 125 |
+
return;
|
| 126 |
+
|
| 127 |
+
}
|
src/c_project_files/filters.h
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "union.h"
|
| 2 |
+
|
| 3 |
+
void grayScale(qtNode* t1,qtNode** res);
|
| 4 |
+
void negativeImage(qtNode* t,qtNode** res);
|
| 5 |
+
void sepia(qtNode* t1,qtNode** res);
|
src/c_project_files/filters.o
ADDED
|
Binary file (3.67 kB). View file
|
|
|
src/c_project_files/main.c
ADDED
|
@@ -0,0 +1,423 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <stdlib.h>
|
| 3 |
+
#include <string.h>
|
| 4 |
+
#include <math.h>
|
| 5 |
+
#include "filters.h"
|
| 6 |
+
|
| 7 |
+
int main(int argc, char *argv[])
|
| 8 |
+
{
|
| 9 |
+
// compression
|
| 10 |
+
if (strcmp(argv[1], "-c") == 0)
|
| 11 |
+
{
|
| 12 |
+
unsigned int index = 0;
|
| 13 |
+
unsigned int i;
|
| 14 |
+
int factor, width, height;
|
| 15 |
+
|
| 16 |
+
pixels **r;
|
| 17 |
+
qtNode *node = NULL;
|
| 18 |
+
|
| 19 |
+
r = read(&height, &width, argv[3]);
|
| 20 |
+
compressImage(r, &node, 0, 0, width, atoi(argv[2]));
|
| 21 |
+
|
| 22 |
+
// Vector of pointers to the tree nodes
|
| 23 |
+
qtNode **vector = malloc(sizeof(qtNode *));
|
| 24 |
+
traversal(node, &vector, &index);
|
| 25 |
+
|
| 26 |
+
qtInfo *vec = malloc(sizeof(qtInfo) * index);
|
| 27 |
+
copyToArr(vector, &vec, index);
|
| 28 |
+
|
| 29 |
+
for (i = 0; i < index; i++)
|
| 30 |
+
free(vector[i]);
|
| 31 |
+
free(vector);
|
| 32 |
+
|
| 33 |
+
// Write vector in a file
|
| 34 |
+
FILE *f = fopen(argv[4], "wb");
|
| 35 |
+
// fprintf(f, "P6\n");------------------>segmentation error!
|
| 36 |
+
// fprintf(f, "%d %d\n", width, width);
|
| 37 |
+
// fprintf(f, "255\n");
|
| 38 |
+
|
| 39 |
+
unsigned int count = 0;
|
| 40 |
+
for (i = 0; i < index; i++)
|
| 41 |
+
{
|
| 42 |
+
if (vec[i].topLeft == -1)
|
| 43 |
+
{
|
| 44 |
+
count++;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
fwrite(&count, sizeof(int), 1, f);
|
| 49 |
+
fwrite(&index, sizeof(int), 1, f);
|
| 50 |
+
|
| 51 |
+
for (i = 0; i < index; i++)
|
| 52 |
+
{
|
| 53 |
+
fwrite(&vec[i], sizeof(qtInfo), 1, f);
|
| 54 |
+
if (vec[i].topLeft == -1)
|
| 55 |
+
{
|
| 56 |
+
count++;
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
free(vec);
|
| 60 |
+
fclose(f);
|
| 61 |
+
}
|
| 62 |
+
// decompression
|
| 63 |
+
else if (strcmp(argv[1], "-d") == 0)
|
| 64 |
+
{
|
| 65 |
+
|
| 66 |
+
unsigned int index, i;
|
| 67 |
+
unsigned int colors;
|
| 68 |
+
|
| 69 |
+
FILE *f = fopen(argv[2], "rb");
|
| 70 |
+
fread(&colors, sizeof(int), 1, f);
|
| 71 |
+
// Read number of nodes
|
| 72 |
+
fread(&index, sizeof(int), 1, f);
|
| 73 |
+
|
| 74 |
+
qtInfo *vec = malloc(sizeof(qtInfo) * index);
|
| 75 |
+
|
| 76 |
+
// Read node vector
|
| 77 |
+
fread(vec, sizeof(qtInfo), index, f);
|
| 78 |
+
fclose(f);
|
| 79 |
+
|
| 80 |
+
qtNode *node = NULL;
|
| 81 |
+
readTree(vec, &node, 0);
|
| 82 |
+
free(vec);
|
| 83 |
+
|
| 84 |
+
int size = sqrt(node->area);
|
| 85 |
+
|
| 86 |
+
// Alloc pixels matrix
|
| 87 |
+
pixels **mat = (pixels **)malloc(sizeof(pixels *) * size);
|
| 88 |
+
for (i = 0; i < size; i++)
|
| 89 |
+
{
|
| 90 |
+
mat[i] = malloc(sizeof(pixels) * size);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
decompressImage(node, &mat, 0, 0, size);
|
| 94 |
+
outputFile(mat, argv[3], size);
|
| 95 |
+
}
|
| 96 |
+
// mirroring
|
| 97 |
+
else if (strcmp(argv[1], "-r") == 0)
|
| 98 |
+
{
|
| 99 |
+
unsigned int i;
|
| 100 |
+
int factor, width, height;
|
| 101 |
+
pixels **r;
|
| 102 |
+
qtNode *t = NULL;
|
| 103 |
+
|
| 104 |
+
factor = atoi(argv[3]);
|
| 105 |
+
r = read(&height, &width, argv[4]);
|
| 106 |
+
|
| 107 |
+
compressImage(r, &t, 0, 0, width, factor);
|
| 108 |
+
|
| 109 |
+
if (strcmp(argv[2], "w") == 0)
|
| 110 |
+
{
|
| 111 |
+
getWaterImage(&t);
|
| 112 |
+
}
|
| 113 |
+
else if (strcmp(argv[2], "m") == 0)
|
| 114 |
+
{
|
| 115 |
+
getMirrorImage(&t);
|
| 116 |
+
}
|
| 117 |
+
else if (strcmp(argv[2], "l90") == 0)
|
| 118 |
+
{
|
| 119 |
+
rotateLeft(&t);
|
| 120 |
+
}
|
| 121 |
+
else if (strcmp(argv[2], "r90") == 0)
|
| 122 |
+
{
|
| 123 |
+
rotateRight(&t);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Alloc p matrix
|
| 127 |
+
pixels **mat = (pixels **)malloc(sizeof(pixels *) * width);
|
| 128 |
+
for (i = 0; i < width; i++)
|
| 129 |
+
{
|
| 130 |
+
mat[i] = malloc(sizeof(pixels) * width);
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
decompressImage(t, &mat, 0, 0, width);
|
| 134 |
+
outputFile(mat, argv[5], width);
|
| 135 |
+
|
| 136 |
+
for (i = 0; i < width; i++)
|
| 137 |
+
{
|
| 138 |
+
free(mat[i]);
|
| 139 |
+
}
|
| 140 |
+
free(mat);
|
| 141 |
+
|
| 142 |
+
for (i = 0; i < height; i++)
|
| 143 |
+
{
|
| 144 |
+
free(r[i]);
|
| 145 |
+
}
|
| 146 |
+
free(r);
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// else if (strcmp(argv[1], "-f") == 0)
|
| 150 |
+
// {
|
| 151 |
+
// printf("hi");
|
| 152 |
+
// unsigned int i;
|
| 153 |
+
// int factor, width, height;
|
| 154 |
+
// pixels **r;
|
| 155 |
+
// qtNode *t = NULL;
|
| 156 |
+
// qtNode *res = NULL;
|
| 157 |
+
|
| 158 |
+
// factor = atoi(argv[3]);
|
| 159 |
+
// r = read(&height, &width, argv[4]);
|
| 160 |
+
|
| 161 |
+
// compressImage(r, &t, 0, 0, width, factor);
|
| 162 |
+
|
| 163 |
+
// if (strcmp(argv[2], "g") == 0)
|
| 164 |
+
// {
|
| 165 |
+
// grayScale(t, &res);
|
| 166 |
+
// }
|
| 167 |
+
// // else if (strcmp(argv[2], "n") == 0)
|
| 168 |
+
// // {
|
| 169 |
+
// // negativeImage(t,&res);
|
| 170 |
+
// // }
|
| 171 |
+
|
| 172 |
+
// // Alloc p matrix
|
| 173 |
+
// pixels **mat = (pixels **)malloc(sizeof(pixels *) * width);
|
| 174 |
+
// for (i = 0; i < width; i++)
|
| 175 |
+
// {
|
| 176 |
+
// mat[i] = malloc(sizeof(pixels) * width);
|
| 177 |
+
// }
|
| 178 |
+
|
| 179 |
+
// decompressImage(res, &mat, 0, 0, width);
|
| 180 |
+
// // outputFile(mat, argv[5], width);
|
| 181 |
+
// // destroyTree(&t);
|
| 182 |
+
|
| 183 |
+
// // for (i = 0; i < width; i++)
|
| 184 |
+
// // {
|
| 185 |
+
// // free(mat[i]);
|
| 186 |
+
// // }
|
| 187 |
+
// // free(mat);
|
| 188 |
+
|
| 189 |
+
// // for (i = 0; i < height; i++)
|
| 190 |
+
// // {
|
| 191 |
+
// // free(r[i]);
|
| 192 |
+
// // }
|
| 193 |
+
// // free(r);
|
| 194 |
+
// }
|
| 195 |
+
|
| 196 |
+
else
|
| 197 |
+
{
|
| 198 |
+
if (strcmp(argv[1], "-g") == 0)
|
| 199 |
+
{
|
| 200 |
+
unsigned int i;
|
| 201 |
+
int threshold, width, height;
|
| 202 |
+
|
| 203 |
+
pixels **r1;
|
| 204 |
+
pixels **r2;
|
| 205 |
+
|
| 206 |
+
qtNode *t1 = NULL;
|
| 207 |
+
qtNode *t2 = NULL;
|
| 208 |
+
|
| 209 |
+
threshold = atoi(argv[2]);
|
| 210 |
+
|
| 211 |
+
r1 = read(&height, &width, argv[3]);
|
| 212 |
+
r2 = read(&height, &width, argv[4]);
|
| 213 |
+
|
| 214 |
+
compressImage(r1, &t1, 0, 0, width, threshold);
|
| 215 |
+
compressImage(r2, &t2, 0, 0, width, threshold);
|
| 216 |
+
|
| 217 |
+
qtNode *node_overlay = NULL;
|
| 218 |
+
grayScale(t1, &node_overlay);
|
| 219 |
+
|
| 220 |
+
// Alloc rgb matrix
|
| 221 |
+
pixels **mat = (pixels **)malloc(sizeof(pixels *) * width);
|
| 222 |
+
for (i = 0; i < width; i++)
|
| 223 |
+
{
|
| 224 |
+
mat[i] = malloc(sizeof(pixels) * width);
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
decompressImage(node_overlay, &mat, 0, 0, width);
|
| 228 |
+
outputFile(mat, argv[5], width);
|
| 229 |
+
|
| 230 |
+
// Free
|
| 231 |
+
destroyTree(&t1);
|
| 232 |
+
destroyTree(&t2);
|
| 233 |
+
|
| 234 |
+
for (i = 0; i < width; i++)
|
| 235 |
+
{
|
| 236 |
+
free(mat[i]);
|
| 237 |
+
}
|
| 238 |
+
free(mat);
|
| 239 |
+
|
| 240 |
+
for (i = 0; i < height; i++)
|
| 241 |
+
{
|
| 242 |
+
free(r1[i]);
|
| 243 |
+
}
|
| 244 |
+
free(r1);
|
| 245 |
+
|
| 246 |
+
for (i = 0; i < height; i++)
|
| 247 |
+
{
|
| 248 |
+
free(r2[i]);
|
| 249 |
+
}
|
| 250 |
+
free(r2);
|
| 251 |
+
}
|
| 252 |
+
|
| 253 |
+
if (strcmp(argv[1], "-n") == 0)
|
| 254 |
+
{
|
| 255 |
+
unsigned int i;
|
| 256 |
+
int threshold, width, height;
|
| 257 |
+
|
| 258 |
+
pixels **r1;
|
| 259 |
+
pixels **r2;
|
| 260 |
+
|
| 261 |
+
qtNode *t1 = NULL;
|
| 262 |
+
qtNode *t2 = NULL;
|
| 263 |
+
|
| 264 |
+
threshold = atoi(argv[2]);
|
| 265 |
+
|
| 266 |
+
r1 = read(&height, &width, argv[3]);
|
| 267 |
+
r2 = read(&height, &width, argv[4]);
|
| 268 |
+
|
| 269 |
+
compressImage(r1, &t1, 0, 0, width, threshold);
|
| 270 |
+
compressImage(r2, &t2, 0, 0, width, threshold);
|
| 271 |
+
|
| 272 |
+
qtNode *node_overlay = NULL;
|
| 273 |
+
negativeImage(t1, &node_overlay);
|
| 274 |
+
|
| 275 |
+
// Alloc rgb matrix
|
| 276 |
+
pixels **mat = (pixels **)malloc(sizeof(pixels *) * width);
|
| 277 |
+
for (i = 0; i < width; i++)
|
| 278 |
+
{
|
| 279 |
+
mat[i] = malloc(sizeof(pixels) * width);
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
decompressImage(node_overlay, &mat, 0, 0, width);
|
| 283 |
+
outputFile(mat, argv[5], width);
|
| 284 |
+
|
| 285 |
+
// Free
|
| 286 |
+
destroyTree(&t1);
|
| 287 |
+
destroyTree(&t2);
|
| 288 |
+
|
| 289 |
+
for (i = 0; i < width; i++)
|
| 290 |
+
{
|
| 291 |
+
free(mat[i]);
|
| 292 |
+
}
|
| 293 |
+
free(mat);
|
| 294 |
+
|
| 295 |
+
for (i = 0; i < height; i++)
|
| 296 |
+
{
|
| 297 |
+
free(r1[i]);
|
| 298 |
+
}
|
| 299 |
+
free(r1);
|
| 300 |
+
|
| 301 |
+
for (i = 0; i < height; i++)
|
| 302 |
+
{
|
| 303 |
+
free(r2[i]);
|
| 304 |
+
}
|
| 305 |
+
free(r2);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
if (strcmp(argv[1], "-s") == 0)
|
| 309 |
+
{
|
| 310 |
+
unsigned int i;
|
| 311 |
+
int threshold, width, height;
|
| 312 |
+
|
| 313 |
+
pixels **r1;
|
| 314 |
+
pixels **r2;
|
| 315 |
+
|
| 316 |
+
qtNode *t1 = NULL;
|
| 317 |
+
qtNode *t2 = NULL;
|
| 318 |
+
|
| 319 |
+
threshold = atoi(argv[2]);
|
| 320 |
+
|
| 321 |
+
r1 = read(&height, &width, argv[3]);
|
| 322 |
+
r2 = read(&height, &width, argv[4]);
|
| 323 |
+
|
| 324 |
+
compressImage(r1, &t1, 0, 0, width, threshold);
|
| 325 |
+
compressImage(r2, &t2, 0, 0, width, threshold);
|
| 326 |
+
|
| 327 |
+
qtNode *node_overlay = NULL;
|
| 328 |
+
sepia(t1, &node_overlay);
|
| 329 |
+
|
| 330 |
+
// Alloc rgb matrix
|
| 331 |
+
pixels **mat = (pixels **)malloc(sizeof(pixels *) * width);
|
| 332 |
+
for (i = 0; i < width; i++)
|
| 333 |
+
{
|
| 334 |
+
mat[i] = malloc(sizeof(pixels) * width);
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
decompressImage(node_overlay, &mat, 0, 0, width);
|
| 338 |
+
outputFile(mat, argv[5], width);
|
| 339 |
+
|
| 340 |
+
// Free
|
| 341 |
+
destroyTree(&t1);
|
| 342 |
+
destroyTree(&t2);
|
| 343 |
+
|
| 344 |
+
for (i = 0; i < width; i++)
|
| 345 |
+
{
|
| 346 |
+
free(mat[i]);
|
| 347 |
+
}
|
| 348 |
+
free(mat);
|
| 349 |
+
|
| 350 |
+
for (i = 0; i < height; i++)
|
| 351 |
+
{
|
| 352 |
+
free(r1[i]);
|
| 353 |
+
}
|
| 354 |
+
free(r1);
|
| 355 |
+
|
| 356 |
+
for (i = 0; i < height; i++)
|
| 357 |
+
{
|
| 358 |
+
free(r2[i]);
|
| 359 |
+
}
|
| 360 |
+
free(r2);
|
| 361 |
+
}
|
| 362 |
+
|
| 363 |
+
// union of two images
|
| 364 |
+
else
|
| 365 |
+
{
|
| 366 |
+
if (strcmp(argv[1], "-u") == 0)
|
| 367 |
+
{
|
| 368 |
+
unsigned int i;
|
| 369 |
+
int threshold, width, height;
|
| 370 |
+
|
| 371 |
+
pixels **r1;
|
| 372 |
+
pixels **r2;
|
| 373 |
+
|
| 374 |
+
qtNode *t1 = NULL;
|
| 375 |
+
qtNode *t2 = NULL;
|
| 376 |
+
|
| 377 |
+
threshold = atoi(argv[2]);
|
| 378 |
+
|
| 379 |
+
r1 = read(&height, &width, argv[3]);
|
| 380 |
+
r2 = read(&height, &width, argv[4]);
|
| 381 |
+
|
| 382 |
+
compressImage(r1, &t1, 0, 0, width, threshold);
|
| 383 |
+
compressImage(r2, &t2, 0, 0, width, threshold);
|
| 384 |
+
|
| 385 |
+
qtNode *node_overlay = NULL;
|
| 386 |
+
unionOfImages(t1, t2, &node_overlay);
|
| 387 |
+
|
| 388 |
+
// Alloc rgb matrix
|
| 389 |
+
pixels **mat = (pixels **)malloc(sizeof(pixels *) * width);
|
| 390 |
+
for (i = 0; i < width; i++)
|
| 391 |
+
{
|
| 392 |
+
mat[i] = malloc(sizeof(pixels) * width);
|
| 393 |
+
}
|
| 394 |
+
|
| 395 |
+
decompressImage(node_overlay, &mat, 0, 0, width);
|
| 396 |
+
outputFile(mat, argv[5], width);
|
| 397 |
+
|
| 398 |
+
// Free
|
| 399 |
+
destroyTree(&t1);
|
| 400 |
+
destroyTree(&t2);
|
| 401 |
+
|
| 402 |
+
for (i = 0; i < width; i++)
|
| 403 |
+
{
|
| 404 |
+
free(mat[i]);
|
| 405 |
+
}
|
| 406 |
+
free(mat);
|
| 407 |
+
|
| 408 |
+
for (i = 0; i < height; i++)
|
| 409 |
+
{
|
| 410 |
+
free(r1[i]);
|
| 411 |
+
}
|
| 412 |
+
free(r1);
|
| 413 |
+
|
| 414 |
+
for (i = 0; i < height; i++)
|
| 415 |
+
{
|
| 416 |
+
free(r2[i]);
|
| 417 |
+
}
|
| 418 |
+
free(r2);
|
| 419 |
+
}
|
| 420 |
+
}
|
| 421 |
+
}
|
| 422 |
+
return 0;
|
| 423 |
+
}
|
src/c_project_files/main.o
ADDED
|
Binary file (10.7 kB). View file
|
|
|
src/c_project_files/mona_lisa.ppm
ADDED
|
|
src/c_project_files/rcb.ppm
ADDED
|
|
Git LFS Details
|
src/c_project_files/rotate.c
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "rotate.h"
|
| 2 |
+
|
| 3 |
+
// flip the image along the vertical axis
|
| 4 |
+
void getWaterImage(qtNode **t)
|
| 5 |
+
{
|
| 6 |
+
if ((*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL)
|
| 7 |
+
{
|
| 8 |
+
qtNode *temp;
|
| 9 |
+
|
| 10 |
+
getWaterImage(&(*t)->topLeft);
|
| 11 |
+
getWaterImage(&(*t)->topRight);
|
| 12 |
+
getWaterImage(&(*t)->bottomRight);
|
| 13 |
+
getWaterImage(&(*t)->bottomLeft);
|
| 14 |
+
|
| 15 |
+
temp = (*t)->topLeft;
|
| 16 |
+
(*t)->topLeft = (*t)->bottomLeft;
|
| 17 |
+
(*t)->bottomLeft = temp;
|
| 18 |
+
|
| 19 |
+
temp = (*t)->topRight;
|
| 20 |
+
(*t)->topRight = (*t)->bottomRight;
|
| 21 |
+
(*t)->bottomRight = temp;
|
| 22 |
+
}
|
| 23 |
+
// empty tree condition
|
| 24 |
+
else
|
| 25 |
+
{
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
// flip the image along the horizontal axis
|
| 31 |
+
void getMirrorImage(qtNode **node)
|
| 32 |
+
{
|
| 33 |
+
if ((*node)->topLeft != NULL && (*node)->topLeft != NULL && (*node)->topLeft != NULL && (*node)->topLeft != NULL)
|
| 34 |
+
{
|
| 35 |
+
qtNode *temp;
|
| 36 |
+
|
| 37 |
+
getMirrorImage(&(*node)->topLeft);
|
| 38 |
+
getMirrorImage(&(*node)->topRight);
|
| 39 |
+
getMirrorImage(&(*node)->bottomRight);
|
| 40 |
+
getMirrorImage(&(*node)->bottomLeft);
|
| 41 |
+
|
| 42 |
+
temp = (*node)->topLeft;
|
| 43 |
+
(*node)->topLeft = (*node)->topRight;
|
| 44 |
+
(*node)->topRight = temp;
|
| 45 |
+
|
| 46 |
+
temp = (*node)->bottomLeft;
|
| 47 |
+
(*node)->bottomLeft = (*node)->bottomRight;
|
| 48 |
+
(*node)->bottomRight = temp;
|
| 49 |
+
}
|
| 50 |
+
// empty tree condition
|
| 51 |
+
else
|
| 52 |
+
{
|
| 53 |
+
return;
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
// rotate the image to the left by 90 degrees
|
| 58 |
+
void rotateLeft(qtNode **t)
|
| 59 |
+
{
|
| 60 |
+
if ((*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL)
|
| 61 |
+
{
|
| 62 |
+
qtNode *temp1;
|
| 63 |
+
qtNode *temp2;
|
| 64 |
+
qtNode *temp3;
|
| 65 |
+
qtNode *temp4;
|
| 66 |
+
|
| 67 |
+
rotateLeft(&(*t)->topLeft);
|
| 68 |
+
rotateLeft(&(*t)->topRight);
|
| 69 |
+
rotateLeft(&(*t)->bottomLeft);
|
| 70 |
+
rotateLeft(&(*t)->bottomRight);
|
| 71 |
+
|
| 72 |
+
temp1 = (*t)->topLeft;
|
| 73 |
+
temp2 = (*t)->topRight;
|
| 74 |
+
temp3 = (*t)->bottomLeft;
|
| 75 |
+
temp4 = (*t)->bottomRight;
|
| 76 |
+
|
| 77 |
+
(*t)->topLeft = temp2;
|
| 78 |
+
(*t)->topRight = temp4;
|
| 79 |
+
(*t)->bottomLeft = temp1;
|
| 80 |
+
(*t)->bottomRight = temp3;
|
| 81 |
+
}
|
| 82 |
+
else
|
| 83 |
+
{
|
| 84 |
+
return;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
// rotate the image to the right by 90 degrees
|
| 89 |
+
void rotateRight(qtNode **t)
|
| 90 |
+
{
|
| 91 |
+
if ((*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL)
|
| 92 |
+
{
|
| 93 |
+
qtNode *temp1;
|
| 94 |
+
qtNode *temp2;
|
| 95 |
+
qtNode *temp3;
|
| 96 |
+
qtNode *temp4;
|
| 97 |
+
|
| 98 |
+
rotateRight(&(*t)->topLeft);
|
| 99 |
+
rotateRight(&(*t)->topRight);
|
| 100 |
+
rotateRight(&(*t)->bottomLeft);
|
| 101 |
+
rotateRight(&(*t)->bottomRight);
|
| 102 |
+
|
| 103 |
+
temp1 = (*t)->topLeft;
|
| 104 |
+
temp2 = (*t)->topRight;
|
| 105 |
+
temp3 = (*t)->bottomLeft;
|
| 106 |
+
temp4 = (*t)->bottomRight;
|
| 107 |
+
|
| 108 |
+
(*t)->topLeft = temp3;
|
| 109 |
+
(*t)->topRight = temp1;
|
| 110 |
+
(*t)->bottomLeft = temp4;
|
| 111 |
+
(*t)->bottomRight = temp2;
|
| 112 |
+
}
|
| 113 |
+
else
|
| 114 |
+
{
|
| 115 |
+
return;
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
// rotate the image 180 degrees
|
| 120 |
+
void rotate180(qtNode **t)
|
| 121 |
+
{
|
| 122 |
+
if ((*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL && (*t)->topLeft != NULL)
|
| 123 |
+
{
|
| 124 |
+
qtNode *temp1;
|
| 125 |
+
qtNode *temp2;
|
| 126 |
+
qtNode *temp3;
|
| 127 |
+
qtNode *temp4;
|
| 128 |
+
|
| 129 |
+
rotate180(&(*t)->topLeft);
|
| 130 |
+
rotate180(&(*t)->topRight);
|
| 131 |
+
rotate180(&(*t)->bottomLeft);
|
| 132 |
+
rotate180(&(*t)->bottomRight);
|
| 133 |
+
|
| 134 |
+
temp1 = (*t)->topLeft;
|
| 135 |
+
temp2 = (*t)->topRight;
|
| 136 |
+
temp3 = (*t)->bottomLeft;
|
| 137 |
+
temp4 = (*t)->bottomRight;
|
| 138 |
+
|
| 139 |
+
(*t)->topLeft = temp4;
|
| 140 |
+
(*t)->topRight = temp3;
|
| 141 |
+
(*t)->bottomLeft = temp2;
|
| 142 |
+
(*t)->bottomRight = temp1;
|
| 143 |
+
}
|
| 144 |
+
else
|
| 145 |
+
{
|
| 146 |
+
return;
|
| 147 |
+
}
|
| 148 |
+
}
|
| 149 |
+
|
src/c_project_files/rotate.h
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "decompress.h"
|
| 2 |
+
|
| 3 |
+
void getWaterImage(qtNode ** node);
|
| 4 |
+
void getMirrorImage(qtNode ** node);
|
| 5 |
+
void rotateLeft(qtNode** t);
|
| 6 |
+
void rotateRight(qtNode** t);
|
src/c_project_files/rotate.o
ADDED
|
Binary file (3.09 kB). View file
|
|
|
src/c_project_files/sailboat.ppm
ADDED
|
|
Git LFS Details
|
src/c_project_files/squares.ppm
ADDED
|
|
Git LFS Details
|
src/c_project_files/suppl.c
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "suppl.h"
|
| 2 |
+
|
| 3 |
+
//-----------------------IMG MANIPULATION FUNC-----------------------------//
|
| 4 |
+
|
| 5 |
+
// reads the .ppm file and stores the data in 2D matrix form
|
| 6 |
+
pixels **read(int *height, int *width, char *file)
|
| 7 |
+
{
|
| 8 |
+
FILE *f;
|
| 9 |
+
char magic_num[3];
|
| 10 |
+
int color;
|
| 11 |
+
int i;
|
| 12 |
+
|
| 13 |
+
f = fopen(file, "rb");
|
| 14 |
+
|
| 15 |
+
fscanf(f, "%s", magic_num);
|
| 16 |
+
if (magic_num[0] != 'P' || magic_num[1] != '6')
|
| 17 |
+
{
|
| 18 |
+
printf("Invalid Image Format!\n");
|
| 19 |
+
exit;
|
| 20 |
+
}
|
| 21 |
+
fscanf(f, "%d ", width);
|
| 22 |
+
fscanf(f, "%d\n", height);
|
| 23 |
+
fscanf(f, "%d", &color);
|
| 24 |
+
|
| 25 |
+
char garbage;
|
| 26 |
+
fread(&garbage, sizeof(char), 1, f);
|
| 27 |
+
|
| 28 |
+
pixels **r = (pixels **)malloc(sizeof(pixels *) * (*height));
|
| 29 |
+
|
| 30 |
+
for (i = 0; i < (*height); i++)
|
| 31 |
+
{
|
| 32 |
+
r[i] = malloc(sizeof(pixels) * (*width));
|
| 33 |
+
fread(r[i], sizeof(pixels), (*width), f);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
fclose(f);
|
| 37 |
+
return r;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
// gives the output file in .ppm format
|
| 41 |
+
void outputFile(pixels **mat, char *file, int size)
|
| 42 |
+
{
|
| 43 |
+
|
| 44 |
+
FILE *f = fopen(file, "w");
|
| 45 |
+
|
| 46 |
+
fprintf(f, "P6\n");
|
| 47 |
+
fprintf(f, "%d %d\n", size, size);
|
| 48 |
+
fprintf(f, "255\n");
|
| 49 |
+
|
| 50 |
+
int i;
|
| 51 |
+
for (i = 0; i < size; i++)
|
| 52 |
+
{
|
| 53 |
+
fwrite(mat[i], sizeof(pixels), size, f);
|
| 54 |
+
}
|
| 55 |
+
fclose(f);
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
int getMean(pixels **matrix, qtNode **t, int x, int y, int size)
|
| 59 |
+
{
|
| 60 |
+
int i, j;
|
| 61 |
+
unsigned long long int blue = 0, green = 0, red = 0, mean = 0;
|
| 62 |
+
|
| 63 |
+
(*t) = malloc(sizeof(qtNode));
|
| 64 |
+
(*t)->area = size * size;
|
| 65 |
+
|
| 66 |
+
for (i = y; i < y + size; i++)
|
| 67 |
+
for (j = x; j < x + size; j++)
|
| 68 |
+
{
|
| 69 |
+
blue = blue + matrix[i][j].blue;
|
| 70 |
+
green = green + matrix[i][j].green;
|
| 71 |
+
red = red + matrix[i][j].red;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
blue = blue / ((*t)->area);
|
| 75 |
+
red = red / ((*t)->area);
|
| 76 |
+
green = green / ((*t)->area);
|
| 77 |
+
|
| 78 |
+
(*t)->p.blue = blue;
|
| 79 |
+
(*t)->p.red = red;
|
| 80 |
+
(*t)->p.green = green;
|
| 81 |
+
|
| 82 |
+
// Compute score
|
| 83 |
+
|
| 84 |
+
for (i = y; i < y + size; i++)
|
| 85 |
+
{
|
| 86 |
+
for (j = x; j < x + size; j++)
|
| 87 |
+
{
|
| 88 |
+
mean = mean + ((red - matrix[i][j].red) * (red - matrix[i][j].red)) + ((green - matrix[i][j].green) * (green - matrix[i][j].green)) + ((blue - matrix[i][j].blue) * (blue - matrix[i][j].blue));
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
|
| 92 |
+
mean = mean / (3 * (*t)->area);
|
| 93 |
+
|
| 94 |
+
return mean;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
//--------------------------QUAD TREE FUNCTIONS------------------------------//
|
| 98 |
+
|
| 99 |
+
// stores the quad tree info in array
|
| 100 |
+
|
| 101 |
+
void traversal(qtNode *node, qtNode **vector[], unsigned int *index)
|
| 102 |
+
{
|
| 103 |
+
if (node != NULL)
|
| 104 |
+
{
|
| 105 |
+
if ((*index) > 0)
|
| 106 |
+
(*vector) = realloc((*vector), sizeof(qtNode *) * ((*index) + 1));
|
| 107 |
+
|
| 108 |
+
(*vector)[(*index)] = node;
|
| 109 |
+
node->index = (*index);
|
| 110 |
+
(*index)++;
|
| 111 |
+
|
| 112 |
+
traversal(node->topLeft, vector, index);
|
| 113 |
+
traversal(node->topRight, vector, index);
|
| 114 |
+
traversal(node->bottomRight, vector, index);
|
| 115 |
+
traversal(node->bottomLeft, vector, index);
|
| 116 |
+
}
|
| 117 |
+
else
|
| 118 |
+
return;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
// transfers the contents to qtInfo
|
| 122 |
+
void copyToArr(qtNode **vp, qtInfo **v, int index)
|
| 123 |
+
{
|
| 124 |
+
|
| 125 |
+
unsigned int i;
|
| 126 |
+
|
| 127 |
+
for (i = 0; i < index; i++)
|
| 128 |
+
{
|
| 129 |
+
(*v)[i].red = vp[i]->p.red;
|
| 130 |
+
(*v)[i].blue = vp[i]->p.blue;
|
| 131 |
+
(*v)[i].green = vp[i]->p.green;
|
| 132 |
+
(*v)[i].area = vp[i]->area;
|
| 133 |
+
|
| 134 |
+
if (vp[i]->topLeft != NULL)
|
| 135 |
+
(*v)[i].topLeft = vp[i]->topLeft->index;
|
| 136 |
+
else
|
| 137 |
+
(*v)[i].topLeft = -1;
|
| 138 |
+
|
| 139 |
+
if (vp[i]->topRight != NULL)
|
| 140 |
+
(*v)[i].topRight = vp[i]->topRight->index;
|
| 141 |
+
else
|
| 142 |
+
(*v)[i].topRight = -1;
|
| 143 |
+
|
| 144 |
+
if (vp[i]->bottomRight != NULL)
|
| 145 |
+
(*v)[i].bottomRight = vp[i]->bottomRight->index;
|
| 146 |
+
else
|
| 147 |
+
(*v)[i].bottomRight = -1;
|
| 148 |
+
|
| 149 |
+
if (vp[i]->bottomLeft != NULL)
|
| 150 |
+
(*v)[i].bottomLeft = vp[i]->bottomLeft->index;
|
| 151 |
+
else
|
| 152 |
+
(*v)[i].bottomLeft = -1;
|
| 153 |
+
}
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
// reads the data from matrix
|
| 157 |
+
void readTree(qtInfo *vec, qtNode **node, int i)
|
| 158 |
+
{
|
| 159 |
+
(*node) = malloc(sizeof(qtNode));
|
| 160 |
+
|
| 161 |
+
(*node)->p.red = vec[i].red;
|
| 162 |
+
(*node)->p.blue = vec[i].blue;
|
| 163 |
+
(*node)->p.green = vec[i].green;
|
| 164 |
+
(*node)->area = vec[i].area;
|
| 165 |
+
(*node)->index = i;
|
| 166 |
+
|
| 167 |
+
if (vec[i].topLeft != -1 && vec[i].topRight != -1 && vec[i].bottomLeft != -1 && vec[i].bottomRight != -1)
|
| 168 |
+
{
|
| 169 |
+
readTree(vec, &(*node)->topLeft, vec[i].topLeft);
|
| 170 |
+
readTree(vec, &(*node)->topRight, vec[i].topRight);
|
| 171 |
+
readTree(vec, &(*node)->bottomLeft, vec[i].bottomLeft);
|
| 172 |
+
readTree(vec, &(*node)->bottomRight, vec[i].bottomRight);
|
| 173 |
+
}
|
| 174 |
+
else
|
| 175 |
+
{
|
| 176 |
+
(*node)->topLeft = NULL;
|
| 177 |
+
(*node)->topRight = NULL;
|
| 178 |
+
(*node)->bottomLeft = NULL;
|
| 179 |
+
(*node)->bottomRight = NULL;
|
| 180 |
+
}
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
void destroyTree(qtNode** t)
|
| 184 |
+
{
|
| 185 |
+
if(!t)
|
| 186 |
+
{
|
| 187 |
+
destroyTree(&(*t)->topLeft);
|
| 188 |
+
destroyTree(&(*t)->topRight);
|
| 189 |
+
destroyTree(&(*t)->bottomLeft);
|
| 190 |
+
destroyTree(&(*t)->bottomRight);
|
| 191 |
+
}
|
| 192 |
+
free(*t);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
//-----------------------------OTHER FUNCS---------------------------------//
|
| 196 |
+
int min(int a,int b)
|
| 197 |
+
{
|
| 198 |
+
if(a>b)
|
| 199 |
+
{
|
| 200 |
+
return a;
|
| 201 |
+
}
|
| 202 |
+
else
|
| 203 |
+
{
|
| 204 |
+
return b;
|
| 205 |
+
}
|
| 206 |
+
}
|
src/c_project_files/suppl.h
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <stdio.h>
|
| 2 |
+
#include <stdlib.h>
|
| 3 |
+
#include <string.h>
|
| 4 |
+
#include <math.h>
|
| 5 |
+
|
| 6 |
+
// rgb structure
|
| 7 |
+
typedef struct pixels
|
| 8 |
+
{
|
| 9 |
+
|
| 10 |
+
unsigned char red;
|
| 11 |
+
unsigned char green;
|
| 12 |
+
unsigned char blue;
|
| 13 |
+
|
| 14 |
+
} pixels;
|
| 15 |
+
|
| 16 |
+
// quad tree structure
|
| 17 |
+
typedef struct qtNode
|
| 18 |
+
{
|
| 19 |
+
|
| 20 |
+
pixels p;
|
| 21 |
+
long long index;
|
| 22 |
+
int area;
|
| 23 |
+
|
| 24 |
+
struct qtNode *topLeft;
|
| 25 |
+
struct qtNode *topRight;
|
| 26 |
+
struct qtNode *bottomLeft;
|
| 27 |
+
struct qtNode *bottomRight;
|
| 28 |
+
|
| 29 |
+
} qtNode;
|
| 30 |
+
|
| 31 |
+
//structure for storing the information about quad tree array
|
| 32 |
+
typedef struct qtInfo
|
| 33 |
+
{
|
| 34 |
+
|
| 35 |
+
unsigned char blue, green, red;
|
| 36 |
+
int area;
|
| 37 |
+
int topLeft;
|
| 38 |
+
int topRight;
|
| 39 |
+
int bottomLeft;
|
| 40 |
+
int bottomRight;
|
| 41 |
+
|
| 42 |
+
} qtInfo;
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
//-----------------------IMG MANIPULATION FUNCTIONS-----------------------------//
|
| 46 |
+
|
| 47 |
+
pixels **read(int *height, int *width, char *file);
|
| 48 |
+
void outputFile(pixels **mat, char *file, int size);
|
| 49 |
+
int getMean(pixels **matrix, qtNode **node, int x, int y, int size);
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
//--------------------------QUAD TREE FUNCTIONS------------------------------//
|
| 53 |
+
void traversal(qtNode * node, qtNode ** vector[], unsigned int * index);
|
| 54 |
+
void copyToArr(qtNode ** vp, qtInfo ** v, int index);
|
| 55 |
+
void readTree(qtInfo * vec, qtNode ** node, int i);
|
| 56 |
+
void destroyTree(qtNode** t);
|
| 57 |
+
|
| 58 |
+
//------------------------OTHER FUNCS--------------------------------------//
|
| 59 |
+
int min(int a,int b);
|
src/c_project_files/suppl.o
ADDED
|
Binary file (6.93 kB). View file
|
|
|
src/c_project_files/union.c
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "union.h"
|
| 2 |
+
|
| 3 |
+
void unionOfImages(qtNode *t1, qtNode *t2, qtNode **res)
|
| 4 |
+
{
|
| 5 |
+
(*res) = malloc(sizeof(qtNode));
|
| 6 |
+
if (t1->topLeft != NULL && t2->topLeft != NULL)
|
| 7 |
+
{
|
| 8 |
+
unionOfImages(t1->topLeft, t2->topLeft, &(*res)->topLeft);
|
| 9 |
+
unionOfImages(t1->topRight, t2->topRight, &(*res)->topRight);
|
| 10 |
+
unionOfImages(t1->bottomLeft, t2->bottomLeft, &(*res)->bottomLeft);
|
| 11 |
+
unionOfImages(t1->bottomRight, t2->bottomRight, &(*res)->bottomRight);
|
| 12 |
+
}
|
| 13 |
+
else
|
| 14 |
+
{
|
| 15 |
+
if (t1->topLeft == NULL && t2->topLeft != NULL)
|
| 16 |
+
{
|
| 17 |
+
unionOfImages(t1, t2->topLeft, (&(*res)->topLeft));
|
| 18 |
+
unionOfImages(t1, t2->topRight, &(*res)->topRight);
|
| 19 |
+
unionOfImages(t1, t2->bottomLeft, &(*res)->bottomLeft);
|
| 20 |
+
unionOfImages(t1, t2->bottomRight, &(*res)->bottomRight);
|
| 21 |
+
}
|
| 22 |
+
else
|
| 23 |
+
{
|
| 24 |
+
if (t1->topLeft != NULL && t2->topLeft == NULL)
|
| 25 |
+
{
|
| 26 |
+
unionOfImages(t1->topLeft, t2, &(*res)->topLeft);
|
| 27 |
+
unionOfImages(t1->topRight, t2, &(*res)->topRight);
|
| 28 |
+
unionOfImages(t1->bottomLeft, t2, &(*res)->bottomLeft);
|
| 29 |
+
unionOfImages(t1->bottomRight, t2, &(*res)->bottomRight);
|
| 30 |
+
}
|
| 31 |
+
else
|
| 32 |
+
{
|
| 33 |
+
|
| 34 |
+
(*res)->topRight = NULL;
|
| 35 |
+
(*res)->topLeft = NULL;
|
| 36 |
+
(*res)->bottomLeft = NULL;
|
| 37 |
+
(*res)->bottomRight = NULL;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
}
|
| 41 |
+
(*res)->area = min(t1->area, t2->area);
|
| 42 |
+
(*res)->p.blue = (t1->p.blue + t2->p.blue) / 2;
|
| 43 |
+
(*res)->p.red = (t1->p.red + t2->p.red) / 2;
|
| 44 |
+
(*res)->p.green = (t1->p.green + t2->p.green) / 2;
|
| 45 |
+
|
| 46 |
+
return;
|
| 47 |
+
}
|
src/c_project_files/union.h
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "rotate.h"
|
| 2 |
+
|
| 3 |
+
void unionOfImages(qtNode *t1, qtNode *t2, qtNode **res);
|
| 4 |
+
|
src/c_project_files/union.o
ADDED
|
Binary file (2.54 kB). View file
|
|
|