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.
 
 
 
 
 
 

91 lines
2.3 KiB

  1. /*
  2. * libpipi Proper image processing implementation 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. * image.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 <cv.h>
  23. #include <highgui.h>
  24. #include "pipi.h"
  25. #include "pipi_internals.h"
  26. /* FIXME: this whole file is broken until we support BGR24 images */
  27. pipi_image_t *pipi_load_opencv(const char *name)
  28. {
  29. pipi_image_t *img;
  30. IplImage *priv = cvLoadImage(name, 1);
  31. if(!priv)
  32. return NULL;
  33. img = pipi_new(priv->width, priv->height);
  34. img->p[PIPI_PIXELS_BGR24].pixels = priv->imageData;
  35. img->p[PIPI_PIXELS_BGR24].w = priv->width;
  36. img->p[PIPI_PIXELS_BGR24].h = priv->height;
  37. img->p[PIPI_PIXELS_BGR24].pitch = priv->widthStep;
  38. img->last_modified = PIPI_PIXELS_BGR24;
  39. img->codec_priv = (void *)priv;
  40. img->codec_format = PIPI_PIXELS_BGR24;
  41. return img;
  42. }
  43. void pipi_free_opencv(pipi_image_t *img)
  44. {
  45. IplImage *iplimg;
  46. iplimg = (IplImage *)img->codec_priv;
  47. cvReleaseImage(&iplimg);
  48. }
  49. void pipi_save_opencv(pipi_image_t *img, const char *name)
  50. {
  51. if(!img->codec_priv)
  52. {
  53. IplImage *priv = cvCreateImage(cvSize(img->w, img->h),
  54. IPL_DEPTH_8U, 3);
  55. /* FIXME: check pitch differences here */
  56. if(img->last_modified == PIPI_PIXELS_BGR24)
  57. {
  58. memcpy(priv->imageData, img->p[PIPI_PIXELS_BGR24].pixels,
  59. 3 * img->w * img->h);
  60. free(img->p[PIPI_PIXELS_BGR24].pixels);
  61. }
  62. img->p[PIPI_PIXELS_BGR24].pixels = priv->imageData;
  63. img->p[PIPI_PIXELS_BGR24].w = priv->width;
  64. img->p[PIPI_PIXELS_BGR24].h = priv->height;
  65. img->p[PIPI_PIXELS_BGR24].pitch = priv->widthStep;
  66. img->codec_priv = (void *)priv;
  67. img->codec_format = PIPI_PIXELS_BGR24;
  68. }
  69. pipi_getpixels(img, img->codec_format);
  70. cvSaveImage(name, img->codec_priv);
  71. }