FloatImg4PythonBinding/Fonderie/glitches.c

55 lines
1.2 KiB
C
Raw Normal View History

2020-11-10 13:58:18 +11:00
/*
* glitches.c
*/
#include <stdio.h>
#include <stdlib.h>
#include "../floatimg.h"
extern int verbosity;
/* -------------------------------------------------------------- */
2020-11-11 00:00:22 +11:00
int kill_a_random_line(FloatImg *pvictime, float fval, int bits)
2020-11-10 13:58:18 +11:00
{
int line, xpos, offset;
#if DEBUG_LEVEL
2020-11-11 00:00:22 +11:00
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pvictime, bits);
2020-11-10 13:58:18 +11:00
#endif
line = rand() % pvictime->height;
if (verbosity > 1) {
fprintf(stderr, "%s: try to kill line %d\n", __func__, line);
}
offset = pvictime->width * line;
2020-11-10 19:28:53 +11:00
for (xpos=0; xpos<pvictime->width; xpos++) {
2020-11-11 00:00:22 +11:00
if (bits & 1) pvictime->R[offset+xpos] = fval;
else pvictime->R[offset+xpos] = 0.0;
if (bits & 2) pvictime->G[offset+xpos] = fval;
else pvictime->G[offset+xpos] = 0.0;
if (bits & 4) pvictime->B[offset+xpos] = fval;
else pvictime->B[offset+xpos] = 0.0;
2020-11-10 13:58:18 +11:00
}
return 0;
}
/* -------------------------------------------------------------- */
int kill_a_few_lines(FloatImg *who, float fval, int number)
{
int idx, foo;
/* Frag the pixels */
for (idx=0; idx<number; idx++) {
2020-11-11 00:00:22 +11:00
foo = kill_a_random_line(who, fval, rand() & 0x0f);
2020-11-10 13:58:18 +11:00
if (foo) abort();
}
return foo;
}
/* -------------------------------------------------------------- */