Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

120 Zeilen
3.0 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. if(!imlib_image_get_data())
  33. {
  34. imlib_free_image();
  35. return NULL;
  36. }
  37. img = pipi_new(imlib_image_get_width(), imlib_image_get_height());
  38. img->p[PIPI_PIXELS_RGBA_C].pixels = imlib_image_get_data();
  39. img->p[PIPI_PIXELS_RGBA_C].w = img->w;
  40. img->p[PIPI_PIXELS_RGBA_C].h = img->h;
  41. img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * img->w;
  42. img->p[PIPI_PIXELS_RGBA_C].bpp = 32;
  43. img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h;
  44. img->last_modified = PIPI_PIXELS_RGBA_C;
  45. img->codec_priv = (void *)priv;
  46. img->codec_format = PIPI_PIXELS_RGBA_C;
  47. img->codec_free = pipi_free_imlib2;
  48. img->wrap = 0;
  49. img->u8 = 1;
  50. return img;
  51. }
  52. int pipi_save_imlib2(pipi_image_t *img, const char *name)
  53. {
  54. if(!img->codec_priv)
  55. {
  56. Imlib_Image priv = imlib_create_image(img->w, img->h);
  57. void *data;
  58. imlib_context_set_image(priv);
  59. data = imlib_image_get_data();
  60. /* FIXME: check pitch differences here */
  61. if(img->last_modified == PIPI_PIXELS_RGBA_C)
  62. {
  63. memcpy(data, img->p[PIPI_PIXELS_RGBA_C].pixels,
  64. 4 * img->w * img->h);
  65. free(img->p[PIPI_PIXELS_RGBA_C].pixels);
  66. }
  67. img->p[PIPI_PIXELS_RGBA_C].pixels = data;
  68. img->p[PIPI_PIXELS_RGBA_C].w = imlib_image_get_width();
  69. img->p[PIPI_PIXELS_RGBA_C].h = imlib_image_get_height();
  70. img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * imlib_image_get_width();
  71. img->p[PIPI_PIXELS_RGBA_C].bpp = 32;
  72. img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h;
  73. img->codec_priv = (void *)priv;
  74. img->codec_format = PIPI_PIXELS_RGBA_C;
  75. img->codec_free = pipi_free_imlib2;
  76. img->wrap = 0;
  77. img->u8 = 1;
  78. }
  79. pipi_set_colorspace(img, img->codec_format);
  80. imlib_context_set_image(img->codec_priv);
  81. imlib_save_image(name);
  82. return 0;
  83. }
  84. /*
  85. * XXX: The following functions are local.
  86. */
  87. static int pipi_free_imlib2(pipi_image_t *img)
  88. {
  89. imlib_context_set_image(img->codec_priv);
  90. imlib_free_image();
  91. return 0;
  92. }