add "fimg_make_rndfluffy_lines" function

This commit is contained in:
tTh 2023-02-12 11:15:04 +01:00
parent 70694cf592
commit 7d66b09635
5 changed files with 84 additions and 3 deletions

View File

@ -20,7 +20,7 @@
* https://git.tetalab.org/tTh/FloatImg
*/
#define FIMG_VERSION (212)
#define FIMG_VERSION (218)
#define RELEASE_NAME ("noname")
/* XXX add a test for stdint.h / uint32_t XXX */
@ -174,6 +174,7 @@ int fimg_binarize(FloatImg *pimg, int notused);
int fimg_trinarize(FloatImg *pimg, int notused);
/* module sfx3.c */
int fimg_make_rndfluffy_lines(FloatImg *src, FloatImg *dst, int rndt);
int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused);
/* module sfx4.c */

View File

@ -9,6 +9,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <sys/time.h>
@ -16,6 +17,45 @@
extern int verbosity;
/* -------------------------------------------------------------- */
/* new Sun 29 Jan 2023 10:01:39 PM CET
*/
int fimg_make_rndfluffy_lines(FloatImg *src, FloatImg *dst, int rndt)
{
int x, y, ol;
float accu;
// #if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%p' '%p' %d )\n", __func__,
src, dst, rndt);
// #endif
if (fimg_images_not_compatible(src, dst)) {
/* be hard for the lamers */
fprintf(stderr, "compatibility OUPS in %s\n", __func__);
abort();
}
for (y=0; y<src->height; y++) {
ol = y * src->width;
if (rndt < (rand() % 100)) {
accu = 0.0;
for (x=0; x<src->width; x++) accu += src->R[ol + x];
accu /= (float)src->width;
for (x=0; x<src->width; x++) dst->R[ol + x] = accu;
}
else {
for (x=0; x<src->width; x++) {
dst->R[ol+x] = src->R[ol+x];
dst->G[ol+x] = src->G[ol+x];
dst->B[ol+x] = src->B[ol+x];
}
}
}
return 0;
}
/* -------------------------------------------------------------- */
int fimg_crump_hard(FloatImg *src, FloatImg *dst, float kval, int notused)
{

View File

@ -26,7 +26,7 @@ enum nCmd { Equalize=1, Rotate, Sfx0, F3x3, MIRE, Wfits, Wpng, Wtiff,
Geometrie, FileType, Mirror, KillRGB,
Pixelize,SplitLevel, DecompRgbz, DecompRgbg,
Rectangle, Dicom, Fakolor0, Fakolor3,
Fmorpho0 };
Fmorpho0, Fluffy };
typedef struct {
char *name;
int Cmd;
@ -64,6 +64,7 @@ Command commands[] = {
{ "fakolor0", Fakolor0 },
{ "fakolor3", Fakolor3 },
{ "fmorpho0", Fmorpho0 },
{ "fluffy", Fluffy },
{ NULL, 0 }
} ;
@ -262,6 +263,9 @@ switch(opt) {
case Fmorpho0:
foo = essai_fmorpho_0(filename, "/tmp/fmorpho", 0);
break;
case Fluffy:
foo = essai_rndfluffy(filename, outfile, 0);
break;
default:
fprintf(stderr, "'%s' is a bad command\n", command);
exit(1);

View File

@ -27,7 +27,6 @@ extern int verbosity;
/*
* nouveau 30 octobre 2022 --> fmorpho.c
*/
int essai_fmorpho_0(char *infile, char *basefname, int k)
{
FloatImg src, dst;
@ -318,6 +317,42 @@ if (foo) {
return 0;
}
/* --------------------------------------------------------------------- */
/* new Sun Feb 12 10:34:06 CET 2023
*/
int essai_rndfluffy(char *infile, char *outfile, int k)
{
int foo;
FloatImg src, dst;
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n", __func__,
infile, outfile, k);
foo = fimg_create_from_dump(infile, &src);
if (0 != foo) {
fprintf(stderr, "%s: err %d loading image '%s'\n", __func__,
foo, infile);
return foo;
}
fprintf(stderr, " %s loaded.\n", infile);
fimg_clone(&src, &dst, 0);
fprintf(stderr, " %p cloned.\n", &src);
foo = fimg_make_rndfluffy_lines(&src, &dst, 80);
if (foo) {
fprintf(stderr, "err %d while making fluffy\n", foo);
return foo;
}
foo = fimg_export_picture(&dst, outfile, 0);
if (foo) {
fprintf(stderr, "%s: err %d exporting %s\n", __func__, foo, outfile);
return foo;
}
fimg_destroy(&src); fimg_destroy(&dst);
return 0;
}
/* --------------------------------------------------------------------- */
int essai_split_level(char *inf, char *outf, int flags)
{

View File

@ -8,6 +8,7 @@ int essai_miroir(char *inf, char *outf, int flags);
int essai_killrgb(char *inf, char *outf);
int essai_decomprgb_color(char *inf, char *outf);
int essai_decomprgb_gray(char *inf, char *outf);
int essai_rndfluffy(char *infile, char *outfile, int k); /* sfx3.c */
int essai_split_level(char *inf, char *outf, int flags);
int essai_displacement(char *infile, char *outfile);