GRASS GIS 7 Programmer's Manual
7.9.dev(2021)-e5379bbd7
main.c
Go to the documentation of this file.
1
2
/****************************************************************************
3
*
4
* MODULE: bitmap
5
* AUTHOR(S): David Gerdes (CERL) (original contributor)
6
* Markus Neteler <neteler itc.it>,
7
* Bernhard Reiter <bernhard intevation.de>,
8
* Brad Douglas <rez touchofmadness.com>,
9
* Glynn Clements <glynn gclements.plus.com>
10
* PURPOSE: provides basic support for the creation and manipulation of
11
* two dimensional bitmap arrays
12
* COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
13
*
14
* This program is free software under the GNU General Public
15
* License (>=v2). Read the file COPYING that comes with GRASS
16
* for details.
17
*
18
*****************************************************************************/
19
#include <stdio.h>
20
#include <stdlib.h>
21
#include <
grass/bitmap.h
>
22
23
24
static
int
dump_map(
struct
BM
*map);
25
26
27
int
main
(
int
argc,
char
*argv[])
28
{
29
int
SIZE;
30
struct
BM
*map, *map2;
31
int
i,
x
, y;
32
int
dump;
33
FILE *fp;
34
35
if
(argc < 2)
36
SIZE = 11;
37
else
38
SIZE = atoi(argv[1]);
39
40
if
(
NULL
!=
getenv
(
"NODUMP"
))
41
dump = 0;
42
else
43
dump = 1;
44
45
map =
BM_create
(SIZE, SIZE);
46
47
/* turn on bits in X pattern */
48
for
(i = 0; i < SIZE; i++) {
49
BM_set
(map, i, i, 1);
50
BM_set
(map, (SIZE - 1) - i, i, 1);
51
}
52
53
54
if
(dump)
55
dump_map(map);
56
fprintf(stdout,
"Size = %d\n"
,
BM_get_map_size
(map));
57
58
fprintf(stdout,
"\n\n"
);
59
60
/* now invert it */
61
for
(y = 0; y < SIZE; y++)
62
for
(x = 0; x < SIZE; x++)
63
BM_set
(map, x, y, !
BM_get
(map, x, y));
64
65
if
(dump)
66
dump_map(map);
67
68
fprintf(stdout,
"Size = %d\n"
,
BM_get_map_size
(map));
69
70
{
71
fp = fopen(
"dumpfile"
,
"w"
);
72
BM_file_write
(fp, map);
73
fclose(fp);
74
75
fp = fopen(
"dumpfile"
,
"r"
);
76
map2 =
BM_file_read
(fp);
77
fclose(fp);
78
dump_map(map2);
79
}
80
81
BM_destroy
(map);
82
BM_destroy
(map2);
83
84
return
0;
85
}
86
87
88
static
int
dump_map(
struct
BM
*map)
89
{
90
int
x
, y;
91
92
for
(y = 0; y < map->
rows
; y++) {
93
for
(x = 0; x < map->
cols
; x++) {
94
fprintf(stdout,
"%c"
,
BM_get
(map, x, y) ?
'#'
:
'.'
);
95
96
}
97
fprintf(stdout,
"\n"
);
98
}
99
}
main
int main(int argc, char *argv[])
Definition:
main.c:27
BM_get_map_size
size_t BM_get_map_size(struct BM *)
Returns size in bytes that bitmap is taking up.
Definition:
bitmap.c:245
BM_set
int BM_set(struct BM *, int, int, int)
Sets bitmap value to 'val' at location 'x' 'y'.
Definition:
bitmap.c:187
BM_file_read
struct BM * BM_file_read(FILE *)
Create map structure and load it from file.
Definition:
bitmap.c:313
BM
Definition:
bitmap.h:17
BM::rows
int rows
Definition:
bitmap.h:19
NULL
#define NULL
Definition:
ccmath.h:32
x
#define x
BM_destroy
int BM_destroy(struct BM *)
Destroy bitmap and free all associated memory.
Definition:
bitmap.c:90
BM_file_write
int BM_file_write(FILE *, struct BM *)
Write bitmap out to file.
Definition:
bitmap.c:269
BM_get
int BM_get(struct BM *, int, int)
Gets 'val' from the bitmap.
Definition:
bitmap.c:220
BM_create
struct BM * BM_create(int, int)
Create bitmap of dimension x/y and return structure token.
Definition:
bitmap.c:60
bitmap.h
BM::cols
int cols
Definition:
bitmap.h:20
getenv
char * getenv()
lib
bitmap
main.c
Generated on Mon May 31 2021 05:21:30 for GRASS GIS 7 Programmer's Manual by
1.8.13