FloatImg4PythonBinding/funcs/t.c

237 lines
5.1 KiB
C

/*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pam.h>
#include "../floatimg.h"
int verbosity;
float global_fvalue;
/* --------------------------------------------------------------------- */
int essai_filtrage(char *infile)
{
FloatImg fimg;
int foo, idx;
char buffer[100];
if (NULL != infile) {
fprintf(stderr, "loading %s\n", infile);
foo = fimg_create_from_dump(infile, &fimg);
if (foo) {
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
return foo;
}
}
else {
fprintf(stderr, "%s is creating the picz\n", __func__);
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
fimg_draw_something(&fimg);
}
foo = fimg_save_as_pnm(&fimg, "source.pnm", 0);
for (idx=0; idx<20; idx++) {
foo = fimg_lissage_2x2(&fimg);
foo = fimg_killborders(&fimg);
sprintf(buffer, "filter%03d.pnm", idx);
foo = fimg_save_as_pnm(&fimg, buffer, 0);
}
fimg_destroy(&fimg);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_geometrie(char *infile)
{
FloatImg fimg, result;
int foo;
if (NULL != infile) {
fprintf(stderr, "loading %s\n", infile);
fimg_create_from_dump(infile, &fimg);
}
else {
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
fimg_draw_something(&fimg);
}
foo = fimg_save_as_pnm(&fimg, "source.pnm", 0);
memset(&result, 0, sizeof(FloatImg));
foo = fimg_halfsize_0(&fimg, &result, 0);
fprintf(stderr, "retour halfsize -> %d\n", foo);
if (foo) {
return -2;
}
if (verbosity) fimg_describe(&result, "result after halfsize");
foo = fimg_save_as_pnm(&result, "something.pnm", 0);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_sfx0(char *infile)
{
FloatImg fimg;
int foo;
if (NULL != infile) {
fprintf(stderr, "loading %s\n", infile);
fimg_create_from_dump(infile, &fimg);
}
else {
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
fimg_draw_something(&fimg);
}
foo = fimg_save_as_pnm(&fimg, "something.pnm", 0);
if (foo) {
fprintf(stderr, "%s: err save %d\n", __func__, foo);
return -6;
}
foo = fimg_killcolors_a(&fimg, 0.0);
foo = fimg_save_as_pnm(&fimg, "colorskilled-a.pnm", 0);
if (foo) {
fprintf(stderr, "%s: err save %d\n", __func__, foo);
return -6;
}
foo = fimg_killcolors_b(&fimg, 0.0);
foo = fimg_save_as_pnm(&fimg, "colorskilled-b.pnm", 0);
if (foo) {
fprintf(stderr, "%s: err save %d\n", __func__, foo);
return -6;
}
return 0;
}
/* --------------------------------------------------------------------- */
int essai_parse_double(void)
{
int foo;
double dval;
char *str;
str = "12.34"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
str = "12e4"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
str = "5s"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
str = "PORN"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_detect_type(void)
{
int foo;
char *fname;
foo = format_from_extension(fname="foo.fimg");
printf("%-10s %d\n\n", fname, foo);
foo = format_from_extension(fname="foo.pnm");
printf("%-10s %d\n\n", fname, foo);
foo = format_from_extension(fname="foo.png");
printf("%-10s %d\n\n", fname, foo);
foo = format_from_extension(fname="foo.xyzzy");
printf("%-10s %d\n\n", fname, foo);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_rampes(void)
{
FloatImg fimg;
int foo;
fimg_create(&fimg, 640, 480, FIMG_TYPE_RGB);
foo = fimg_hdeg_a(&fimg, (double)3.141592654);
fprintf(stderr, "make h deg -> %d\n", foo);
foo = fimg_save_as_pnm(&fimg, "hdeg.pnm", 0);
fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo);
foo = fimg_vdeg_a(&fimg, (double)3.141592654);
fprintf(stderr, "make h deg -> %d\n", foo);
foo = fimg_save_as_pnm(&fimg, "vdeg.pnm", 0);
fprintf(stderr, "%s: save as pnm -> %d\n", __func__, foo);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_ecrire_png(char *fname)
{
FloatImg fimg;
int foo;
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
fimg_draw_something(&fimg);
/* XXX
for (foo=0; foo<512; foo++) {
fimg_plot_rgb(&fimg, foo, foo, 17000.0, 8000.0, 11111.1);
}
*/
foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0);
fprintf(stderr, "save as pnm -> %d\n", foo);
foo = fimg_save_as_png(&fimg, fname, 0);
fprintf(stderr, "save as png -> %d\n", foo);
return 0;
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
char *filename;
puts("++++++++++++++++++++++++++++++++");
global_fvalue = 1.0;
while ((opt = getopt(argc, argv, "hk:v")) != -1) {
switch(opt) {
// case 'h': help(0); break;
case 'k': global_fvalue = atof(optarg); break;
case 'v': verbosity++; break;
}
}
fprintf(stderr, "argc %d optind %d\n", argc, optind);
filename = NULL;
if (1 == argc-optind) filename = argv[optind];
foo = essai_filtrage(filename);
if (foo) {
fprintf(stderr, "====> %d\n", foo);
}
return 0;
}
/* --------------------------------------------------------------------- */