#include "config.h"
#include "common.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;
    int ret = 0;
    if(argc < 4)
    {
        fprintf(stderr, "%s: too few arguments\n", argv[0]);
        fprintf(stderr, "Usage: %s <src> <x> <y> <dest>\n", argv[0]);
        return EXIT_FAILURE;
    }

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

    img = pipi_load(srcname);

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

    newimg = pipi_copy(img);
    pipi_free(img);
    ret = pipi_flood_fill(newimg, atoi(argv[2]), atoi(argv[3]), 1, 0, 0, 1);

    if(!ret) pipi_save(newimg, dstname);


    pipi_free(newimg);

    return ret;
}