do_patch.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <grass/gis.h>
  2. #include <grass/raster.h>
  3. /*
  4. * patch in non-zero data over zero data
  5. * keep track of the categories which are patched in
  6. * for later use in constructing the new category and color files
  7. *
  8. * returns: 1 the result still contains nulls
  9. * 0 the result contains no zero nulls
  10. */
  11. int is_zero_value(void *rast, RASTER_MAP_TYPE data_type)
  12. {
  13. /* insert 0 check here */
  14. return Rast_is_null_value(rast, data_type) ||
  15. Rast_get_d_value(rast, data_type) != 0.0 ? 0 : 1;
  16. }
  17. int do_patch(void *result, void *patch,
  18. struct Cell_stats *statf, int ncols,
  19. RASTER_MAP_TYPE out_type, size_t out_cell_size, int use_zero)
  20. {
  21. int more;
  22. more = 0;
  23. while (ncols-- > 0) {
  24. if (use_zero) { /* use 0 for transparency instead of NULL */
  25. if (is_zero_value(result, out_type) ||
  26. Rast_is_null_value(result, out_type)) {
  27. /* Don't patch hole with a null, just mark as more */
  28. if (Rast_is_null_value(patch, out_type))
  29. more = 1;
  30. else {
  31. /* Mark that there is more to be done if we patch with 0 */
  32. if (is_zero_value(patch, out_type))
  33. more = 1;
  34. Rast_raster_cpy(result, patch, 1, out_type);
  35. if (out_type == CELL_TYPE)
  36. Rast_update_cell_stats((CELL *) result, 1, statf);
  37. }
  38. } /* ZERO support */
  39. }
  40. else { /* use NULL for transparency instead of 0 */
  41. if (Rast_is_null_value(result, out_type)) {
  42. if (Rast_is_null_value(patch, out_type))
  43. more = 1;
  44. else {
  45. Rast_raster_cpy(result, patch, 1, out_type);
  46. if (out_type == CELL_TYPE)
  47. Rast_update_cell_stats((CELL *) result, 1, statf);
  48. }
  49. } /* NULL support */
  50. }
  51. result = G_incr_void_ptr(result, out_cell_size);
  52. patch = G_incr_void_ptr(patch, out_cell_size);
  53. }
  54. return more;
  55. }