您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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->p[PIPI_PIXELS_BGR24].bpp = 24;
  39. img->p[PIPI_PIXELS_BGR24].bytes = 3 * img->w * img->h;
  40. img->last_modified = PIPI_PIXELS_BGR24;
  41. img->codec_priv = (void *)priv;
  42. img->codec_format = PIPI_PIXELS_BGR24;
  43. return img;
  44. }
  45. void pipi_free_opencv(pipi_image_t *img)
  46. {
  47. IplImage *iplimg;
  48. iplimg = (IplImage *)img->codec_priv;
  49. cvReleaseImage(&iplimg);
  50. }
  51. void pipi_save_opencv(pipi_image_t *img, const char *name)
  52. {
  53. if(!img->codec_priv)
  54. {
  55. IplImage *priv = cvCreateImage(cvSize(img->w, img->h),
  56. IPL_DEPTH_8U, 3);
  57. /* FIXME: check pitch differences here */
  58. if(img->last_modified == PIPI_PIXELS_BGR24)
  59. {
  60. memcpy(priv->imageData, img->p[PIPI_PIXELS_BGR24].pixels,
  61. 3 * img->w * img->h);
  62. free(img->p[PIPI_PIXELS_BGR24].pixels);
  63. }
  64. img->p[PIPI_PIXELS_BGR24].pixels = priv->imageData;
  65. img->p[PIPI_PIXELS_BGR24].w = priv->width;
  66. img->p[PIPI_PIXELS_BGR24].h = priv->height;
  67. img->p[PIPI_PIXELS_BGR24].pitch = priv->widthStep;
  68. img->p[PIPI_PIXELS_BGR24].bpp = 24;
  69. img->p[PIPI_PIXELS_BGR24].bytes = 3 * img->w * img->h;
  70. img->codec_priv = (void *)priv;
  71. img->codec_format = PIPI_PIXELS_BGR24;
  72. }
  73. pipi_getpixels(img, img->codec_format);
  74. cvSaveImage(name, img->codec_priv);
  75. }