#include <amscimglib4/amscimglib4.h>
#include <amscimglib4/amscimglib4_intl.h>

#ifdef __cplusplus
extern "C" {  
#endif

void amscimglib4_test_init()
{
    amscimglib4_image *img1 = NULL;
    amscimglib4_image *img2 = NULL;
    int res;

    printf("Testing basic image operations for memory leaks...\n");
    printf("use valgrind...\n");
    
    res = amscimglib4_image_new(&img1,1000,1000); printf("res=%d (%d,%d)\n",res,img1->sizex,img1->sizey);
    res = amscimglib4_image_new(&img2,200,1000); printf("res=%d (%d,%d)\n",res,img2->sizex,img2->sizey);
    
    res = amscimglib4_image_resize(img1,500,500); printf("res=%d (%d,%d)\n",res,img1->sizex,img1->sizey);
    res = amscimglib4_image_copy(img2,img1); printf("res=%d, img2=(%d,%d), img1=(%d,%d)\n",res, img2->sizex,img2->sizey,img1->sizex,img1->sizey);

    amscimglib4_image_delete(&img1);
    amscimglib4_image_delete(&img2);
    
}

AMSCIMGLIB4_API void amscimglib4_test_loadsave()
{
    printf("Testing basic image loading/saving and conversion...\n");

    amscimglib4_image *img1 = NULL;
    amscimglib4_image *img2 = NULL;

    amscimglib4_image_new(&img1,1,1);
    amscimglib4_image_new(&img2,1,1);

    amscimglib4_readimage_bmp("../testimg/testpfp0.bmp",img1);
    printf("read in (%d,%d) bitmap image.\n",img1->sizex,img1->sizey);
    amscimglib4_image_flipx(img1);
    amscimglib4_writeimage_bmp("../testimg/testpfp0_1.bmp",img1);
    amscimglib4_writeimage_jpeg("../testimg/testpfp0_2.jpg",img1,90);
    amscimglib4_writeimage_png("../testimg/testpfp0_3.png",img1);

    amscimglib4_readimage("../testimg/testpfp0.png",img1);
    printf("read in (%d,%d) png image.\n",img1->sizex,img1->sizey);
    amscimglib4_transpose_image(img1);
    amscimglib4_writeimage("../testimg/testpfp1_1.bmp",img1);
    amscimglib4_writeimage("../testimg/testpfp1_2.png",img1);
    amscimglib4_writeimage("../testimg/testpfp1_3.jpg",img1);

    amscimglib4_readimage("../testimg/testpfp0.jpg",img1);
    printf("read in (%d,%d) jpg image.\n",img1->sizex,img1->sizey);
    amscimglib4_image_flipy(img1);
    amscimglib4_writeimage("../testimg/testpfp2_1.bmp",img1);
    amscimglib4_writeimage("../testimg/testpfp2_2.png",img1);
    amscimglib4_writeimage("../testimg/testpfp2_3.jpg",img1);

    amscimglib4_image_delete(&img1);
    amscimglib4_image_delete(&img2);

}

#ifdef __cplusplus
}; //end extern "C"
#endif