Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

100 rindas
2.5 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. memset(img, 0, sizeof(pipi_image_t));
  33. imlib_context_set_image(priv);
  34. img->w = imlib_image_get_width();
  35. img->h = imlib_image_get_height();
  36. img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
  37. img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
  38. img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
  39. img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
  40. img->last_modified = PIPI_PIXELS_RGBA32;
  41. img->codec_priv = (void *)priv;
  42. img->codec_format = PIPI_PIXELS_RGBA32;
  43. return img;
  44. }
  45. pipi_image_t *pipi_new_imlib2(int width, int height)
  46. {
  47. pipi_image_t *img;
  48. Imlib_Image priv = imlib_create_image(width, height);
  49. if(!priv)
  50. return NULL;
  51. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  52. memset(img, 0, sizeof(pipi_image_t));
  53. imlib_context_set_image(priv);
  54. img->w = imlib_image_get_width();
  55. img->h = imlib_image_get_height();
  56. img->p[PIPI_PIXELS_RGBA32].pixels = imlib_image_get_data();
  57. img->p[PIPI_PIXELS_RGBA32].w = imlib_image_get_width();
  58. img->p[PIPI_PIXELS_RGBA32].h = imlib_image_get_height();
  59. img->p[PIPI_PIXELS_RGBA32].pitch = 4 * imlib_image_get_width();
  60. img->last_modified = PIPI_PIXELS_RGBA32;
  61. img->codec_priv = (void *)priv;
  62. img->codec_format = PIPI_PIXELS_RGBA32;
  63. return img;
  64. }
  65. void pipi_free_imlib2(pipi_image_t *img)
  66. {
  67. imlib_context_set_image(img->codec_priv);
  68. imlib_free_image();
  69. free(img);
  70. }
  71. void pipi_save_imlib2(pipi_image_t *img, const char *name)
  72. {
  73. pipi_getpixels(img, img->codec_format);
  74. imlib_context_set_image(img->codec_priv);
  75. imlib_save_image(name);
  76. }