Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

125 rader
2.4 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_JPEG
  34. if(!ret)
  35. ret = pipi_load_jpeg(name);
  36. #endif
  37. #if USE_IMLIB2
  38. if(!ret)
  39. ret = pipi_load_imlib2(name);
  40. #endif
  41. #if USE_OPENCV
  42. if(!ret)
  43. ret = pipi_load_opencv(name);
  44. #endif
  45. #if USE_SDL
  46. if(!ret)
  47. ret = pipi_load_sdl(name);
  48. #endif
  49. #if USE_GDIPLUS
  50. if(!ret)
  51. ret = pipi_load_gdiplus(name);
  52. #endif
  53. #if USE_GDI
  54. if(!ret)
  55. ret = pipi_load_gdi(name);
  56. #endif
  57. #if USE_COCOA
  58. if(!ret)
  59. ret = pipi_load_coreimage(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_JPEG
  79. if(ret < 0)
  80. ret = pipi_save_jpeg(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. }