FloatImg/funcs/t.c

321 lines
6.9 KiB
C
Raw Normal View History

2019-09-13 04:48:12 +11:00
/*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pam.h>
#include "../floatimg.h"
2020-01-23 08:14:06 +11:00
int verbosity;
2020-02-17 02:21:27 +11:00
float global_fvalue;
/* --------------------------------------------------------------------- */
2020-03-01 07:59:12 +11:00
int essai_filtrage_3x3(char *infile)
{
FloatImg src, dst;
int foo, idx;
char buffer[100];
FimgFilter3x3 filter_a = {
{ 1.0, 1.0, 1.0,
1.0, -3.0, 1.0,
1.0, 1.0, 1.0 },
8.0, 0.0
};
FimgFilter3x3 filter_b = {
{ -2.0, -1.0, 0.0,
-1.0, 3.0, 1.0,
0.0, 1.0, 2.0 },
8.0, 0.0
};
if (NULL != infile) {
fprintf(stderr, "%s: loading %s\n", __func__, infile);
foo = fimg_create_from_dump(infile, &src);
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(&src, 640, 480, FIMG_TYPE_RGB);
fimg_test_pattern(&src, 0, 255.0);
fimg_save_as_png(&src, "test.png", 0);
}
foo = fimg_clone(&src, &dst, 0);
2020-03-02 11:19:57 +11:00
fimg_filter_3x3(&src, &dst, &filter_a);
foo = fimg_clamp_negativ(&dst);
if (foo) {
fprintf(stderr, "clamped %d negative pixels\n", foo);
}
foo = fimg_save_as_png(&dst, "f3x3a.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
2020-03-01 07:59:12 +11:00
fimg_filter_3x3(&src, &dst, &filter_b);
foo = fimg_clamp_negativ(&dst);
if (foo) {
2020-03-02 11:19:57 +11:00
fprintf(stderr, "clamped %d negative pixels\n", foo);
2020-03-01 07:59:12 +11:00
}
2020-03-02 11:19:57 +11:00
foo = fimg_save_as_png(&dst, "f3x3b.png", 0);
// foo = fimg_save_as_pnm(&dst, "f3x3a.pnm", 0);
2020-03-01 07:59:12 +11:00
fimg_destroy(&src); fimg_destroy(&dst);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_filtrage_2x2(char *infile)
{
FloatImg fimg;
int foo, idx;
char buffer[100];
if (NULL != infile) {
2020-03-01 07:59:12 +11:00
fprintf(stderr, "%s: loading %s\n", __func__, 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);
2020-02-27 23:16:00 +11:00
/*
* running multiple filters so you can
* watch the up-left shift :)
*/
2020-03-01 07:59:12 +11:00
for (idx=0; idx<5; idx++) {
foo = fimg_lissage_2x2(&fimg);
2020-02-27 23:16:00 +11:00
sprintf(buffer, "filter%03d.png", idx);
foo = fimg_save_as_png(&fimg, buffer, 0);
2020-03-01 07:59:12 +11:00
if (verbosity) {
fprintf(stderr, "%s %d\n", buffer, foo);
}
}
fimg_destroy(&fimg);
return 0;
}
2020-02-14 06:44:22 +11:00
/* --------------------------------------------------------------------- */
int essai_geometrie(char *infile)
{
FloatImg fimg, result;
int foo;
if (NULL != infile) {
fprintf(stderr, "loading %s\n", infile);
2020-02-27 23:16:00 +11:00
foo = fimg_create_from_dump(infile, &fimg);
if (foo) {
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
return foo;
}
2020-02-14 06:44:22 +11:00
}
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;
}
2020-02-17 02:21:27 +11:00
if (verbosity) fimg_describe(&result, "result after halfsize");
2020-02-14 06:44:22 +11:00
foo = fimg_save_as_pnm(&result, "something.pnm", 0);
2020-02-08 04:01:28 +11:00
2020-02-14 06:44:22 +11:00
return 0;
}
2020-02-08 04:01:28 +11:00
/* --------------------------------------------------------------------- */
int essai_sfx0(char *infile)
{
FloatImg fimg;
int foo;
2020-02-08 06:09:03 +11:00
if (NULL != infile) {
fprintf(stderr, "loading %s\n", infile);
2020-02-27 23:16:00 +11:00
foo = fimg_create_from_dump(infile, &fimg);
if (foo) {
fprintf(stderr, "%s: err load '%s'\n", __func__, infile);
return foo;
}
2020-02-08 06:09:03 +11:00
}
else {
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
fimg_draw_something(&fimg);
}
2020-02-08 04:01:28 +11:00
foo = fimg_save_as_pnm(&fimg, "something.pnm", 0);
2020-02-17 02:21:27 +11:00
if (foo) {
fprintf(stderr, "%s: err save %d\n", __func__, foo);
return -6;
}
2020-02-08 04:01:28 +11:00
foo = fimg_killcolors_a(&fimg, 0.0);
2020-02-08 06:09:03 +11:00
foo = fimg_save_as_pnm(&fimg, "colorskilled-a.pnm", 0);
2020-02-17 02:21:27 +11:00
if (foo) {
fprintf(stderr, "%s: err save %d\n", __func__, foo);
return -6;
}
2020-02-08 06:09:03 +11:00
foo = fimg_killcolors_b(&fimg, 0.0);
foo = fimg_save_as_pnm(&fimg, "colorskilled-b.pnm", 0);
2020-02-17 02:21:27 +11:00
if (foo) {
fprintf(stderr, "%s: err save %d\n", __func__, foo);
return -6;
}
2020-02-08 04:01:28 +11:00
return 0;
}
2019-09-13 04:48:12 +11:00
/* --------------------------------------------------------------------- */
2019-10-31 01:49:53 +11:00
int essai_parse_double(void)
2019-09-13 04:48:12 +11:00
{
int foo;
2019-09-16 21:28:47 +11:00
double dval;
char *str;
str = "12.34"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
2019-09-13 04:48:12 +11:00
2019-09-16 21:28:47 +11:00
str = "12e4"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
2019-09-13 04:48:12 +11:00
2019-09-16 21:28:47 +11:00
str = "5s"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
2019-09-13 23:34:56 +11:00
2019-09-16 21:28:47 +11:00
str = "PORN"; dval = 0.0;
foo = parse_double(str, &dval);
printf("%-10s -> %3d %g\n", str, foo, dval);
2019-09-13 04:48:12 +11:00
return 0;
}
/* --------------------------------------------------------------------- */
2019-10-31 01:49:53 +11:00
int essai_detect_type(void)
{
int foo;
char *fname;
foo = format_from_extension(fname="foo.fimg");
printf("%-10s %d\n\n", fname, foo);
2020-02-08 04:01:28 +11:00
foo = format_from_extension(fname="foo.pnm");
printf("%-10s %d\n\n", fname, foo);
foo = format_from_extension(fname="foo.png");
2019-10-31 01:49:53 +11:00
printf("%-10s %d\n\n", fname, foo);
foo = format_from_extension(fname="foo.xyzzy");
printf("%-10s %d\n\n", fname, foo);
2020-01-04 01:39:11 +11:00
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);
2019-12-14 04:18:07 +11:00
return 0;
}
/* --------------------------------------------------------------------- */
int essai_ecrire_png(char *fname)
{
FloatImg fimg;
int foo;
fimg_create(&fimg, 512, 512, FIMG_TYPE_RGB);
2019-12-31 22:02:37 +11:00
fimg_draw_something(&fimg);
/* XXX
2019-12-14 04:18:07 +11:00
for (foo=0; foo<512; foo++) {
fimg_plot_rgb(&fimg, foo, foo, 17000.0, 8000.0, 11111.1);
}
2019-12-31 22:02:37 +11:00
*/
2019-12-14 04:18:07 +11:00
2019-12-31 22:02:37 +11:00
foo = fimg_save_as_pnm(&fimg, "quux.pnm", 0);
fprintf(stderr, "save as pnm -> %d\n", foo);
2019-12-14 04:18:07 +11:00
foo = fimg_save_as_png(&fimg, fname, 0);
2019-12-31 22:02:37 +11:00
fprintf(stderr, "save as png -> %d\n", foo);
2019-12-14 04:18:07 +11:00
2019-10-31 01:49:53 +11:00
return 0;
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
2020-02-17 02:21:27 +11:00
int foo, opt;
char *filename;
2019-10-31 01:49:53 +11:00
2019-12-14 04:18:07 +11:00
puts("++++++++++++++++++++++++++++++++");
2020-02-17 02:21:27 +11:00
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];
2020-03-01 07:59:12 +11:00
/*
foo = essai_filtrage_2x2(filename);
if (foo) {
fprintf(stderr, "Filtre 2x2 ====> %d\n", foo);
}
*/
foo = essai_filtrage_3x3(filename);
2020-02-17 02:21:27 +11:00
if (foo) {
2020-03-01 07:59:12 +11:00
fprintf(stderr, "Filtre 3x3 ====> %d\n", foo);
2020-02-17 02:21:27 +11:00
}
2019-10-31 01:49:53 +11:00
2020-03-01 07:59:12 +11:00
fprintf(stderr, "++++++++++++++ end of pid %d\n", getpid());
2019-10-31 01:49:53 +11:00
return 0;
}
/* --------------------------------------------------------------------- */