FloatImg/lib/t.c

129 lines
2.5 KiB
C
Raw Normal View History

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;
2019-08-08 17:16:20 +02:00
/* ---------------------------------------------------------------- */
int petit_dessin(FloatImg *img)
{
int x, y;
float r, g, b;
for (y=0; y<img->height; y++) {
r = (float)y / (float)img->height;
for (x=0; x<img->width; x++) {
g = (float)x / (float)img->width;
b = 0.0;;
fimg_plot_rgb(img, x, y, r, g, b);
}
}
return -1;
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-08-26 01:47:05 +02:00
return 0;
2019-08-08 17:16:20 +02:00
}
/* ---------------------------------------------------------------- */
2019-09-09 16:02:44 +02:00
/****
foo = fimg_create(&dessin, W, H, 3);
petit_dessin(&dessin);
foo = fimg_create(&noise, W, H, 3);
fimg_drand48(&noise, 0.1);
****/
/* ---------------------------------------------------------------- */
#define W 320
#define H 240
2019-06-29 23:50:03 +02:00
int main(int argc, char *argv[])
{
2019-09-09 16:02:44 +02:00
int foo, idx;
float coef;
2019-08-08 17:16:20 +02:00
FloatImg dessin, noise, result;
2019-09-09 16:02:44 +02:00
char outname[100];
2019-06-29 23:50:03 +02:00
2019-08-08 17:16:20 +02:00
verbosity = 1;
2019-08-07 11:55:29 +02:00
2019-08-08 17:16:20 +02:00
fimg_print_version(1);
2019-06-29 23:50:03 +02:00
2019-09-09 17:27:48 +02:00
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &dessin);
if (foo) {
fprintf(stderr, "s1 load err %d\n", foo);
exit(1);
}
fimg_describe(&dessin, "s1 dessin");
fimg_to_gray(&dessin);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &noise);
if (foo) {
fprintf(stderr, "s2 load err %d\n", foo);
exit(1);
}
fimg_describe(&noise, "s2 noise");
2019-07-08 06:28:04 +02:00
2019-08-10 18:37:52 +02:00
foo = fimg_create(&result, W, H, 3);
2019-09-09 16:02:44 +02:00
2019-09-09 17:27:48 +02:00
#define NBRE 20
2019-09-09 16:02:44 +02:00
for (idx=0; idx<NBRE; idx++) {
coef = (float)idx / (float)NBRE;
coef = (0.5-0.5*cos( 3.141592654*coef));
foo = fimg_interpolate(&dessin, &noise, &result, coef);
printf("%6d %9.6f\n", idx, coef);
2019-09-09 17:27:48 +02:00
// fimg_to_gray(&result);
2019-09-09 16:02:44 +02:00
sprintf(outname, "/home/tth/TMP/floatimg/%05d.pnm", idx);
foo = fimg_save_as_pnm(&result, outname, 0);
}
// essai_2gray(&result, "gray.pnm");
2019-08-24 13:06:51 +02:00
2019-08-26 01:47:05 +02:00
fimg_destroy(&dessin), fimg_destroy(&noise), fimg_destroy(&result);
2019-08-07 17:30:16 +02:00
2019-06-29 23:50:03 +02:00
return 0;
2019-07-08 06:28:04 +02:00
}