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.
 
 
 
 
 
 

106 lines
2.1 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. #if USE_COCOA
  51. if(!ret)
  52. ret = pipi_load_coreimage(name);
  53. #endif
  54. return ret;
  55. }
  56. void pipi_free(pipi_image_t *img)
  57. {
  58. int i;
  59. for(i = 0; i < PIPI_PIXELS_MAX; i++)
  60. if(i != img->codec_format && img->p[i].pixels)
  61. free(img->p[i].pixels);
  62. if(img->codec_priv)
  63. img->codec_free(img);
  64. free(img);
  65. }
  66. int pipi_save(pipi_image_t *img, const char *name)
  67. {
  68. int ret = -1;
  69. if(ret < 0)
  70. ret = pipi_save_oric(img, name);
  71. #if USE_IMLIB2
  72. if(ret < 0)
  73. ret = pipi_save_imlib2(img, name);
  74. #endif
  75. #if USE_OPENCV
  76. if(ret < 0)
  77. ret = pipi_save_opencv(img, name);
  78. #endif
  79. #if USE_SDL
  80. if(ret < 0)
  81. ret = pipi_save_sdl(img, name);
  82. #endif
  83. #if USE_GDI
  84. if(ret < 0)
  85. ret = pipi_save_gdi(img, name);
  86. #endif
  87. return ret;
  88. }