Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_GDIPLUS
  46. if(!ret)
  47. ret = pipi_load_gdiplus(name);
  48. #endif
  49. #if USE_GDI
  50. if(!ret)
  51. ret = pipi_load_gdi(name);
  52. #endif
  53. #if USE_COCOA
  54. if(!ret)
  55. ret = pipi_load_coreimage(name);
  56. #endif
  57. #if USE_MODULAR
  58. if(!ret)
  59. ret = pipi_load_modular(name);
  60. #endif
  61. return ret;
  62. }
  63. void pipi_free(pipi_image_t *img)
  64. {
  65. int i;
  66. for(i = 0; i < PIPI_PIXELS_MAX; i++)
  67. if(i != img->codec_format && img->p[i].pixels)
  68. free(img->p[i].pixels);
  69. if(img->codec_priv)
  70. img->codec_free(img);
  71. free(img);
  72. }
  73. int pipi_save(pipi_image_t *img, const char *name)
  74. {
  75. int ret = -1;
  76. if(ret < 0)
  77. ret = pipi_save_oric(img, name);
  78. #if USE_MODULAR
  79. if(ret < 0)
  80. ret = pipi_save_modular(img, name);
  81. #endif
  82. #if USE_IMLIB2
  83. if(ret < 0)
  84. ret = pipi_save_imlib2(img, name);
  85. #endif
  86. #if USE_OPENCV
  87. if(ret < 0)
  88. ret = pipi_save_opencv(img, name);
  89. #endif
  90. #if USE_SDL
  91. if(ret < 0)
  92. ret = pipi_save_sdl(img, name);
  93. #endif
  94. #if USE_GDIPLUS
  95. if(ret < 0)
  96. ret = pipi_save_gdiplus(img, name);
  97. #endif
  98. #if USE_GDI
  99. if(ret < 0)
  100. ret = pipi_save_gdi(img, name);
  101. #endif
  102. #if USE_COCOA
  103. if(ret < 0)
  104. ret = pipi_save_coreimage(img, name);
  105. #endif
  106. return ret;
  107. }