moving trinarize func

This commit is contained in:
tth 2021-03-26 05:40:45 +01:00
parent 2cf45fdbe5
commit 5d121dee87
4 changed files with 51 additions and 47 deletions

View File

@ -220,7 +220,7 @@ switch (idFx) {
retval = fimg_binarize(image, 0); retval = fimg_binarize(image, 0);
break; break;
case CR_trinarize: case CR_trinarize:
retval = trinarize(image, 0); retval = fimg_trinarize(image, 0);
break; break;
case CR_liss2x2: case CR_liss2x2:
retval = fimg_lissage_2x2(image); retval = fimg_lissage_2x2(image);

View File

@ -306,57 +306,13 @@ for (y=0; y<pimg->height; y++) {
} }
} }
return 0;
}
/* -------------------------------------------------------------- */
int trinarize(FloatImg *pimg, int notused)
{
float mm[6], mRa, mGa, mBa, mRb, mGb, mBb;
float *fptr;
int foo, size;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
#endif
foo = fimg_get_minmax_rgb(pimg, mm);
mRa = (mm[1] - mm[0]) * 0.33333;
mGa = (mm[3] - mm[2]) * 0.33333;
mBa = (mm[5] - mm[4]) * 0.33333;
mRb = (mm[1] - mm[0]) * 0.66666;
mGb = (mm[3] - mm[2]) * 0.66666;
mBb = (mm[5] - mm[4]) * 0.66666;
size = pimg->width * pimg->height;
for (foo=0; foo<size; foo++) {
fptr = pimg->R;
if (fptr[foo] < mRa || fptr[foo] > mRb)
fptr[foo] = mm[0];
else
fptr[foo] = mm[1];
fptr = pimg->G;
if (fptr[foo] < mGa || fptr[foo] > mGb)
fptr[foo] = mm[2];
else
fptr[foo] = mm[3];
fptr = pimg->B;
if (fptr[foo] < mBa || fptr[foo] > mBb)
fptr[foo] = mm[4];
else
fptr[foo] = mm[5];
}
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
/* /*
* int binarize(FloatImg *pimg, int notused) was now in * int binarize(FloatImg *pimg, int notused) was now in
* funcs/sfx2.c * funcs/sfx2.c
* same move for trinarize.
*/ */
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int brotche_rand48_a(FloatImg *fimg, float ratio, float mval) int brotche_rand48_a(FloatImg *fimg, float ratio, float mval)

View File

@ -4,7 +4,7 @@
* http://la.buvette.org/photos/cumul * http://la.buvette.org/photos/cumul
*/ */
#define FIMG_VERSION 126 #define FIMG_VERSION 127
/* /*
* in memory descriptor * in memory descriptor
@ -114,6 +114,7 @@ int fimg_highlight_color(FloatImg *src, FloatImg *dst,
/* module sfx2.c */ /* module sfx2.c */
int fimg_binarize(FloatImg *pimg, int notused); int fimg_binarize(FloatImg *pimg, int notused);
int fimg_trinarize(FloatImg *pimg, int notused);
/* funcs/rotate.c module */ /* funcs/rotate.c module */
/* #coronamaison */ /* #coronamaison */

View File

@ -45,3 +45,50 @@ for (foo=0; foo<size; foo++) {
return 0; return 0;
} }
/* -------------------------------------------------------------- */ /* -------------------------------------------------------------- */
int fimg_trinarize(FloatImg *pimg, int notused)
{
float mm[6], mRa, mGa, mBa, mRb, mGb, mBb;
float *fptr;
int foo, size;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
#endif
foo = fimg_get_minmax_rgb(pimg, mm);
mRa = (mm[1] - mm[0]) * 0.33333;
mGa = (mm[3] - mm[2]) * 0.33333;
mBa = (mm[5] - mm[4]) * 0.33333;
mRb = (mm[1] - mm[0]) * 0.66666;
mGb = (mm[3] - mm[2]) * 0.66666;
mBb = (mm[5] - mm[4]) * 0.66666;
size = pimg->width * pimg->height;
for (foo=0; foo<size; foo++) {
fptr = pimg->R;
if (fptr[foo] < mRa || fptr[foo] > mRb)
fptr[foo] = mm[0];
else
fptr[foo] = mm[1];
fptr = pimg->G;
if (fptr[foo] < mGa || fptr[foo] > mGb)
fptr[foo] = mm[2];
else
fptr[foo] = mm[3];
fptr = pimg->B;
if (fptr[foo] < mBa || fptr[foo] > mBb)
fptr[foo] = mm[4];
else
fptr[foo] = mm[5];
}
return 0;
}
/* -------------------------------------------------------------- */