source: libpipi/trunk/examples/histogram.c @ 3082

Last change on this file since 3082 was 3082, checked in by Jean-Yves Lamoureux, 12 years ago
  • Fixed a memory leak in histogram example
File size: 1.0 KB
Line 
1#include "config.h"
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <string.h>
6
7#include <pipi.h>
8
9int main(int argc, char *argv[])
10{
11    char *srcname = NULL, *dstname = NULL;
12    pipi_image_t *img, *newimg, *tmp;
13    pipi_histogram_t* histogram = NULL;
14    int ret = 0;
15    if(argc < 2)
16    {
17        fprintf(stderr, "%s: too few arguments\n", argv[0]);
18        fprintf(stderr, "Usage: %s <src> <dest>\n", argv[0]);
19        return EXIT_FAILURE;
20    }
21
22    srcname = argv[1];
23    dstname = argv[2];
24
25    img = pipi_load(srcname);
26
27    if(!img) {
28        fprintf(stderr, "Can't open %s for reading\n", srcname);
29    }
30
31    newimg = pipi_copy(img);
32    pipi_free(img);
33
34
35    tmp = pipi_copy(newimg);
36
37    histogram = pipi_new_histogram();
38    pipi_get_image_histogram(tmp, histogram, PIPI_COLOR_R|PIPI_COLOR_G|PIPI_COLOR_B);
39
40    pipi_render_histogram(tmp, histogram, PIPI_COLOR_R|PIPI_COLOR_G|PIPI_COLOR_B);
41
42    pipi_free_histogram(histogram);
43
44    pipi_save(tmp, dstname);
45    pipi_free(newimg);
46    pipi_free(tmp);
47    return ret;
48}
49
Note: See TracBrowser for help on using the repository browser.