GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
defs/bitmap.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct BMBM_create (int, int)
 Create bitmap of dimension x/y and return structure token. More...
 
int BM_destroy (struct BM *)
 Destroy bitmap and free all associated memory. More...
 
int BM_set_mode (int, int)
 Specify the type of data structure to use for bitmap. 'mode' can be either BM_FLAT or BM_SPARSE: More...
 
int BM_set (struct BM *, int, int, int)
 Sets bitmap value to 'val' at location 'x' 'y'. More...
 
int BM_get (struct BM *, int, int)
 Gets 'val' from the bitmap. More...
 
size_t BM_get_map_size (struct BM *)
 Returns size in bytes that bitmap is taking up. More...
 
int BM_file_write (FILE *, struct BM *)
 Write bitmap out to file. More...
 
struct BMBM_file_read (FILE *)
 Create map structure and load it from file. More...
 
struct BMBM_create_sparse (int, int)
 Create a sparse bitmap of dimension 'x'/'y'. More...
 
int BM_destroy_sparse (struct BM *)
 Destroy sparse bitmap and free all associated memory. More...
 
int BM_set_sparse (struct BM *, int, int, int)
 Set sparse bitmap value to 'val' at location 'x'/'y'. More...
 
int BM_get_sparse (struct BM *, int, int)
 Returns sparse bitmap value at location 'x'/'y'. More...
 
size_t BM_get_map_size_sparse (struct BM *)
 Returns size of sparse bitmap in bytes. More...
 
int BM_dump_map_sparse (struct BM *)
 Debugging code to dump out structure of links. More...
 
int BM_dump_map_row_sparse (struct BM *, int)
 Debugging code to dump out structure of links for single row. More...
 
int BM_file_write_sparse (FILE *, struct BM *)
 Write sparse bitmap matrix out to disk file 'fp'. NOTE: 'fp' must already be opened and later closed by user. More...
 

Function Documentation

◆ BM_create()

struct BM* BM_create ( int  x,
int  y 
)

Create bitmap of dimension x/y and return structure token.

Bitmap is initialized to all zeros

Parameters
xx dimension
yy dimension
Returns
pointer to struct BM
NULL on error

Definition at line 60 of file bitmap.c.

Referenced by gs_update_curmask(), gsbm_make_mask(), IL_create_bitmask(), and main().

◆ BM_create_sparse()

struct BM* BM_create_sparse ( int  x,
int  y 
)

Create a sparse bitmap of dimension 'x'/'y'.

Returns bitmap structure or NULL on error

Parameters
x
y
Returns
struct BM

Definition at line 44 of file sparse.c.

References BM::bytes, BM::cols, count, BM::data, link_init(), link_new(), link_set_chunk_size(), malloc(), NULL, BM::rows, BM::sparse, BM::token, BMlink::val, and x.

Referenced by main().

◆ BM_destroy()

int BM_destroy ( struct BM map)

Destroy bitmap and free all associated memory.

Parameters
map
Returns
int returns 0

Definition at line 90 of file bitmap.c.

References BM_destroy_sparse(), BM::data, free(), and BM::sparse.

Referenced by free_data_buffs(), and gs_update_curmask().

◆ BM_destroy_sparse()

int BM_destroy_sparse ( struct BM map)

Destroy sparse bitmap and free all associated memory.

Returns 0

Parameters
map
Returns
int

Definition at line 90 of file sparse.c.

Referenced by BM_destroy().

◆ 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.

Returns 0

Parameters
map
y
Returns
int

Definition at line 332 of file sparse.c.

References BMlink::count, BM::data, BMlink::next, NULL, and BMlink::val.

◆ BM_dump_map_sparse()

int BM_dump_map_sparse ( struct BM map)

Debugging code to dump out structure of links.

Returns 0

Parameters
map
Returns
int

Definition at line 302 of file sparse.c.

References BMlink::count, BM::data, BMlink::next, NULL, BM::rows, and BMlink::val.

◆ BM_file_read()

struct BM* BM_file_read ( FILE *  fp)

Create map structure and load it from file.

'fp' should previously been created by BM_file_write()

Returns struct BM * or NULL on error

Parameters
fp
Returns
struct BM

Definition at line 313 of file bitmap.c.

◆ BM_file_write()

int BM_file_write ( FILE *  fp,
struct BM map 
)

Write bitmap out to file.

Expects open file pointer 'fp' and existing map structure. Caller is responsible to open and close 'fp'.

Returns 0 or -1 on error

Parameters
fp
map
Returns
int

Definition at line 269 of file bitmap.c.

◆ BM_file_write_sparse()

int BM_file_write_sparse ( FILE *  fp,
struct BM map 
)

Write sparse bitmap matrix out to disk file 'fp'. NOTE: 'fp' must already be opened and later closed by user.

Returns 0 on success or -1 on error

Parameters
fp
map
Returns
int

Definition at line 364 of file sparse.c.

◆ BM_get()

int BM_get ( struct BM map,
int  x,
int  y 
)

Gets 'val' from the bitmap.

Returns 0 or 1 on success or -1 on error

Parameters
map
x
y
Returns
int

Definition at line 220 of file bitmap.c.

References BM_col_to_bit, BM_col_to_byte, BM_get_sparse(), BM::bytes, BM::cols, BM::data, BM::rows, and BM::sparse.

Referenced by calc_norm(), get_mapatt(), gs_masked(), gs_point_is_masked(), gsbm_make_mask(), gsd_wire_arrows(), gsd_wire_surf_const(), gsd_wire_surf_map(), IL_secpar_loop_2d(), and print_bm().

◆ BM_get_map_size()

size_t BM_get_map_size ( struct BM map)

Returns size in bytes that bitmap is taking up.

Parameters
map
Returns
int

Definition at line 245 of file bitmap.c.

References BM_get_map_size_sparse(), BM::bytes, BM::rows, and BM::sparse.

Referenced by free_data_buffs().

◆ BM_get_map_size_sparse()

size_t BM_get_map_size_sparse ( struct BM map)

Returns size of sparse bitmap in bytes.

Parameters
map
Returns
int

Definition at line 272 of file sparse.c.

References BM::data, BMlink::next, NULL, and BM::rows.

Referenced by BM_get_map_size().

◆ BM_get_sparse()

int BM_get_sparse ( struct BM map,
int  x,
int  y 
)

Returns sparse bitmap value at location 'x'/'y'.

Returns value or -1 on error

Parameters
map
x
y
Returns
int

Definition at line 246 of file sparse.c.

References BMlink::count, cur_x, BM::data, BMlink::next, NULL, and BMlink::val.

Referenced by BM_get().

◆ BM_set()

int BM_set ( struct BM map,
int  x,
int  y,
int  val 
)

Sets bitmap value to 'val' at location 'x' 'y'.

Returns 0 on success

Parameters
map
x
y
val
Returns
int

Definition at line 187 of file bitmap.c.

References BM_col_to_bit, BM_col_to_byte, BM_set_sparse(), BM::bytes, BM::cols, BM::data, BM::rows, and BM::sparse.

Referenced by gs_update_curmask(), gsbm_make_mask(), IL_create_bitmask(), and main().

◆ BM_set_mode()

int BM_set_mode ( int  mode,
int  size 
)

Specify the type of data structure to use for bitmap. 'mode' can be either BM_FLAT or BM_SPARSE:

BM_FLAT is a basic packed bitmap - eight values stored per byte thus creating a 1:8 compression over using char arrays and a 1:32 compression over using CELL arrays.

BM_SPARSE is a linked array of values. This is much more efficient for large, very sparse arrays. It is slower to access, especially for writing, but can save several orders of magnitude of memory on large bitmaps.

NOTE: At this time 'size' must be passed a value of 1

returns 0 on success or -1 on error

Parameters
mode
size
Returns
int

Definition at line 149 of file bitmap.c.

◆ BM_set_sparse()

int BM_set_sparse ( struct BM map,
int  x,
int  y,
int  val 
)

Set sparse bitmap value to 'val' at location 'x'/'y'.

Returns 0

Parameters
map
x
y
val
Returns
int

Definition at line 128 of file sparse.c.

References BMlink::count, cur_x, BM::data, link_dispose(), link_new(), BMlink::next, NULL, BM::token, BMlink::val, and VOID_T.

Referenced by BM_set().