GRASS GIS 7 Programmer's Manual
7.8.4(2020)-exported
smain.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <grass/bitmap.h>
4
5
6
static
int
dump_map(
struct
BM *map);
7
8
9
int
main
(
int
argc,
char
*argv[])
10
{
11
int
SIZE;
12
struct
BM *map, *map2;
13
int
i,
x
, y;
14
int
dump;
15
FILE *fp;
16
17
if
(argc < 2)
18
SIZE = 11;
19
else
20
SIZE = atoi(argv[1]);
21
22
if
(
NULL
== getenv(
"NODUMP"
))
23
dump = 1;
24
else
25
dump = 0;
26
27
map =
BM_create_sparse
(SIZE, SIZE);
28
29
/* turn on bits in X pattern */
30
for
(i = 0; i < SIZE; i++) {
31
BM_set
(map, i, i, 1);
32
BM_set
(map, (SIZE - 1) - i, i, 1);
33
}
34
35
if
(dump)
36
dump_map(map);
37
38
fprintf(stdout,
"Size = %d\n"
,
BM_get_map_size
(map));
39
40
/*
41
BM_dump_map_sparse (map);
42
*/
43
44
fprintf(stdout,
"\n\n"
);
45
/* now invert it */
46
for
(y = 0; y < SIZE; y++)
47
for
(
x
= 0;
x
< SIZE;
x
++) {
48
BM_set
(map,
x
, y, !
BM_get
(map,
x
, y));
49
#ifdef FOO
50
/*DEBUG*/
if
(y == 0)
51
/*DEBUG*/
BM_dump_map_row_sparse
(map, y);
52
#endif
53
}
54
55
if
(dump)
56
dump_map(map);
57
58
fprintf(stdout,
"Size = %d\n"
,
BM_get_map_size
(map));
59
/*
60
fprintf (stdout, "\n\n");
61
BM_dump_map_sparse (map);
62
*/
63
{
64
fp = fopen(
"dumpfile"
,
"w"
);
65
if
(0 >
BM_file_write
(fp, map)) {
66
fprintf(stderr,
"File_write failed\n"
);
67
goto
nowrite;
68
}
69
fclose(fp);
70
71
fp = fopen(
"dumpfile"
,
"r"
);
72
map2 =
BM_file_read
(fp);
73
fclose(fp);
74
dump_map(map2);
75
}
76
77
BM_destroy
(map2);
78
nowrite:
79
80
BM_destroy
(map);
81
82
return
0;
83
}
84
85
86
static
int
dump_map(
struct
BM *map)
87
{
88
int
x
, y;
89
90
for
(y = 0; y < map->rows; y++) {
91
for
(
x
= 0;
x
< map->cols;
x
++) {
92
fprintf(stdout,
"%c"
,
BM_get
(map,
x
, y) ?
'#'
:
'.'
);
93
94
}
95
fprintf(stdout,
"\n"
);
96
}
97
}
BM_set
int BM_set(struct BM *map, int x, int y, int val)
Sets bitmap value to 'val' at location 'x' 'y'.
Definition:
bitmap.c:187
BM_file_read
struct BM * BM_file_read(FILE *fp)
Create map structure and load it from file.
Definition:
bitmap.c:313
x
#define x
BM_create_sparse
struct BM * BM_create_sparse(int x, int y)
Create a sparse bitmap of dimension 'x'/'y'.
Definition:
sparse.c:44
BM_get
int BM_get(struct BM *map, int x, int y)
Gets 'val' from the bitmap.
Definition:
bitmap.c:220
BM_get_map_size
size_t BM_get_map_size(struct BM *map)
Returns size in bytes that bitmap is taking up.
Definition:
bitmap.c:245
NULL
#define NULL
Definition:
ccmath.h:32
BM_destroy
int BM_destroy(struct BM *map)
Destroy bitmap and free all associated memory.
Definition:
bitmap.c:90
BM_dump_map_row_sparse
int BM_dump_map_row_sparse(struct BM *map, int y)
Debugging code to dump out structure of links for single row.
Definition:
sparse.c:332
main
int main(int argc, char *argv[])
Definition:
smain.c:9
BM_file_write
int BM_file_write(FILE *fp, struct BM *map)
Write bitmap out to file.
Definition:
bitmap.c:269
bitmap
smain.c
Generated on Mon Oct 5 2020 08:56:03 for GRASS GIS 7 Programmer's Manual by
1.8.20