FloatImg4PythonBinding/Fonderie/sfx.c

102 lines
2.1 KiB
C
Raw Normal View History

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>
#include <floatimg.h>
#include "fonctions.h"
/* -------------------------------------------------------------- */
/* global vars from main
*/
extern int verbosity;
/* -------------------------------------------------------------- */
int brotche_rand48(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)
fprintf(stderr, "ratio %f nbpix %d todo %d\n", ratio, nbpix, todo);
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) {
fprintf(stderr, "ratio %f nbpix %d todo %d\n",
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;
}
/* -------------------------------------------------------------- */
/*
* OMG ! a Color Graphic Adaptor emulator :)
*/
int kill_colors_a(FloatImg *fimg, float fval)
{
int nbpix, foo;
if (FIMG_TYPE_RGB != fimg->type) {
fprintf(stderr, "%s: bad src type %d on %p\n", __func__,
fimg->type, fimg);
return -8;
}
nbpix = fimg->width * fimg->height;
for (foo=0; foo<nbpix; foo++) {
if (fimg->R[foo] > fimg->G[foo])
fimg->B[foo] = fimg->R[foo];
else
fimg->B[foo] = fimg->G[foo];
}
return 0;
}
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */