Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. }