main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  23. main (int argc, char *argv[])
  24. {
  25. int SIZE;
  26. struct BM *map, *map2;
  27. int i, x, y;
  28. int dump;
  29. FILE *fp;
  30. if (argc < 2)
  31. SIZE = 11;
  32. else
  33. SIZE = atoi (argv[1]);
  34. if(NULL != getenv ("NODUMP"))
  35. dump = 0;
  36. else
  37. dump = 1;
  38. map = BM_create (SIZE, SIZE);
  39. /* turn on bits in X pattern */
  40. for (i = 0 ; i < SIZE ; i++)
  41. {
  42. BM_set (map, i, i, 1);
  43. BM_set (map, (SIZE-1)-i, i, 1);
  44. }
  45. if (dump)
  46. dump_map (map);
  47. fprintf (stdout, "Size = %d\n", BM_get_map_size (map));
  48. fprintf (stdout, "\n\n");
  49. /* now invert it */
  50. for (y = 0 ; y < SIZE ; y++)
  51. for (x = 0 ; x < SIZE ; x++)
  52. BM_set(map, x, y, !BM_get (map, x, y));
  53. if (dump)
  54. dump_map (map);
  55. fprintf (stdout, "Size = %d\n", BM_get_map_size (map));
  56. {
  57. fp = fopen ("dumpfile", "w");
  58. BM_file_write (fp, map);
  59. fclose (fp);
  60. fp = fopen ("dumpfile", "r");
  61. map2 = BM_file_read (fp);
  62. fclose (fp);
  63. dump_map (map2);
  64. }
  65. BM_destroy (map);
  66. BM_destroy (map2);
  67. return 0;
  68. }
  69. static int
  70. dump_map (struct BM *map)
  71. {
  72. int x, y;
  73. for (y = 0 ; y < map->rows ; y++)
  74. {
  75. for (x = 0 ; x < map->cols ; x++)
  76. {
  77. fprintf (stdout, "%c", BM_get(map, x, y) ? '#' : '.');
  78. }
  79. fprintf (stdout, "\n");
  80. }
  81. }