2020-11-02 01:25:00 +01:00
|
|
|
/*
|
|
|
|
* SPECIAL EFFECTS
|
|
|
|
*
|
|
|
|
* Du code bien cracra / tTh / Tetalab
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
2020-12-02 19:55:06 +01:00
|
|
|
#include "../floatimg.h"
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
#include "fonctions.h"
|
2020-12-02 19:55:06 +01:00
|
|
|
#include "sfx.h"
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-05 12:48:35 +01:00
|
|
|
/* here are global vars exported by the main module
|
2020-11-02 01:25:00 +01:00
|
|
|
*/
|
2020-11-02 14:51:48 +01:00
|
|
|
extern int verbosity;
|
2020-11-02 01:25:00 +01:00
|
|
|
|
2020-11-20 22:25:30 +01:00
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
/* nouveau du 20 novembre 2020, pour encoder une vidz du vernissage
|
|
|
|
* du festival Sauvageonnes de Mixart-Myrys */
|
|
|
|
int des_bords_sombres_a(FloatImg *pimg, int offset)
|
|
|
|
{
|
|
|
|
float coef;
|
2020-11-25 10:32:02 +01:00
|
|
|
int xpos, xp2, lidx, y;
|
2020-11-20 22:25:30 +01:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, offset);
|
|
|
|
#endif
|
|
|
|
|
2020-11-25 10:32:02 +01:00
|
|
|
if (offset<0 || offset>=pimg->width) {
|
2020-11-20 22:25:30 +01:00
|
|
|
fprintf(stderr, "%s offset %d is bad\n", __func__, offset);
|
|
|
|
return -66;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (y=0; y<pimg->height; y++) {
|
2020-11-25 10:32:02 +01:00
|
|
|
lidx = y * pimg->width; /* start of the
|
|
|
|
'y' line */
|
2020-11-20 22:25:30 +01:00
|
|
|
for (xpos=0; xpos<offset; xpos++) {
|
|
|
|
coef = (float)xpos / (float)offset;
|
|
|
|
pimg->R[xpos+lidx] *= coef;
|
|
|
|
pimg->G[xpos+lidx] *= coef;
|
|
|
|
pimg->B[xpos+lidx] *= coef;
|
2020-11-25 10:32:02 +01:00
|
|
|
xp2 = pimg->width-xpos;
|
|
|
|
pimg->R[xp2+lidx] *= coef;
|
|
|
|
pimg->G[xp2+lidx] *= coef;
|
|
|
|
pimg->B[xp2+lidx] *= coef;
|
2020-11-20 22:25:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-11-10 00:50:25 +01:00
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int trinarize(FloatImg *pimg, int notused)
|
|
|
|
{
|
2020-11-25 10:32:02 +01:00
|
|
|
float mm[6], mRa, mGa, mBa, mRb, mGb, mBb;
|
2020-12-01 13:10:27 +01:00
|
|
|
float val, *fptr;
|
2020-11-25 10:32:02 +01:00
|
|
|
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++) {
|
|
|
|
|
2020-12-01 13:10:27 +01:00
|
|
|
fptr = pimg->R;
|
|
|
|
if (fptr[foo] < mRa || fptr[foo] > mRb)
|
2020-12-02 19:55:06 +01:00
|
|
|
fptr[foo] = mm[0];
|
2020-12-01 13:10:27 +01:00
|
|
|
else
|
2020-12-01 15:26:15 +01:00
|
|
|
fptr[foo] = mm[1];
|
2020-11-25 10:32:02 +01:00
|
|
|
|
2020-12-01 13:10:27 +01:00
|
|
|
fptr = pimg->G;
|
|
|
|
if (fptr[foo] < mGa || fptr[foo] > mGb)
|
2020-12-02 19:55:06 +01:00
|
|
|
fptr[foo] = mm[2];
|
2020-12-01 13:10:27 +01:00
|
|
|
else
|
2020-12-01 15:26:15 +01:00
|
|
|
fptr[foo] = mm[3];
|
2020-11-10 00:50:25 +01:00
|
|
|
|
2020-12-01 13:10:27 +01:00
|
|
|
fptr = pimg->B;
|
|
|
|
if (fptr[foo] < mBa || fptr[foo] > mBb)
|
2020-12-02 19:55:06 +01:00
|
|
|
fptr[foo] = mm[4];
|
2020-12-01 13:10:27 +01:00
|
|
|
else
|
2020-12-01 15:26:15 +01:00
|
|
|
fptr[foo] = mm[5];
|
2020-12-01 13:10:27 +01:00
|
|
|
|
|
|
|
}
|
2020-11-10 00:50:25 +01:00
|
|
|
|
2020-12-01 13:26:00 +01:00
|
|
|
return 0;
|
2020-11-10 00:50:25 +01:00
|
|
|
}
|
2020-11-02 01:25:00 +01:00
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-05 12:48:35 +01:00
|
|
|
int binarize(FloatImg *pimg, int notused)
|
|
|
|
{
|
|
|
|
float mm[6], mR, mG, mB;
|
2020-11-05 21:07:38 +01:00
|
|
|
int foo, size;
|
2020-11-05 12:48:35 +01:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pimg, notused);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = fimg_get_minmax_rgb(pimg, mm);
|
|
|
|
mR = (mm[1] - mm[0]) / 2.0;
|
|
|
|
mG = (mm[3] - mm[2]) / 2.0;
|
|
|
|
mB = (mm[5] - mm[4]) / 2.0;
|
|
|
|
|
|
|
|
if (verbosity > 1)
|
2020-11-05 21:07:38 +01:00
|
|
|
fprintf(stderr, "%s: %f %f %f\n", __func__, mR, mG, mB);
|
|
|
|
|
|
|
|
size = pimg->width * pimg->height;
|
|
|
|
|
|
|
|
for (foo=0; foo<size; foo++) {
|
|
|
|
if (pimg->R[foo] < mR) pimg->R[foo] = mm[0];
|
|
|
|
else pimg->R[foo] = mm[1];
|
|
|
|
if (pimg->G[foo] < mG) pimg->G[foo] = mm[2];
|
|
|
|
else pimg->G[foo] = mm[3];
|
|
|
|
if (pimg->B[foo] < mB) pimg->B[foo] = mm[4];
|
|
|
|
else pimg->B[foo] = mm[5];
|
2020-11-05 12:48:35 +01:00
|
|
|
}
|
2020-11-02 01:25:00 +01:00
|
|
|
|
2020-11-05 12:48:35 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-11-02 14:51:48 +01:00
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int brotche_rand48_a(FloatImg *fimg, float ratio, float mval)
|
2020-11-02 01:25:00 +01:00
|
|
|
{
|
|
|
|
int nbpix, todo, foo;
|
|
|
|
int x, y;
|
|
|
|
float fval;
|
|
|
|
|
|
|
|
nbpix = fimg->width * fimg->height;
|
|
|
|
todo = (int)((float)nbpix * ratio);
|
2020-11-02 14:51:48 +01:00
|
|
|
if (verbosity > 1) {
|
|
|
|
fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__,
|
|
|
|
ratio, nbpix, todo);
|
|
|
|
}
|
2020-11-02 01:25:00 +01:00
|
|
|
|
|
|
|
for (foo=0; foo<todo; foo++)
|
|
|
|
{
|
|
|
|
fval = (float)drand48() * mval;
|
|
|
|
x = rand() % fimg->width;
|
|
|
|
y = rand() % fimg->height;
|
|
|
|
fimg_plot_rgb(fimg, x, y, fval, fval, fval);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int brotche_rand48_b(FloatImg *fimg, float ratio, float mval)
|
|
|
|
{
|
|
|
|
int nbpix, todo, foo;
|
|
|
|
int x, y;
|
|
|
|
float fval;
|
|
|
|
|
|
|
|
nbpix = fimg->width * fimg->height;
|
|
|
|
todo = (int)((float)nbpix * ratio);
|
|
|
|
if (verbosity > 1) {
|
2020-11-02 14:51:48 +01:00
|
|
|
fprintf(stderr, "%s: ratio %f nbpix %d todo %d\n", __func__,
|
2020-11-02 01:25:00 +01:00
|
|
|
ratio, nbpix, todo);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (foo=0; foo<todo; foo++)
|
|
|
|
{
|
|
|
|
fval = (float)drand48() * mval;
|
|
|
|
x = 1 + (rand() % (fimg->width-2));
|
|
|
|
y = rand() % fimg->height;
|
|
|
|
fimg_plot_rgb(fimg, x-1, y, fval, 0.0, 0.0);
|
|
|
|
fimg_plot_rgb(fimg, x , y, 0.0, 0.0, fval);
|
|
|
|
fimg_plot_rgb(fimg, x+1, y, 0.0, fval, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|