Draw_bitmap.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*!
  2. \file cairodriver/Draw_bitmap.c
  3. \brief GRASS cairo display driver - draw bitmap
  4. (C) 2007-2008 by Lars Ahlzen and the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. \author Lars Ahlzen <lars ahlzen.com> (original contibutor)
  8. \author Glynn Clements
  9. */
  10. #include <grass/glocale.h>
  11. #include "cairodriver.h"
  12. /*!
  13. \brief Draw bitmap
  14. \param ncols,nrows number of columns and rows
  15. \param threshold threshold value
  16. \param buf data buffer
  17. */
  18. void Cairo_Bitmap(int ncols, int nrows, int threshold,
  19. const unsigned char *buf)
  20. {
  21. cairo_surface_t *surf;
  22. int stride;
  23. unsigned char *data;
  24. int i;
  25. G_debug(1, "Cairo_Bitmap: %d %d %d", ncols, nrows, threshold);
  26. stride = cairo_format_stride_for_width(CAIRO_FORMAT_A8, ncols);
  27. data = malloc(stride * nrows);
  28. surf = cairo_image_surface_create_for_data(
  29. data, CAIRO_FORMAT_A8, ncols, nrows, stride);
  30. if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS)
  31. G_fatal_error(_("Cairo_Bitmap: Failed to create source"));
  32. for (i = 0; i < nrows; i++)
  33. memcpy(&data[i * stride], &buf[i * ncols], ncols);
  34. cairo_mask_surface(cairo, surf, cur_x, cur_y);
  35. cairo_surface_destroy(surf);
  36. ca.modified = 1;
  37. }