A Simple X Image Viewer
 
 
 
 
 
 

50 line
1.4 KiB

  1. /* sxiv: image.c
  2. * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include "sxiv.h"
  21. #include "image.h"
  22. void imlib_init(win_t *win) {
  23. if (!win)
  24. return;
  25. imlib_context_set_display(win->env.dpy);
  26. imlib_context_set_visual(win->env.vis);
  27. imlib_context_set_colormap(win->env.cmap);
  28. imlib_context_set_drawable(win->xwin);
  29. }
  30. void img_load(img_t *img, char *filename) {
  31. if (!img || !filename)
  32. return;
  33. if (imlib_context_get_image())
  34. imlib_free_image();
  35. if (!(img->im = imlib_load_image(filename)))
  36. DIE("could not open image: %s", filename);
  37. imlib_context_set_image(img->im);
  38. img->w = imlib_image_get_width();
  39. img->h = imlib_image_get_height();
  40. }