Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

102 řádky
2.7 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_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->wrap = 0;
  43. img->u8 = 1;
  44. return img;
  45. }
  46. void pipi_free_imlib2(pipi_image_t *img)
  47. {
  48. imlib_context_set_image(img->codec_priv);
  49. imlib_free_image();
  50. }
  51. void pipi_save_imlib2(pipi_image_t *img, const char *name)
  52. {
  53. if(!img->codec_priv)
  54. {
  55. Imlib_Image priv = imlib_create_image(img->w, img->h);
  56. void *data;
  57. imlib_context_set_image(priv);
  58. data = imlib_image_get_data();
  59. /* FIXME: check pitch differences here */
  60. if(img->last_modified == PIPI_PIXELS_RGBA_C)
  61. {
  62. memcpy(data, img->p[PIPI_PIXELS_RGBA_C].pixels,
  63. 4 * img->w * img->h);
  64. free(img->p[PIPI_PIXELS_RGBA_C].pixels);
  65. }
  66. img->p[PIPI_PIXELS_RGBA_C].pixels = data;
  67. img->p[PIPI_PIXELS_RGBA_C].w = imlib_image_get_width();
  68. img->p[PIPI_PIXELS_RGBA_C].h = imlib_image_get_height();
  69. img->p[PIPI_PIXELS_RGBA_C].pitch = 4 * imlib_image_get_width();
  70. img->p[PIPI_PIXELS_RGBA_C].bpp = 32;
  71. img->p[PIPI_PIXELS_RGBA_C].bytes = 4 * img->w * img->h;
  72. img->codec_priv = (void *)priv;
  73. img->codec_format = PIPI_PIXELS_RGBA_C;
  74. img->wrap = 0;
  75. img->u8 = 1;
  76. }
  77. pipi_getpixels(img, img->codec_format);
  78. imlib_context_set_image(img->codec_priv);
  79. imlib_save_image(name);
  80. }