Loading...
Searching...
No Matches
bitmap.c File Reference
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <grass/linkm.h>`
`#include <grass/bitmap.h>`
Include dependency graph for bitmap.c:

Go to the source code of this file.

## Macros

#define | BM_col_to_byte(x)
#define | BM_col_to_bit(x)

## Functions

struct BM * | BM_create (int x, int y)
| Create bitmap of dimension x/y and return structure token.
int | BM_destroy (struct BM *map)
| Destroy bitmap and free all associated memory.
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:
int | BM_set (struct BM *map, int x, int y, int val)
| Sets bitmap value to 'val' at location 'x' 'y'.
int | BM_get (struct BM *map, int x, int y)
| Gets 'val' from the bitmap.
size_t | BM_get_map_size (struct BM *map)
| Returns size in bytes that bitmap is taking up.
int | BM_file_write (FILE *fp, struct BM *map)
| Write bitmap out to file.
struct BM * | BM_file_read (FILE *fp)
| Create map structure and load it from file.

## Macro Definition Documentation

## BM_col_to_bit

#define BM_col_to_bit | ( |  | x | ) |

Value:
((x) & 7) /* x % 8 */
x
#define x

Definition at line 41 of file bitmap.c.

Referenced by BM_get(), and BM_set().

## BM_col_to_byte

#define BM_col_to_byte | ( |  | x | ) |

Value:
((x) >> 3) /* x / 8 */

Definition at line 40 of file bitmap.c.

Referenced by BM_get(), and BM_set().

## 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

  x | x dimension
  y | y dimension

Returns
  pointer to struct BM
  NULL on error

Definition at line 57 of file bitmap.c.

References BM_create_sparse(), NULL, and x.

Referenced by gs_update_curmask(), gsbm_make_mask(), gsds_alloc_typbuff(), IL_create_bitmask(), and 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 88 of file bitmap.c.

References BM_destroy_sparse().

Referenced by free_data_buffs(), gs_update_curmask(), and main().

## 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 299 of file bitmap.c.

References link_init(), link_new(), link_set_chunk_size(), and NULL.

Referenced by main().

## 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 258 of file bitmap.c.

References BM_file_write_sparse().

Referenced by main().

## 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 213 of file bitmap.c.

References BM_col_to_bit, BM_col_to_byte, BM_get_sparse(), and x.

Referenced by calc_norm(), get_mapatt(), gs_masked(), gs_point_is_masked(), gsbm_make_mask(), gsd_norm_arrows(), gsd_surf_const(), gsd_surf_map_old(), gsd_wire_arrows(), gsd_wire_surf_const(), gsd_wire_surf_map(), IL_grid_calc_2d(), IL_secpar_loop_2d(), main(), 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 236 of file bitmap.c.

References BM_get_map_size_sparse().

Referenced by free_data_buffs(), gsds_alloc_typbuff(), and main().

## 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 182 of file bitmap.c.

References BM_col_to_bit, BM_col_to_byte, BM_set_sparse(), and x.

Referenced by Gs_loadmap_as_bitmap(), Gs_loadmap_as_char(), Gs_loadmap_as_float(), Gs_loadmap_as_int(), Gs_loadmap_as_short(), 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 145 of file bitmap.c.