-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbm_aux.c
77 lines (71 loc) · 2.07 KB
/
pbm_aux.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
69
70
71
72
73
74
75
76
77
#include "pbm.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
PPMImage * new_ppmimage(unsigned int w, unsigned int h, unsigned int m)
{
PPMImage* img = (PPMImage*)malloc(sizeof(PPMImage));
img->pixmap[0] = (unsigned int**)malloc(sizeof(unsigned int) * h);
img->pixmap[1] = (unsigned int**)malloc(sizeof(unsigned int) * h);
img->pixmap[2] = (unsigned int**)malloc(sizeof(unsigned int) * h);
for (unsigned int i = 0; i < h; i++) {
img->pixmap[0][i] = (unsigned int*)malloc(sizeof(unsigned int) * w);
img->pixmap[1][i] = (unsigned int*)malloc(sizeof(unsigned int) * w);
img->pixmap[2][i] = (unsigned int*)malloc(sizeof(unsigned int) * w);
}
img->height = h;
img->width = w;
img->max = m;
return img;
}
PBMImage * new_pbmimage(unsigned int w, unsigned int h)
{
PBMImage* img = (PBMImage*)malloc(sizeof(PBMImage));
img->pixmap = (unsigned int**)malloc(sizeof(unsigned int) * h);
for (unsigned int i = 0; i < h; i++) {
img->pixmap[i] = (unsigned int*)malloc(sizeof(unsigned int) * w);
}
img->height = h;
img->width = w;
return img;
}
PGMImage * new_pgmimage(unsigned int w, unsigned int h, unsigned int m)
{
PGMImage* img = (PGMImage*)malloc(sizeof(PGMImage));
img->pixmap = (unsigned int**)malloc(sizeof(unsigned int) * h);
for (unsigned int i = 0; i < h; i++) {
img->pixmap[i] = (unsigned int*)malloc(sizeof(unsigned int) * w);
}
img->height = h;
img->width = w;
img->max = m;
return img;
}
void del_ppmimage(PPMImage *p)
{
for (unsigned int i = 0; i < p->height; i++) {
free(p->pixmap[0][i]);
free(p->pixmap[1][i]);
free(p->pixmap[2][i]);
}
free(p->pixmap[0]);
free(p->pixmap[1]);
free(p->pixmap[2]);
free(p);
}
void del_pgmimage(PGMImage *p)
{
for (unsigned int i = 0; i < p->height; i++) {
free(p->pixmap[i]);
}
free(p->pixmap);
free(p);
}
void del_pbmimage(PBMImage *p)
{
for (unsigned int i = 0; i < p->height; i++) {
free(p->pixmap[i]);
}
free(p->pixmap);
free(p);
}