get_row_colr.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. * \file lib/raster/get_row_colr.c
  3. *
  4. * \brief Raster Library - Get raster row (colors)
  5. *
  6. * (C) 1999-2009 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. * \author USACERL and many others
  13. */
  14. #include <grass/gis.h>
  15. #include <grass/raster.h>
  16. #include "R.h"
  17. /*!
  18. * \brief Reads a row of raster data and converts it to RGB.
  19. *
  20. * Reads a row of raster data and converts it to red, green and blue
  21. * components according to the <em>colors</em> parameter. This
  22. * provides a convenient way to treat a raster layer as a color image
  23. * without having to explicitly cater for each of <tt>CELL</tt>,
  24. * <tt>FCELL</tt> and <tt>DCELL</tt> types.
  25. *
  26. * \param fd field descriptor
  27. * \param row row number
  28. * \param colors pointer to Colors structure which holds color info
  29. * \param[out] red red value
  30. * \param[out] grn green value
  31. * \param[out] blu blue value
  32. * \param[out] nul null value
  33. *
  34. * \return void
  35. */
  36. void Rast_get_row_colors(int fd, int row, struct Colors *colors,
  37. unsigned char *red, unsigned char *grn,
  38. unsigned char *blu, unsigned char *nul)
  39. {
  40. int cols = Rast_window_cols();
  41. int type = Rast_get_map_type(fd);
  42. int size = Rast_cell_size(type);
  43. void *array;
  44. unsigned char *set;
  45. void *p;
  46. int i;
  47. array = G_alloca(cols * size);
  48. Rast_get_row(fd, array, row, type);
  49. if (nul)
  50. for (i = 0, p = array; i < cols; i++, p = G_incr_void_ptr(p, size))
  51. nul[i] = Rast_is_null_value(p, type);
  52. set = G_alloca(cols);
  53. Rast_lookup_colors(array, red, grn, blu, set, cols, colors, type);
  54. G_freea(array);
  55. G_freea(set);
  56. }