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>
|
2021-11-02 15:38:10 +01:00
|
|
|
#include <stdint.h>
|
2019-06-29 23:50:03 +02:00
|
|
|
#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;
|
|
|
|
|
2022-03-19 01:21:58 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int essai_metadata(char *fname)
|
|
|
|
{
|
|
|
|
FimgMetaData Md;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
fprintf(stderr, "-------- %s ( %s ) --------\n", __func__, fname);
|
|
|
|
|
2022-07-06 10:27:55 +02:00
|
|
|
foo = fimg_default_metadata(&Md, 0);
|
2022-03-19 01:21:58 +01:00
|
|
|
|
2022-04-09 23:18:14 +02:00
|
|
|
// foo = fimg_show_metadata(&Md, "default from t.c", 0);
|
|
|
|
|
|
|
|
foo = fimg_get_metadata_from_file(fname, &Md);
|
|
|
|
fprintf(stderr, "%s : get metadata -> %d\n", fname, foo);
|
2022-04-17 04:25:31 +02:00
|
|
|
if (foo) {
|
|
|
|
return foo;
|
|
|
|
}
|
2022-04-09 23:18:14 +02:00
|
|
|
|
|
|
|
foo = fimg_show_metadata(&Md, fname, 0);
|
2022-07-06 10:27:55 +02:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: show metadata -> %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
return 0;
|
2022-03-19 01:21:58 +01:00
|
|
|
}
|
2022-02-28 20:00:20 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int essai_save_plane(int wot)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
FloatImg image;
|
|
|
|
|
|
|
|
fprintf(stderr, "-------- %s ( %d ) --------\n", __func__, wot);
|
|
|
|
|
|
|
|
foo = fimg_create_from_dump("grabbed.fimg", &image);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err loading picz\n");
|
|
|
|
return -6;
|
|
|
|
}
|
|
|
|
foo = fimg_save_plane_as_pgm(&image, "red.pgm", 'r');
|
2022-03-02 00:59:36 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err save red %d\n", foo);
|
|
|
|
return -6;
|
|
|
|
}
|
2022-02-28 20:00:20 +01:00
|
|
|
foo = fimg_save_plane_as_pgm(&image, "green.pgm", 'g');
|
2022-03-02 00:59:36 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err save green %d\n", foo);
|
|
|
|
return -6;
|
|
|
|
}
|
2022-02-28 20:00:20 +01:00
|
|
|
foo = fimg_save_plane_as_pgm(&image, "blue.pgm", 'b');
|
2022-03-02 00:59:36 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "err save blue %d\n", foo);
|
|
|
|
return -6;
|
|
|
|
}
|
2022-02-28 20:00:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-14 13:52:04 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int essai_timer(int uuuh)
|
|
|
|
{
|
|
|
|
double A, B;
|
|
|
|
|
|
|
|
fprintf(stderr, ">>> %s ( %d )\n", __func__, uuuh);
|
|
|
|
|
|
|
|
A = fimg_timer_set(uuuh);
|
|
|
|
sleep(4);
|
|
|
|
B = fimg_timer_get(uuuh);
|
|
|
|
|
|
|
|
fprintf(stderr, " %f %f\n", A, B);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-01-07 13:46:09 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
2022-07-11 06:12:25 +02:00
|
|
|
int essai_alphachan(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return -1984;
|
|
|
|
}
|
2020-01-10 12:01:12 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
#define WI 1024
|
|
|
|
#define HI 768
|
|
|
|
#define KDEG 3.141592654 /* secret magic number */
|
|
|
|
|
|
|
|
int essai_interpolate(int k)
|
|
|
|
{
|
|
|
|
FloatImg A, B, C;
|
2020-02-16 23:16:38 +01:00
|
|
|
int foo, idx;
|
|
|
|
char ligne[200];
|
2022-04-09 23:18:14 +02:00
|
|
|
float fval;
|
2020-01-10 12:01:12 +01:00
|
|
|
|
|
|
|
foo = fimg_create(&A, WI, HI, FIMG_TYPE_RGB);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s err create A %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
2022-07-06 10:27:55 +02:00
|
|
|
if (k) fimg_hdeg_a(&A, KDEG);
|
|
|
|
else fimg_vdeg_a(&A, KDEG);
|
2020-01-10 12:01:12 +01:00
|
|
|
|
|
|
|
foo = fimg_create(&B, WI, HI, FIMG_TYPE_RGB);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s err create B %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
fimg_vdeg_a(&B, KDEG);
|
|
|
|
|
|
|
|
foo = fimg_create(&C, WI, HI, FIMG_TYPE_RGB);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s err create C %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2020-02-16 23:16:38 +01:00
|
|
|
#define NB 16
|
|
|
|
for (idx=0; idx<NB; idx++) {
|
|
|
|
fval = (float)idx / (float)NB;
|
|
|
|
if (verbosity) fprintf(stderr, "%4d %f\n", idx, fval);
|
|
|
|
foo = fimg_interpolate(&A, &B, &C, fval);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s err interpolate %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
sprintf(ligne, "polate-%02d.pnm", idx);
|
|
|
|
foo = fimg_save_as_pnm(&C, ligne, 0);
|
2020-01-10 12:01:12 +01:00
|
|
|
}
|
2020-02-16 23:16:38 +01:00
|
|
|
/*
|
|
|
|
$ convert -delay 10 polate-* foo.gif ; animate foo.gif
|
|
|
|
*/
|
2020-01-10 12:01:12 +01:00
|
|
|
fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C);
|
|
|
|
|
2020-01-07 13:46:09 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2019-08-24 13:06:51 +02:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
|
2022-02-09 23:21:58 +01:00
|
|
|
int essai_2gray(FloatImg *picz, char *basename)
|
2019-08-24 13:06:51 +02:00
|
|
|
{
|
2019-08-26 01:47:05 +02:00
|
|
|
int foo;
|
|
|
|
FloatImg gray;
|
2022-02-09 23:21:58 +01:00
|
|
|
char outname[200];
|
2019-08-24 13:06:51 +02:00
|
|
|
|
2022-02-09 23:21:58 +01:00
|
|
|
fprintf(stderr, ">>> %s ( %p '%s' )\n", __func__, picz, basename);
|
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
|
|
|
|
2022-02-09 23:21:58 +01:00
|
|
|
strcpy(outname,basename); strcat(outname, ".pnm");
|
2019-08-26 01:47:05 +02:00
|
|
|
foo = fimg_save_as_pnm(&gray, outname, 0);
|
|
|
|
if (foo) {
|
2022-02-09 23:21:58 +01:00
|
|
|
fprintf(stderr, "%s : err %d on save_as_PNM\n", __func__, foo);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
strcpy(outname,basename); strcat(outname, ".pgm");
|
|
|
|
foo = fimg_save_as_pgm(&gray, outname, 0);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s : err %d on save_as_PGM\n", __func__, foo);
|
2019-08-26 01:47:05 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fimg_destroy(&gray);
|
2019-08-24 13:06:51 +02:00
|
|
|
|
2019-12-27 12:25:33 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
2020-01-10 12:01:12 +01:00
|
|
|
#define TAILLE 1024
|
2019-12-27 12:25:33 +01:00
|
|
|
|
|
|
|
int essai_clone_et_copy(int unused)
|
|
|
|
{
|
|
|
|
FloatImg A, B, C;
|
|
|
|
int foo;
|
|
|
|
|
2021-03-09 11:55:48 +01:00
|
|
|
fprintf(stderr, "-------- %s ( %d ) --------\n", __func__, unused);
|
|
|
|
|
2020-01-10 12:01:12 +01:00
|
|
|
foo = fimg_create(&A, TAILLE, TAILLE, FIMG_TYPE_RGB);
|
2019-12-27 12:25:33 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-01-10 12:01:12 +01:00
|
|
|
foo = fimg_save_as_pnm(&A, "A.pnm", 0);
|
2019-12-27 12:25:33 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-01-10 12:01:12 +01:00
|
|
|
foo = fimg_create(&C, TAILLE, TAILLE, FIMG_TYPE_RGB);
|
2019-12-27 12:25:33 +01:00
|
|
|
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);
|
|
|
|
|
2020-01-10 12:01:12 +01:00
|
|
|
fimg_destroy(&A); fimg_destroy(&B); fimg_destroy(&C);
|
2019-12-27 12:25:33 +01:00
|
|
|
|
2019-08-26 01:47:05 +02:00
|
|
|
return 0;
|
2019-08-08 17:16:20 +02:00
|
|
|
}
|
2020-01-10 12:01:12 +01:00
|
|
|
|
|
|
|
#undef TAILLE
|
|
|
|
|
2020-03-02 01:19:57 +01:00
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
int essai_get_values(char *fname)
|
|
|
|
{
|
|
|
|
int foo;
|
|
|
|
FloatImg dessin;
|
|
|
|
float vals[6];
|
|
|
|
|
|
|
|
foo = fimg_create_from_dump(fname, &dessin);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "in %s, error %d loading '%s'\n",
|
|
|
|
__func__, foo, fname);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2020-03-02 14:51:34 +01:00
|
|
|
foo = fimg_get_minmax_rgb(&dessin, vals);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: err %d on fimg_get_minmax_rgb\n",
|
|
|
|
__func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
2020-03-02 01:19:57 +01:00
|
|
|
|
|
|
|
for (foo=0; foo<6; foo++) {
|
|
|
|
fprintf(stderr, "%7d %17.6g\n", foo, vals[foo]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
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;
|
|
|
|
|
2021-03-09 11:55:48 +01:00
|
|
|
fprintf(stderr, "-------- %s ( '%s' ) --------\n", __func__, fname);
|
|
|
|
|
2019-11-12 00:20:28 +01:00
|
|
|
foo = fimg_create_from_dump(fname, &dessin);
|
2020-01-10 12:01:12 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "in %s, error %d loading '%s'\n",
|
|
|
|
__func__, foo, fname);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2019-11-12 19:31:00 +01:00
|
|
|
foo = fimg_clone(&dessin, ©, 0);
|
2021-03-09 11:55:48 +01:00
|
|
|
fimg_save_as_pnm(&dessin, "dessin.pnm", 0);
|
2019-11-12 19:31:00 +01:00
|
|
|
|
2019-11-12 00:20:28 +01:00
|
|
|
maxi = (double)fimg_get_maxvalue(&dessin);
|
2020-01-10 12:01: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(©);
|
2020-01-10 12:01:12 +01:00
|
|
|
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
|
|
|
|
fimg_save_as_pnm(©, "power2.pnm", 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);
|
2020-01-10 12:01:12 +01:00
|
|
|
fimg_save_as_pnm(©, "squareroot.pnm", 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);
|
2020-01-10 12:01:12 +01:00
|
|
|
fimg_save_as_pnm(©, "cos_01.pnm", 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);
|
2020-01-10 12:01:12 +01:00
|
|
|
fimg_save_as_pnm(©, "cos_010.pnm", 0);
|
2020-01-09 09:28:23 +01:00
|
|
|
|
2020-01-10 12:01:12 +01:00
|
|
|
fimg_destroy(&dessin); fimg_destroy(©);
|
2019-11-12 00:20:28 +01:00
|
|
|
|
2020-01-10 12:01:12 +01:00
|
|
|
return 0;
|
2022-07-06 10:27:55 +02:00
|
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
void help_me_obiwan(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2019-11-12 00:20:28 +01:00
|
|
|
}
|
2019-09-09 16:02:44 +02:00
|
|
|
/* ---------------------------------------------------------------- */
|
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;
|
|
|
|
|
2022-07-06 10:27:55 +02:00
|
|
|
while ((opt = getopt(argc, argv, "ghn:v")) != -1) {
|
2019-09-10 01:31:48 +02:00
|
|
|
switch(opt) {
|
|
|
|
case 'g': gray++; break;
|
2022-07-06 10:27:55 +02:00
|
|
|
case 'h': help_me_obiwan(); 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;
|
2020-02-16 23:16:38 +01:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: oh, %c is a bad opt.\n",
|
|
|
|
argv[0], opt);
|
|
|
|
exit(5);
|
2019-09-10 01:31:48 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-29 23:50:03 +02:00
|
|
|
|
2020-06-11 15:57:12 +02:00
|
|
|
if (verbosity) {
|
|
|
|
fimg_print_version(1);
|
|
|
|
fimg_print_sizeof();
|
|
|
|
}
|
2019-08-07 11:55:29 +02:00
|
|
|
|
2022-04-09 23:18:14 +02:00
|
|
|
foo = essai_metadata("quux.fimg");
|
2022-02-09 23:21:58 +01:00
|
|
|
fprintf(stderr, "retour essai -> %d\n", foo);
|
2020-01-10 12:01:12 +01:00
|
|
|
|
2022-03-19 01:21:58 +01:00
|
|
|
// foo = essai_save_plane(0);
|
|
|
|
// fprintf(stderr, "retour essai -> %d\n", foo);
|
|
|
|
|
2020-02-16 23:16:38 +01:00
|
|
|
// foo = essai_clone_et_copy(0);
|
|
|
|
// fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo);
|
2020-01-10 12:01:12 +01:00
|
|
|
|
2021-03-09 11:55:48 +01:00
|
|
|
// foo = essai_timer(0);
|
|
|
|
// fprintf(stderr, "retour essai timer -> %d\n", foo);
|
2020-01-10 12:01:12 +01:00
|
|
|
|
2019-06-29 23:50:03 +02:00
|
|
|
return 0;
|
2019-07-08 06:28:04 +02:00
|
|
|
}
|