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 | pipi_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 | img->width = priv->width; |
---|
42 | img->height = priv->height; |
---|
43 | img->pitch = priv->widthStep; |
---|
44 | img->channels = priv->nChannels; |
---|
45 | img->pixels = priv->imageData; |
---|
46 | img->priv = (void *)priv; |
---|
47 | |
---|
48 | return img; |
---|
49 | } |
---|
50 | |
---|
51 | pipi_image_t *pipi_new_opencv(int width, int height) |
---|
52 | { |
---|
53 | pipi_image_t *img; |
---|
54 | IplImage *priv = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); |
---|
55 | |
---|
56 | if(!priv) |
---|
57 | return NULL; |
---|
58 | |
---|
59 | img = (pipi_image_t *)malloc(sizeof(pipi_image_t)); |
---|
60 | img->width = priv->width; |
---|
61 | img->height = priv->height; |
---|
62 | img->pitch = priv->widthStep; |
---|
63 | img->channels = priv->nChannels; |
---|
64 | img->pixels = priv->imageData; |
---|
65 | img->priv = (void *)priv; |
---|
66 | |
---|
67 | return img; |
---|
68 | } |
---|
69 | |
---|
70 | void pipi_free_opencv(pipi_image_t *img) |
---|
71 | { |
---|
72 | IplImage *iplimg; |
---|
73 | iplimg = (IplImage *)img->priv; |
---|
74 | cvReleaseImage(&iplimg); |
---|
75 | |
---|
76 | free(img); |
---|
77 | } |
---|
78 | |
---|
79 | void pipi_save_opencv(pipi_image_t *img, const char *name) |
---|
80 | { |
---|
81 | cvSaveImage(name, img->priv); |
---|
82 | } |
---|
83 | |
---|