選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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