raster2.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /********************************************************************
  2. * code in this file is designed to send raster data to the graphics
  3. * driver. It handles raster->color lookup translation, as well as
  4. * loading appropriate colormaps into the driver and the sending of
  5. * raster data to the plotter. The loading of colors is designed to
  6. * never send more colors than the hardware can support - even though
  7. * the GRASS drivers will allocate virtual colormaps to pretend there are more
  8. * This code effectively disables that driver feature/mistake.
  9. *
  10. * To simply plot raster data:
  11. *
  12. * to specify if overlay mode is to be used
  13. * D_set_overlay_mode(flag)
  14. * int flag; /1=yes,0=no/
  15. *
  16. * to select a raster color for line drawing
  17. * D_color (cat, colors)
  18. * CELL cat
  19. * struct Colors *colors; /color info/
  20. *
  21. * D_color_of_type(raster, colors, data_type);
  22. * void *raster;
  23. * struct Colors *colors; /color info/
  24. * RASTER_MAP_TYPE data_type;
  25. *
  26. * Note: the same Colors structure must be passed to all routines.
  27. *
  28. */
  29. #include <stdlib.h>
  30. #include <grass/gis.h>
  31. #include <grass/raster.h>
  32. #include <grass/display.h>
  33. int D__overlay_mode = 0; /* external for now, but to be fixed later */
  34. /*!
  35. * \brief Configure raster overlay mode
  36. *
  37. * This routine determines if D_draw_raster() draws in overlay mode
  38. * (locations with category 0 are left untouched) or not (colored with
  39. * the color for category 0).
  40. *
  41. * \param n 1 (TRUE) for overlay mode; 0 (FALSE) otherwise
  42. *
  43. * \return 0
  44. */
  45. int D_set_overlay_mode(int n)
  46. {
  47. D__overlay_mode = (n != 0);
  48. return 0;
  49. }
  50. /* this routine modifies the hardware colormap
  51. * provided that we are not using fixed mode colors.
  52. * For use by programs such as d.colors
  53. *
  54. * returns:
  55. * 0 error - in fixed mode,
  56. * or cat not in min:max color range
  57. * 1 ok
  58. */
  59. int D_color(CELL cat, struct Colors *colors)
  60. {
  61. return D_c_color(cat, colors);
  62. }
  63. /* select color for line drawing */
  64. int D_c_color(CELL cat, struct Colors *colors)
  65. {
  66. return D_color_of_type(&cat, colors, CELL_TYPE);
  67. }
  68. /* select color for line drawing */
  69. /*!
  70. * \brief
  71. *
  72. * Same functionality as <tt>D_color()</tt> except that the <em>value</em> is type
  73. * <tt>DCELL</tt>. This implies that the floating-point interfaces to the <em>colors</em>
  74. * are used by this routine.
  75. *
  76. * \param value
  77. * \param colors
  78. * \return int
  79. */
  80. int D_d_color(DCELL val, struct Colors *colors)
  81. {
  82. return D_color_of_type(&val, colors, DCELL_TYPE);
  83. }
  84. /* select color for line drawing */
  85. /*!
  86. * \brief
  87. *
  88. * Same
  89. * functionality as <tt>D_color()</tt> except that the <em>value</em> is type <tt>FCELL</tt>.
  90. * This implies that the floating-point interfaces to the <em>colors</em> are used by this routine.
  91. *
  92. * \param value
  93. * \param colors
  94. * \return int
  95. */
  96. int D_f_color(FCELL val, struct Colors *colors)
  97. {
  98. return D_color_of_type(&val, colors, FCELL_TYPE);
  99. }
  100. /*!
  101. * \brief
  102. *
  103. * If the <em>data_type</em> is CELL_TYPE,
  104. * calls D_color((CELL *value, colors);
  105. * If the <em>data_type</em> is FCELL_TYPE, calls D_f_color((FCELL *value,
  106. * colors);
  107. * If the <em>data_type</em> is DCELL_TYPE, calls D_d_color((DCELL *value,
  108. * colors);
  109. *
  110. * \param value
  111. * \param colors
  112. * \param data_type
  113. * \return int
  114. */
  115. int D_color_of_type(const void *raster,
  116. struct Colors *colors, RASTER_MAP_TYPE data_type)
  117. {
  118. int r, g, b;
  119. Rast_get_color(raster, &r, &g, &b, colors, data_type);
  120. D_RGB_color((unsigned char)r, (unsigned char)g, (unsigned char)b);
  121. return 0;
  122. }