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

Last change on this file since 2629 was 2629, checked in by Sam Hocevar, 14 years ago
  • pipi.c: reimplement pipi_new() without relying on the underlying codec library, so we can have several or none of them at some time.
  • sdl.c imlib.c: allow to save images that weren't created using the current codec.
File size: 2.4 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
32/* FIXME: this whole file is broken until we support BGR24 images */
33
34pipi_image_t *pipi_load_opencv(const char *name)
35{
36    pipi_image_t *img;
37    IplImage *priv = cvLoadImage(name, -1);
38
39    if(!priv)
40        return NULL;
41
42    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
43    memset(img, 0, sizeof(pipi_image_t));
44
45    img->w = priv->width;
46    img->h = priv->height;
47
48    img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
49    img->p[PIPI_PIXELS_RGBA32].w = priv->width;
50    img->p[PIPI_PIXELS_RGBA32].h = priv->height;
51    img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
52    img->last_modified = PIPI_PIXELS_RGBA32;
53
54    img->codec_priv = (void *)priv;
55    img->codec_format = PIPI_PIXELS_RGBA32;
56
57    return img;
58}
59
60pipi_image_t *pipi_new_opencv(int width, int height)
61{
62    pipi_image_t *img;
63    IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 4);
64
65    if(!priv)
66        return NULL;
67
68    img = (pipi_image_t *)malloc(sizeof(pipi_image_t));
69    memset(img, 0, sizeof(pipi_image_t));
70
71    img->w = priv->width;
72    img->h = priv->height;
73
74    img->p[PIPI_PIXELS_RGBA32].pixels = priv->imageData;
75    img->p[PIPI_PIXELS_RGBA32].w = priv->width;
76    img->p[PIPI_PIXELS_RGBA32].h = priv->height;
77    img->p[PIPI_PIXELS_RGBA32].pitch = priv->widthStep;
78    img->last_modified = PIPI_PIXELS_RGBA32;
79
80    img->codec_priv = (void *)priv;
81    img->codec_format = PIPI_PIXELS_RGBA32;
82
83    return img;
84}
85
86void pipi_free_opencv(pipi_image_t *img)
87{
88    IplImage *iplimg;
89    iplimg = (IplImage *)img->codec_priv;
90    cvReleaseImage(&iplimg);
91
92    free(img);
93}
94
95void pipi_save_opencv(pipi_image_t *img, const char *name)
96{
97    pipi_getpixels(img, img->codec_format);
98    cvSaveImage(name, img->codec_priv);
99}
100
Note: See TracBrowser for help on using the repository browser.