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