You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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