forked from tTh/FloatImg
127 lines
2.6 KiB
C
127 lines
2.6 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 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;
|
|
}
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
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_contraste(char *fname)
|
|
{
|
|
int foo;
|
|
FloatImg dessin, copy;
|
|
double maxi;
|
|
|
|
foo = fimg_create_from_dump(fname, &dessin);
|
|
foo = fimg_clone(&dessin, ©, 0);
|
|
|
|
|
|
maxi = (double)fimg_get_maxvalue(&dessin);
|
|
fprintf(stderr, "image source valeur maxi = %f\n", maxi);
|
|
|
|
fimg_power_2(&dessin, ©, maxi);
|
|
maxi = (double)fimg_get_maxvalue(©);
|
|
fprintf(stderr, "apres power_2 valeur maxi = %f\n", maxi);
|
|
fimg_dump_to_file(©, "power2.fimg", 0);
|
|
|
|
fimg_square_root(&dessin, ©, maxi);
|
|
maxi = (double)fimg_get_maxvalue(©);
|
|
fprintf(stderr, "apres square_root valeur maxi = %f\n", maxi);
|
|
fimg_dump_to_file(©, "squareroot.fimg", 0);
|
|
|
|
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);
|
|
|
|
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_contraste("original.fimg");
|
|
fprintf(stderr, "retour essai contraste -> %d\n", foo);
|
|
|
|
return 0;
|
|
}
|