read.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. \file lib/cairodriver/read.c
  3. \brief GRASS cairo display driver - read image (lower level functions)
  4. (C) 2007-2008, 2011 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 "cairodriver.h"
  11. void cairo_read_image(void)
  12. {
  13. G_debug(1, "read_image");
  14. if (!cairo || !surface)
  15. return;
  16. if (ca.file_type == FTYPE_PPM) {
  17. G_debug(1, "Reading image from %s", ca.file_name);
  18. cairo_read_ppm();
  19. }
  20. else if (ca.file_type == FTYPE_BMP) {
  21. G_debug(1, "Reading image from %s", ca.file_name);
  22. cairo_read_bmp();
  23. }
  24. #if CAIRO_HAS_PNG_FUNCTIONS
  25. else if (ca.file_type == FTYPE_PNG) {
  26. cairo_surface_t *img_surf;
  27. G_debug(1, "Reading image from %s", ca.file_name);
  28. img_surf = cairo_image_surface_create_from_png(ca.file_name);
  29. if (!img_surf)
  30. return;
  31. cairo_save(cairo);
  32. cairo_set_source_surface(cairo, img_surf, 0, 0);
  33. cairo_paint(cairo);
  34. cairo_restore(cairo);
  35. cairo_surface_destroy(img_surf);
  36. }
  37. #endif
  38. #if CAIRO_HAS_XLIB_XRENDER_SURFACE
  39. else if (ca.file_type == FTYPE_X11) {
  40. G_debug(1, "Reading XID from %s", ca.file_name);
  41. cairo_read_xid();
  42. }
  43. #endif
  44. /* vector format files are written directly to file */
  45. ca.modified = 0;
  46. }