#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <pipi.h>

int main(int argc, char *argv[])
{
    char *srcname = NULL, *dstname = NULL;
    pipi_image_t *img, *newimg, *tmp;
    pipi_histogram_t* histogram = NULL;
    int ret = 0;
    if(argc < 2)
    {
        fprintf(stderr, "%s: too few arguments\n", argv[0]);
        fprintf(stderr, "Usage: %s <src> <dest>\n", argv[0]);
        return EXIT_FAILURE;
    }

    srcname = argv[1];
    dstname = argv[2];

    img = pipi_load(srcname);

    if(!img) {
        fprintf(stderr, "Can't open %s for reading\n", srcname);
    }

    newimg = pipi_copy(img);
    pipi_free(img);


    tmp = pipi_copy(newimg);

    histogram = pipi_new_histogram();
    pipi_get_image_histogram(tmp, histogram, PIPI_COLOR_R|PIPI_COLOR_G|PIPI_COLOR_B);

    pipi_render_histogram(tmp, histogram, PIPI_COLOR_R|PIPI_COLOR_G|PIPI_COLOR_B);

    pipi_free_histogram(histogram);

    pipi_save(tmp, dstname);
    pipi_free(newimg);
    pipi_free(tmp);
    return ret;
}

