2019-09-09 16:02:44 +02:00
|
|
|
/*
|
|
|
|
* programme de test pour
|
|
|
|
* les fonctions de base.
|
|
|
|
*/
|
|
|
|
|
2019-06-29 23:50:03 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2019-08-07 11:55:29 +02:00
|
|
|
#include <string.h>
|
2019-08-08 17:16:20 +02:00
|
|
|
#include <math.h>
|
2019-06-29 23:50:03 +02:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
|
2020-01-07 13:46:09 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int essai_normalize(void)
|
|
|
|
{
|
|
|
|
FloatImg A;
|
|
|
|
float val;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
fimg_drand48(&A, 255.0);
|
|
|
|
val = fimg_get_maxvalue(&A);
|
|
|
|
fprintf(stderr, "BEFORE max pixel %f\n", val);
|
|
|
|
|
|
|
|
A.fval = 255.0; A.count = 1;
|
|
|
|
|
|
|
|
foo = fimg_normalize(&A, 1.0, 0);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s err normalize A %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = fimg_get_maxvalue(&A);
|
|
|
|
fprintf(stderr, "AFTER max pixel %f\n", val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-08-24 13:06:51 +02:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int essai_2gray(FloatImg *picz, char *outname)
|
|
|
|
{
|
2019-08-26 01:47:05 +02:00
|
|
|
int foo;
|
|
|
|
FloatImg gray;
|
2019-08-24 13:06:51 +02:00
|
|
|
|
2019-08-26 01:47:05 +02:00
|
|
|
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, outname);
|
2019-08-24 13:06:51 +02:00
|
|
|
|
2019-08-26 01:47:05 +02:00
|
|
|
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);
|
|
|
|
}
|
2019-08-24 13:06:51 +02:00
|
|
|
|
2019-08-26 01:47:05 +02:00
|
|
|
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);
|
2019-08-24 13:06:51 +02:00
|
|
|
|
2019-12-27 12:25:33 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
2019-08-26 01:47:05 +02:00
|
|
|
return 0;
|
2019-08-08 17:16:20 +02:00
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
2019-11-12 00:20:28 +01:00
|
|
|
|
|
|
|
int essai_contraste(char *fname)
|
|
|
|
{
|
|
|
|
int foo;
|
2019-11-12 19:31:00 +01:00
|
|
|
FloatImg dessin, copy;
|
2019-11-12 00:20:28 +01:00
|
|
|
double maxi;
|
|
|
|
|
|
|
|
foo = fimg_create_from_dump(fname, &dessin);
|
2019-11-12 19:31:00 +01:00
|
|
|
foo = fimg_clone(&dessin, ©, 0);
|
|
|
|
|
2019-11-12 00:20:28 +01:00
|
|
|
maxi = (double)fimg_get_maxvalue(&dessin);
|
2019-11-14 14:23:12 +01:00
|
|
|
fprintf(stderr, "image source valeur maxi = %f\n", maxi);
|
2019-11-12 00:20:28 +01:00
|
|
|
|
2019-11-12 19:31:00 +01:00
|
|
|
fimg_power_2(&dessin, ©, maxi);
|
2019-11-14 14:23:12 +01:00
|
|
|
maxi = (double)fimg_get_maxvalue(©);
|
2019-11-12 19:31:00 +01:00
|
|
|
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
|
|
|
|
fimg_dump_to_file(©, "power2.fimg", 0);
|
2019-11-12 00:20:28 +01:00
|
|
|
|
2019-11-12 19:31:00 +01:00
|
|
|
fimg_square_root(&dessin, ©, maxi);
|
2019-11-14 14:23:12 +01:00
|
|
|
maxi = (double)fimg_get_maxvalue(©);
|
2019-11-12 19:31:00 +01:00
|
|
|
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
|
|
|
|
fimg_dump_to_file(©, "squareroot.fimg", 0);
|
2019-11-12 00:20:28 +01:00
|
|
|
|
2019-11-14 14:23:12 +01:00
|
|
|
fimg_cos_01(&dessin, ©, maxi);
|
|
|
|
maxi = (double)fimg_get_maxvalue(©);
|
|
|
|
fprintf(stderr, "apres cos 01 valeur maxi = %f\n", maxi);
|
|
|
|
fimg_dump_to_file(©, "cos_01.fimg", 0);
|
2019-11-12 00:20:28 +01:00
|
|
|
|
2020-01-09 09:28:23 +01:00
|
|
|
fimg_cos_010(&dessin, ©, maxi);
|
|
|
|
maxi = (double)fimg_get_maxvalue(©);
|
|
|
|
fprintf(stderr, "apres cos 010 valeur maxi = %f\n", maxi);
|
|
|
|
fimg_dump_to_file(©, "cos_010.fimg", 0);
|
|
|
|
|
2019-11-12 00:20:28 +01:00
|
|
|
fimg_destroy(&dessin);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2019-09-09 16:02:44 +02:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
#define W 320
|
|
|
|
#define H 240
|
2019-06-29 23:50:03 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2020-01-07 13:46:09 +01:00
|
|
|
int foo, opt;
|
2019-11-12 00:20:28 +01:00
|
|
|
// char outname[100];
|
2019-09-10 01:31:48 +02:00
|
|
|
int gray = 0;
|
|
|
|
|
|
|
|
while ((opt = getopt(argc, argv, "gn:v")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'g': gray++; break;
|
2019-11-12 00:20:28 +01:00
|
|
|
case 'n': foo=atoi(optarg); break;
|
2019-09-10 01:31:48 +02:00
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
2019-06-29 23:50:03 +02:00
|
|
|
|
2019-09-10 01:31:48 +02:00
|
|
|
if (verbosity) fimg_print_version(0);
|
2019-08-07 11:55:29 +02:00
|
|
|
|
2020-01-07 13:46:09 +01:00
|
|
|
foo = essai_normalize();
|
|
|
|
fprintf(stderr, "retour essai normalize -> %d\n", foo);
|
2019-11-12 14:10:45 +01:00
|
|
|
|
2019-06-29 23:50:03 +02:00
|
|
|
return 0;
|
2019-07-08 06:28:04 +02:00
|
|
|
}
|