-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompress.c
More file actions
32 lines (30 loc) · 1.1 KB
/
compress.c
File metadata and controls
32 lines (30 loc) · 1.1 KB
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
/* CONSTANTINESCU Vlad 314CB */
#include "quadtree.h"
/* Compression/ Task2 = writes in a binary output file the size of the image,
* as well as the types of nodes and the BFS of the tree using an auxiliary
* queue to arrange the nodes in the BFS order */
void compress(TQuad qtree, FILE *output, unsigned int size)
{
fwrite(&size, sizeof(unsigned int), 1, output);
TQueue Q = InitQ();
PushQ(&Q, qtree);
while (Q->front != NULL) {
/* type = 1 => node is leaf, writes the RGB value
* type = 0 => node is parent, pushes in the queue
* the children of the parent */
if (Q->front->info->type) {
fwrite(&Q->front->info->type, sizeof(char), 1, output);
fwrite(&Q->front->info->info.R, sizeof(char), 1, output);
fwrite(&Q->front->info->info.G, sizeof(char), 1, output);
fwrite(&Q->front->info->info.B, sizeof(char), 1, output);
} else {
fwrite(&Q->front->info->type, sizeof(char), 1, output);
PushQ(&Q, Q->front->info->topL);
PushQ(&Q, Q->front->info->topR);
PushQ(&Q, Q->front->info->botR);
PushQ(&Q, Q->front->info->botL);
}
PopQ(&Q);
}
FreeQ(&Q);
}