get_row_colr.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <grass/gis.h>
  2. #include "G.h"
  3. /*!
  4. * \brief
  5. *
  6. * Reads a row of raster data and converts it to red,
  7. * green and blue components according to the <em>colors</em> parameter.
  8. * This provides a convenient way to treat a raster layer as a color
  9. * image without having to explictly cater for each of <tt>CELL</tt>, <tt>FCELL</tt> and <tt>DCELL</tt> types
  10. *
  11. * \param fd
  12. * \param row
  13. * \param colors
  14. * \param red
  15. * \param grn
  16. * \param blu
  17. * \param nul
  18. * \return int
  19. */
  20. int
  21. G_get_raster_row_colors(int fd, int row, struct Colors *colors,
  22. unsigned char *red, unsigned char *grn,
  23. unsigned char *blu, unsigned char *nul)
  24. {
  25. int cols = G_window_cols();
  26. int type = G_get_raster_map_type(fd);
  27. int size = G_raster_size(type);
  28. void *array;
  29. unsigned char *set;
  30. void *p;
  31. int i;
  32. array = G__alloca(cols * size);
  33. if (G_get_raster_row(fd, array, row, type) < 0) {
  34. G__freea(array);
  35. return -1;
  36. }
  37. if (nul)
  38. for (i = 0, p = array; i < cols; i++, p = G_incr_void_ptr(p, size))
  39. nul[i] = G_is_null_value(p, type);
  40. set = G__alloca(cols);
  41. G_lookup_raster_colors(array, red, grn, blu, set, cols, colors, type);
  42. G__freea(array);
  43. G__freea(set);
  44. return 0;
  45. }