Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

113 wiersze
2.9 KiB

  1. /*
  2. * libpipi Pathetic image processing interface 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 <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <Imlib2.h>
  22. #include "pipi.h"
  23. #include "pipi_internals.h"
  24. static int pipi_free_imlib2(pipi_image_t *);
  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_RGBA_C].pixels = imlib_image_get_data();
  34. img->p[PIPI_PIXELS_RGBA_C].w = img->w;
  35. img->p[PIPI_PIXELS_RGBA_C].h = img->h;
  36. img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * img->w;
  37. img->p[PIPI_PIXELS_RGBA_C].bpp = 32;
  38. img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h;
  39. img->last_modified = PIPI_PIXELS_RGBA_C;
  40. img->codec_priv = (void *)priv;
  41. img->codec_format = PIPI_PIXELS_RGBA_C;
  42. img->codec_free = pipi_free_imlib2;
  43. img->wrap = 0;
  44. img->u8 = 1;
  45. return img;
  46. }
  47. int 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_RGBA_C)
  57. {
  58. memcpy(data, img->p[PIPI_PIXELS_RGBA_C].pixels,
  59. 4 * img->w * img->h);
  60. free(img->p[PIPI_PIXELS_RGBA_C].pixels);
  61. }
  62. img->p[PIPI_PIXELS_RGBA_C].pixels = data;
  63. img->p[PIPI_PIXELS_RGBA_C].w = imlib_image_get_width();
  64. img->p[PIPI_PIXELS_RGBA_C].h = imlib_image_get_height();
  65. img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * imlib_image_get_width();
  66. img->p[PIPI_PIXELS_RGBA_C].bpp = 32;
  67. img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h;
  68. img->codec_priv = (void *)priv;
  69. img->codec_format = PIPI_PIXELS_RGBA_C;
  70. img->codec_free = pipi_free_imlib2;
  71. img->wrap = 0;
  72. img->u8 = 1;
  73. }
  74. pipi_getpixels(img, img->codec_format);
  75. imlib_context_set_image(img->codec_priv);
  76. imlib_save_image(name);
  77. return 0;
  78. }
  79. /*
  80. * XXX: The following functions are local.
  81. */
  82. static int pipi_free_imlib2(pipi_image_t *img)
  83. {
  84. imlib_context_set_image(img->codec_priv);
  85. imlib_free_image();
  86. return 0;
  87. }