-
Notifications
You must be signed in to change notification settings - Fork 0
/
ppm.c
68 lines (54 loc) · 2.36 KB
/
ppm.c
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
62
63
64
65
66
67
68
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "read_image.h"
#include "modification_and_write_image.h"
//============================================================================
// Main
//============================================================================
int main(int argc, char* argv[])
{
//--------------------------------------------------------------------------
// Read file "gargouille.ppm" into image (width and height)
//--------------------------------------------------------------------------
old *oldimage = ppm_read_from_file("gargouille.ppm");
int width=oldimage->width;
int height=oldimage->height;
u_char *image=oldimage->data;
//--------------------------------------------------------------------------
// Create a desaturated (B&W) copy of the image we've just read and
// write it into "gargouille_BW.ppm"
//--------------------------------------------------------------------------
// Copy image into image_bw
int width_bw = width;
int height_bw = height;
u_char* image_bw = (u_char*) malloc(3 * width * height * sizeof(*image_bw));
memcpy(image_bw, image, 3 * width * height * sizeof(*image_bw));
// Desaturate image_bw
newimg* newimage = ppm_desaturate(image_bw, width, height);
// Write the desaturated image into "gargouille_BW.ppm"
ppm_write_to_file(newimage, "gargouille_BW.ppm");
// Free the desaturated image
//--------------------------------------------------------------------------
// Create a resized copy of the image and
// write it into "gargouille_small.ppm"
//--------------------------------------------------------------------------
// Copy image into image_small
int width_small = width;
int height_small = height;
u_char* image_small = (u_char*) malloc(3 * width_small * height_small * sizeof(*image_small));
memcpy(image_small, image, 3 * width_small * height_small * sizeof(*image_small));
// Shrink image_small size 2-fold
newimg * newimage1=ppm_shrink(&image_small, &width_small, &height_small, 2);
// Write the desaturated image into "gargouille_small.ppm"
ppm_write_to_file(newimage1, "gargouille_small.ppm");
// Free the not yet freed images
free(oldimage->data);
free(oldimage);
free(newimage->data);
free(newimage);
free(newimage1->data);
free(newimage1);
free(image_small);
}