You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.4 KiB

  1. /*
  2. * libpipi Proper image processing implementation library
  3. * Copyright (c) 2004-2008 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /*
  15. * imlib.c: ImLib I/O functions
  16. */
  17. #include "config.h"
  18. #include "common.h"
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <Imlib2.h>
  23. #include "pipi.h"
  24. #include "pipi_internals.h"
  25. pipi_image_t *pipi_load_imlib2(const char *name)
  26. {
  27. pipi_image_t *img;
  28. Imlib_Image priv = imlib_load_image(name);
  29. if(!priv)
  30. return NULL;
  31. imlib_context_set_image(priv);
  32. img = pipi_new(imlib_image_get_width(), imlib_image_get_height());
  33. img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
  34. img->p[PIPI_PIXELS_RGBA32].w = img->w;
  35. img->p[PIPI_PIXELS_RGBA32].h = img->h;
  36. img->p[PIPI_PIXELS_RGBA32].pitch = 4 * img->w;
  37. img->last_modified = PIPI_PIXELS_RGBA32;
  38. img->codec_priv = (void *)priv;
  39. img->codec_format = PIPI_PIXELS_RGBA32;
  40. return img;
  41. }
  42. void pipi_free_imlib2(pipi_image_t *img)
  43. {
  44. imlib_context_set_image(img->codec_priv);
  45. imlib_free_image();
  46. }
  47. void pipi_save_imlib2(pipi_image_t *img, const char *name)
  48. {
  49. if(!img->codec_priv)
  50. {
  51. Imlib_Image priv = imlib_create_image(img->w, img->h);
  52. void *data;
  53. imlib_context_set_image(priv);
  54. data = imlib_image_get_data();
  55. /* FIXME: check pitch differences here */
  56. if(img->last_modified == PIPI_PIXELS_RGBA32)
  57. {
  58. memcpy(data, img->p[PIPI_PIXELS_RGBA32].pixels,
  59. 4 * img->w * img->h);
  60. free(img->p[PIPI_PIXELS_RGBA32].pixels);
  61. }
  62. img->p[PIPI_PIXELS_RGBA32].pixels = data;
  63. img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
  64. img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
  65. img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
  66. img->codec_priv = (void *)priv;
  67. img->codec_format = PIPI_PIXELS_RGBA32;
  68. }
  69. pipi_getpixels(img, img->codec_format);
  70. imlib_context_set_image(img->codec_priv);
  71. imlib_save_image(name);
  72. }