FloatImg4PythonBinding/lib/t.c

148 lines
3.2 KiB
C

/*
* programme de test pour
* les fonctions de base.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include "../floatimg.h"
int verbosity;
/* ---------------------------------------------------------------- */
int essai_2gray(FloatImg *picz, char *outname)
{
int foo;
FloatImg gray;
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, outname);
foo = fimg_create(&gray, picz->width, picz->height, FIMG_TYPE_GRAY);
if (foo) {
fprintf(stderr, "%s : err %d on fimg create\n", __func__, foo);
exit(1);
}
foo = fimg_mk_gray_from(picz, &gray, 0);
if (foo) {
fprintf(stderr, "%s : err %d on fimg mk_gray_from\n", __func__, foo);
exit(1);
}
foo = fimg_save_as_pnm(&gray, outname, 0);
if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1);
}
fimg_destroy(&gray);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_clone_et_copy(int unused)
{
FloatImg A, B, C;
int foo;
foo = fimg_create(&A, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
foo = fimg_draw_something(&A);
if (foo) {
fprintf(stderr, "%s err drawing A %d\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
if (foo) {
fprintf(stderr, "%s : err %d on save_as_pnm\n", __func__, foo);
exit(1);
}
foo = fimg_clone(&A, &B, 1);
if (foo) {
fprintf(stderr, "%s err clone B %d\n", __func__, foo);
return foo;
}
foo = fimg_create(&C, 512, 512, FIMG_TYPE_RGB);
if (foo) {
fprintf(stderr, "%s err create A %d\n", __func__, foo);
return foo;
}
foo = fimg_copy_data(&A, &C);
if (foo) {
fprintf(stderr, "%s err copydata %d\n", __func__, foo);
return foo;
}
foo = fimg_save_as_pnm(&C, "C.pnm", 0);
return 0;
}
/* ---------------------------------------------------------------- */
int essai_contraste(char *fname)
{
int foo;
FloatImg dessin, copy;
double maxi;
foo = fimg_create_from_dump(fname, &dessin);
foo = fimg_clone(&dessin, &copy, 0);
maxi = (double)fimg_get_maxvalue(&dessin);
fprintf(stderr, "image source valeur maxi = %f\n", maxi);
fimg_power_2(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "power2.fimg", 0);
fimg_square_root(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "squareroot.fimg", 0);
fimg_cos_01(&dessin, &copy, maxi);
maxi = (double)fimg_get_maxvalue(&copy);
fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi);
fimg_dump_to_file(&copy, "cos_01.fimg", 0);
fimg_destroy(&dessin);
return -1;
}
/* ---------------------------------------------------------------- */
#define W 320
#define H 240
int main(int argc, char *argv[])
{
int foo, idx, opt;
// char outname[100];
int gray = 0;
while ((opt = getopt(argc, argv, "gn:v")) != -1) {
switch(opt) {
case 'g': gray++; break;
case 'n': foo=atoi(optarg); break;
case 'v': verbosity++; break;
}
}
if (verbosity) fimg_print_version(0);
foo = essai_clone_et_copy(0);
fprintf(stderr, "retour essai clone_et_copy -> %d\n", foo);
return 0;
}