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.
 
 
 
 
 
 

103 rindas
2.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. * 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(!ret)
  33. ret = pipi_load_oric(name);
  34. #if USE_IMLIB2
  35. if(!ret)
  36. ret = pipi_load_imlib2(name);
  37. #endif
  38. #if USE_OPENCV
  39. if(!ret)
  40. ret = pipi_load_opencv(name);
  41. #endif
  42. #if USE_SDL
  43. if(!ret)
  44. ret = pipi_load_sdl(name);
  45. #endif
  46. #if USE_GDI
  47. if(!ret)
  48. ret = pipi_load_gdi(name);
  49. #endif
  50. return ret;
  51. }
  52. void pipi_free(pipi_image_t *img)
  53. {
  54. int i;
  55. for(i = 0; i < PIPI_PIXELS_MAX; i++)
  56. if(i != img->codec_format && img->p[i].pixels)
  57. free(img->p[i].pixels);
  58. if(img->codec_priv)
  59. img->codec_free(img);
  60. free(img);
  61. }
  62. int pipi_save(pipi_image_t *img, const char *name)
  63. {
  64. int ret = -1;
  65. if(ret < 0)
  66. ret = pipi_save_oric(img, name);
  67. #if USE_IMLIB2
  68. if(ret < 0)
  69. ret = pipi_save_imlib2(img, name);
  70. #endif
  71. #if USE_OPENCV
  72. if(ret < 0)
  73. ret = pipi_save_opencv(img, name);
  74. #endif
  75. #if USE_SDL
  76. if(ret < 0)
  77. ret = pipi_save_sdl(img, name);
  78. #endif
  79. #if USE_GDI
  80. if(ret < 0)
  81. ret = pipi_save_gdi(img, name);
  82. #endif
  83. return ret;
  84. }