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.
 
 
 
 
 
 

85 line
2.0 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. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  32. imlib_context_set_image(priv);
  33. img->width = imlib_image_get_width();
  34. img->height = imlib_image_get_height();
  35. img->pitch = 4 * imlib_image_get_width();
  36. img->channels = 4;
  37. img->pixels = (char *)imlib_image_get_data();
  38. img->priv = (void *)priv;
  39. return img;
  40. }
  41. pipi_image_t *pipi_new_imlib2(int width, int height)
  42. {
  43. pipi_image_t *img;
  44. Imlib_Image priv = imlib_create_image(width, height);
  45. if(!priv)
  46. return NULL;
  47. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  48. imlib_context_set_image(priv);
  49. img->width = imlib_image_get_width();
  50. img->height = imlib_image_get_height();
  51. img->pitch = 4 * imlib_image_get_width();
  52. img->channels = 4;
  53. img->pixels = (char *)imlib_image_get_data();
  54. img->priv = (void *)priv;
  55. return img;
  56. }
  57. void pipi_free_imlib2(pipi_image_t *img)
  58. {
  59. imlib_context_set_image(img->priv);
  60. imlib_free_image();
  61. free(img);
  62. }
  63. void pipi_save_imlib2(pipi_image_t *img, const char *name)
  64. {
  65. imlib_context_set_image(img->priv);
  66. imlib_save_image(name);
  67. }