Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. pipi_image_t *pipi_load_opencv(const char *name)
  27. {
  28. pipi_image_t *img;
  29. IplImage *priv = cvLoadImage(name, -1);
  30. if(!priv)
  31. return NULL;
  32. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  33. memset(img, 0, sizeof(pipi_image_t));
  34. img->w = priv->width;
  35. img->h = priv->height;
  36. img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
  37. img->p[PIPI_PIXELS_RGBA32].w = priv->width;
  38. img->p[PIPI_PIXELS_RGBA32].h = priv->height;
  39. img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
  40. img->last_modified = PIPI_PIXELS_RGBA32;
  41. img->codec_priv = (void *)priv;
  42. img->codec_format = PIPI_PIXELS_RGBA32;
  43. return img;
  44. }
  45. pipi_image_t *pipi_new_opencv(int width, int height)
  46. {
  47. pipi_image_t *img;
  48. IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
  49. if(!priv)
  50. return NULL;
  51. img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
  52. memset(img, 0, sizeof(pipi_image_t));
  53. img->w = priv->width;
  54. img->h = priv->height;
  55. img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
  56. img->p[PIPI_PIXELS_RGBA32].w = priv->width;
  57. img->p[PIPI_PIXELS_RGBA32].h = priv->height;
  58. img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
  59. img->last_modified = PIPI_PIXELS_RGBA32;
  60. img->codec_priv = (void *)priv;
  61. img->codec_format = PIPI_PIXELS_RGBA32;
  62. return img;
  63. }
  64. void pipi_free_opencv(pipi_image_t *img)
  65. {
  66. IplImage *iplimg;
  67. iplimg = (IplImage *)img->codec_priv;
  68. cvReleaseImage(&iplimg);
  69. free(img);
  70. }
  71. void pipi_save_opencv(pipi_image_t *img, const char *name)
  72. {
  73. pipi_getpixels(img, img->codec_format);
  74. cvSaveImage(name, img->codec_priv);
  75. }