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ů.
 
 
 
 
 
 

97 řádky
1.9 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. * codec.c: image 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 "pipi.h"
  23. #include "pipi_internals.h"
  24. pipi_image_t *pipi_load(char const *name)
  25. {
  26. pipi_image_t *ret = NULL;
  27. if(!strncmp(name, "random:", 7) ||
  28. !strncmp(name, "ediff:", 6) ||
  29. !strncmp(name, "halftone:", 6) ||
  30. !strncmp(name, "bayer:", 6))
  31. ret = pipi_load_stock(name);
  32. #if USE_IMLIB2
  33. if(!ret)
  34. ret = pipi_load_imlib2(name);
  35. #endif
  36. #if USE_OPENCV
  37. if(!ret)
  38. ret = pipi_load_opencv(name);
  39. #endif
  40. #if USE_SDL
  41. if(!ret)
  42. ret = pipi_load_sdl(name);
  43. #endif
  44. #if USE_GDI
  45. if(!ret)
  46. ret = pipi_load_gdi(name);
  47. #endif
  48. return ret;
  49. }
  50. void pipi_free(pipi_image_t *img)
  51. {
  52. int i;
  53. for(i = 0; i < PIPI_PIXELS_MAX; i++)
  54. if(i != img->codec_format && img->p[i].pixels)
  55. free(img->p[i].pixels);
  56. if(img->codec_priv)
  57. img->codec_free(img);
  58. free(img);
  59. }
  60. int pipi_save(pipi_image_t *img, const char *name)
  61. {
  62. int ret = -1;
  63. #if USE_IMLIB2
  64. if(ret < 0)
  65. ret = pipi_save_imlib2(img, name);
  66. #endif
  67. #if USE_OPENCV
  68. if(ret < 0)
  69. ret = pipi_save_opencv(img, name);
  70. #endif
  71. #if USE_SDL
  72. if(ret < 0)
  73. ret = pipi_save_sdl(img, name);
  74. #endif
  75. #if USE_GDI
  76. if(ret < 0)
  77. ret = pipi_save_gdi(img, name);
  78. #endif
  79. return ret;
  80. }