From 56073c0c80273432e22236ea780285cd17ed4500 Mon Sep 17 00:00:00 2001 From: tTh Date: Mon, 19 Sep 2022 11:58:30 +0200 Subject: [PATCH] new func: fimg_do_stripes(&fimg, 0); --- floatimg.h | 3 ++- funcs/rampes.c | 55 ++++++++++++++++++++++++++++++++++++++++++++------ tools/mkfimg.c | 8 +++++--- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/floatimg.h b/floatimg.h index bee8dfc..e91d886 100644 --- a/floatimg.h +++ b/floatimg.h @@ -20,7 +20,7 @@ * https://git.tetalab.org/tTh/FloatImg */ -#define FIMG_VERSION (201) +#define FIMG_VERSION (202) #define RELEASE_NAME ("noname") /* XXX add a test for stdint.h / uint32_t XXX */ @@ -254,6 +254,7 @@ int fimg_displacement_0(FloatImg *psrc, FloatImg *pdst, int flags); /* module funcs/rampes.c */ int fimg_hdeg_a(FloatImg *img, double dcoef); int fimg_vdeg_a(FloatImg *img, double dcoef); +int fimg_do_stripes(FloatImg *img, int mode); /* FIMG native file module */ int fimg_fileinfos(char *fname, int *datas); diff --git a/funcs/rampes.c b/funcs/rampes.c index c6a76b2..a612b82 100644 --- a/funcs/rampes.c +++ b/funcs/rampes.c @@ -5,6 +5,7 @@ #include #include +#include #include #include "../floatimg.h" @@ -23,8 +24,7 @@ if (FIMG_TYPE_RGB != img->type) { fprintf(stderr, "%s bad type\n", __func__); return -6; } -for (x=0; xwidth; x++) - { +for (x=0; xwidth; x++) { value = (float)x / (float)img->width; value *= dcoef; for (y=0; yheight; y++) { @@ -51,11 +51,10 @@ if (FIMG_TYPE_RGB != img->type) { fprintf(stderr, "%s bad type\n", __func__); return -6; } -for (y=0; yheight; y++) - { - value = (float)y / (float)img->height; +for (x=0; xwidth; x++) { + value = (float)x / (float)img->width; value *= dcoef; - for (x=0; xwidth; x++) { + for (y=0; yheight; y++) { fimg_plot_rgb(img, x, y, value, value, value); } } @@ -63,3 +62,47 @@ for (y=0; yheight; y++) return 0; } /* --------------------------------------------------------------------- */ +/* nouveau 19 septembre 2022 */ + +int fimg_do_stripes(FloatImg *img, int mode) +{ +int x, y, quad; +float *ligne; +float fr, fg, fb; + +fprintf(stderr, ">>> %s ( %p %d )\n", __func__, img, mode); + +/* + * allocate and fill a lookup table + */ +if (NULL==(ligne=malloc(img->width*sizeof(float)))) { + fprintf(stderr, "%s: malloc fail\n", __func__); + exit(1); + } +for (x=0; xwidth; x++) + ligne[x] = (float)x / (float)img->width; + +/* + * build the pixels + */ +for (y=0; yheight; y++) + { + quad = (y*4) / img->height ; + for (x=0; xwidth; x++) { + fr = fg = fb = ligne[x]; + switch(quad) { + case 0: fg = fb = 0; break; + case 1: fr = fb = 0; break; + case 2: fr = fg = 0; break; + case 3: break; + default: abort(); break; + } + fimg_plot_rgb(img, x, y, fr, fg, fb); + } + } + +free(ligne); + +return 0; +} +/* --------------------------------------------------------------------- */ diff --git a/tools/mkfimg.c b/tools/mkfimg.c index c5c28b2..4737f8f 100644 --- a/tools/mkfimg.c +++ b/tools/mkfimg.c @@ -154,8 +154,8 @@ fname = argv[optind]; if (verbosity>1) fprintf(stderr, "*** mkfimg *** %s %s *** pid %ld\n", __DATE__, __TIME__, (long)getpid()); -if (verbosity) fprintf(stderr, "making '%s' %dx%d, type %d\n", - fname, width, height, type); +if (verbosity) fprintf(stderr, "::: %s is making '%s' %dx%d, type %d\n", + argv[0], fname, width, height, type); srand48(getpid() ^ time(NULL)); @@ -176,6 +176,7 @@ switch(type) { case T_TPAT0: fimg_test_pattern(&fimg, 0, fvalue); break; case T_MIRCOL1: fimg_mircol_1(&fimg, fvalue); break; case T_BLOUP: fimg_draw_something(&fimg); break; + case T_STRIPES: fimg_do_stripes(&fimg, 0); break; case -1: exit(1); } @@ -191,8 +192,9 @@ if (wrmdata) { else { foo = fimg_dump_to_file(&fimg, fname, 0); } + if (foo) { - fprintf(stderr, "dump fimg to %s error -> %d\n", fname, foo); + fprintf(stderr, "*** dump fimg to %s error -> %d\n", fname, foo); exit(1); }