main.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /****************************************************************************
  2. *
  3. * MODULE: bitmap
  4. * AUTHOR(S): David Gerdes (CERL) (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Brad Douglas <rez touchofmadness.com>,
  8. * Glynn Clements <glynn gclements.plus.com>
  9. * PURPOSE: provides basic support for the creation and manipulation of
  10. * two dimensional bitmap arrays
  11. * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
  12. *
  13. * This program is free software under the GNU General Public
  14. * License (>=v2). Read the file COPYING that comes with GRASS
  15. * for details.
  16. *
  17. *****************************************************************************/
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <grass/bitmap.h>
  21. static int dump_map(struct BM *map);
  22. int main(int argc, char *argv[])
  23. {
  24. int SIZE;
  25. struct BM *map, *map2;
  26. int i, x, y;
  27. int dump;
  28. FILE *fp;
  29. if (argc < 2)
  30. SIZE = 11;
  31. else
  32. SIZE = atoi(argv[1]);
  33. if (NULL != getenv("NODUMP"))
  34. dump = 0;
  35. else
  36. dump = 1;
  37. map = BM_create(SIZE, SIZE);
  38. /* turn on bits in X pattern */
  39. for (i = 0; i < SIZE; i++) {
  40. BM_set(map, i, i, 1);
  41. BM_set(map, (SIZE - 1) - i, i, 1);
  42. }
  43. if (dump)
  44. dump_map(map);
  45. fprintf(stdout, "Size = %d\n", BM_get_map_size(map));
  46. fprintf(stdout, "\n\n");
  47. /* now invert it */
  48. for (y = 0; y < SIZE; y++)
  49. for (x = 0; x < SIZE; x++)
  50. BM_set(map, x, y, !BM_get(map, x, y));
  51. if (dump)
  52. dump_map(map);
  53. fprintf(stdout, "Size = %d\n", BM_get_map_size(map));
  54. {
  55. fp = fopen("dumpfile", "w");
  56. BM_file_write(fp, map);
  57. fclose(fp);
  58. fp = fopen("dumpfile", "r");
  59. map2 = BM_file_read(fp);
  60. fclose(fp);
  61. dump_map(map2);
  62. }
  63. BM_destroy(map);
  64. BM_destroy(map2);
  65. return 0;
  66. }
  67. static int dump_map(struct BM *map)
  68. {
  69. int x, y;
  70. for (y = 0; y < map->rows; y++) {
  71. for (x = 0; x < map->cols; x++) {
  72. fprintf(stdout, "%c", BM_get(map, x, y) ? '#' : '.');
  73. }
  74. fprintf(stdout, "\n");
  75. }
  76. }