source: libpipi/trunk/pipi/codec/opencv.c @ 2605

Last change on this file since 2605 was 2605, checked in by Sam Hocevar, 15 years ago
  • Big API reorganisation. Now libpipi can transparently convert between colour spaces for a given image. For instance, if pipi_gaussian_blur is applied to a 32-bpp image, it is automatically converted to gamma-corrected 32-bit floats beforehands, then converted back to normal.
  • TODO: clipping, regions of interest, more formats, getpixel macros...
File size: 2.3 KB
Line 
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/*
16 * image.c: image I/O functions
17 */
18
19#include "config.h"
20#include "common.h"
21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include <cv.h>
27#include <highgui.h>
28
29#include "pipi.h"
30#include "pipi_internals.h"
31
32pipi_image_t *pipi_load_opencv(const char *name)
33{
34    pipi_image_t *img;
35    IplImage *priv = cvLoadImage(name, -1);
36
37    if(!priv)
38        return NULL;
39
40    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
41    memset(img, 0, sizeof(pipi_image_t));
42
43    img->w = priv->width;
44    img->h = priv->height;
45
46    img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
47    img->p[PIPI_PIXELS_RGBA32].w = priv->width;
48    img->p[PIPI_PIXELS_RGBA32].h = priv->height;
49    img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
50    img->last_modified = PIPI_PIXELS_RGBA32;
51
52    img->codec_priv = (void *)priv;
53    img->codec_format = PIPI_PIXELS_RGBA32;
54
55    return img;
56}
57
58pipi_image_t *pipi_new_opencv(int width, int height)
59{
60    pipi_image_t *img;
61    IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
62
63    if(!priv)
64        return NULL;
65
66    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
67    memset(img, 0, sizeof(pipi_image_t));
68
69    img->w = priv->width;
70    img->h = priv->height;
71
72    img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
73    img->p[PIPI_PIXELS_RGBA32].w = priv->width;
74    img->p[PIPI_PIXELS_RGBA32].h = priv->height;
75    img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
76    img->last_modified = PIPI_PIXELS_RGBA32;
77
78    img->codec_priv = (void *)priv;
79    img->codec_format = PIPI_PIXELS_RGBA32;
80
81    return img;
82}
83
84void pipi_free_opencv(pipi_image_t *img)
85{
86    IplImage *iplimg;
87    iplimg = (IplImage *)img->codec_priv;
88    cvReleaseImage(&iplimg);
89
90    free(img);
91}
92
93void pipi_save_opencv(pipi_image_t *img, const char *name)
94{
95    pipi_getpixels(img, img->codec_format);
96    cvSaveImage(name, img->codec_priv);
97}
98
Note: See TracBrowser for help on using the repository browser.