2020-11-10 03:58:18 +01:00
|
|
|
/*
|
|
|
|
* glitches.c
|
2020-11-12 23:36:06 +01:00
|
|
|
* ----------
|
|
|
|
*
|
|
|
|
* initially developped for the interpolator
|
2020-11-10 03:58:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-11-12 23:36:06 +01:00
|
|
|
#include <math.h>
|
2020-11-10 03:58:18 +01:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
#include "glitches.h"
|
|
|
|
|
2020-11-10 03:58:18 +01:00
|
|
|
extern int verbosity;
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-10 14:00:22 +01:00
|
|
|
int kill_a_random_line(FloatImg *pvictime, float fval, int bits)
|
2020-11-10 03:58:18 +01:00
|
|
|
{
|
|
|
|
int line, xpos, offset;
|
2020-11-12 23:36:06 +01:00
|
|
|
float ftmp;
|
2020-11-10 03:58:18 +01:00
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2020-11-10 14:00:22 +01:00
|
|
|
fprintf(stderr, ">>> %s ( %p %d )\n", __func__, pvictime, bits);
|
2020-11-10 03:58:18 +01: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 09:28:53 +01:00
|
|
|
for (xpos=0; xpos<pvictime->width; xpos++) {
|
2020-11-12 23:36:06 +01:00
|
|
|
if (bits & 1) { ftmp = pvictime->R[offset+xpos] * fval;
|
|
|
|
pvictime->R[offset+xpos] = sqrt(ftmp); }
|
2020-11-10 14:00:22 +01:00
|
|
|
else pvictime->R[offset+xpos] = 0.0;
|
2020-11-12 23:36:06 +01:00
|
|
|
if (bits & 2) { ftmp = pvictime->G[offset+xpos] * fval;
|
|
|
|
pvictime->G[offset+xpos] = sqrt(ftmp); }
|
2020-11-10 14:00:22 +01:00
|
|
|
else pvictime->G[offset+xpos] = 0.0;
|
2020-11-12 23:36:06 +01:00
|
|
|
if (bits & 4) { ftmp = pvictime->B[offset+xpos] * fval;
|
|
|
|
pvictime->B[offset+xpos] = sqrt(ftmp); }
|
2020-11-10 14:00:22 +01:00
|
|
|
else pvictime->B[offset+xpos] = 0.0;
|
2020-11-10 03:58:18 +01: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-10 14:00:22 +01:00
|
|
|
foo = kill_a_random_line(who, fval, rand() & 0x0f);
|
2020-11-10 03:58:18 +01:00
|
|
|
if (foo) abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-10 19:30:49 +01:00
|
|
|
int un_petit_flou_8x8(FloatImg *picture, int xpos, int ypos)
|
|
|
|
{
|
|
|
|
float sr, sg, sb;
|
|
|
|
int x, y, off;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* please add boundary check ?
|
|
|
|
*/
|
|
|
|
sr = sg = sb = 0.0;
|
|
|
|
for (y=0; y<8; y++) {
|
|
|
|
off = xpos + (picture->width * (y+ypos));
|
|
|
|
for (x=0; x<8; x++) {
|
|
|
|
sr += picture->R[off];
|
|
|
|
sg += picture->G[off];
|
|
|
|
sb += picture->B[off];
|
|
|
|
off++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sr /= 64.0; sg /= 64.0; sb /= 64.0;
|
|
|
|
for (y=0; y<8; y++) {
|
|
|
|
off = xpos + (picture->width * (y+ypos));
|
|
|
|
for (x=0; x<8; x++) {
|
|
|
|
picture->R[off] = sr;
|
|
|
|
picture->G[off] = sg;
|
|
|
|
picture->B[off] = sb;
|
|
|
|
off++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int un_moyen_flou_8x8(FloatImg *picture, int xpos, int ypos)
|
|
|
|
{
|
|
|
|
int i, j, x, y;
|
|
|
|
|
2020-11-12 23:36:06 +01:00
|
|
|
/*
|
|
|
|
* please add boundary check ?
|
|
|
|
*/
|
2020-11-10 19:30:49 +01:00
|
|
|
for (i=y=0; i<8; i++, y+=8) {
|
|
|
|
for (j=x=0; j<8; j++, x+=8 ) {
|
|
|
|
un_petit_flou_8x8(picture, x+xpos, y+ypos);
|
|
|
|
}
|
|
|
|
}
|
2020-11-12 23:36:06 +01:00
|
|
|
return 0;
|
2020-11-10 19:30:49 +01:00
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
int poke_a_random_pixel(FloatImg *picz, float fval, int kaboo)
|
|
|
|
{
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-12-02 19:24:54 +01:00
|
|
|
/*
|
|
|
|
* used by vertical_singlitch()
|
|
|
|
*/
|
|
|
|
int x_delta(float dy, float phy)
|
|
|
|
{
|
|
|
|
float param, fv;
|
|
|
|
param = dy + phy;
|
|
|
|
fv = 9.999*sin(param) + 6.666*sin(param*3) + 3.333*sin(param*5);
|
|
|
|
return (int)fv;
|
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
/*
|
|
|
|
* please explain arguments
|
|
|
|
*/
|
2020-11-15 11:47:37 +01:00
|
|
|
int vertical_singlitch(FloatImg *picz, int xpos, float fval,
|
|
|
|
float omega, float phi)
|
2020-11-14 22:26:11 +01:00
|
|
|
{
|
2020-11-15 11:47:37 +01:00
|
|
|
int y, x, w, h;
|
2020-12-02 19:24:54 +01:00
|
|
|
float dy;
|
|
|
|
float fv;
|
2020-11-14 22:26:11 +01:00
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( %p %d %f %f )\n", __func__, picz,
|
|
|
|
xpos, omega, phi);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
h = picz->height; w = picz->width;
|
2020-12-02 19:24:54 +01:00
|
|
|
#define BB 4
|
2020-11-15 11:47:37 +01:00
|
|
|
for (y=BB; y<h-BB; y++) {
|
2020-11-15 21:31:02 +01:00
|
|
|
|
2020-12-02 19:24:54 +01:00
|
|
|
dy = (float)y * omega; /* normalize vertical position */
|
2020-11-15 21:31:02 +01:00
|
|
|
|
2020-12-02 19:24:54 +01:00
|
|
|
x = xpos + x_delta(dy, phi); /* add sinus deviation */
|
2020-11-15 21:31:02 +01:00
|
|
|
|
2020-11-15 11:47:37 +01:00
|
|
|
/* compute bounding box */
|
|
|
|
if ( (x>BB) && (x<w-BB) ) {
|
|
|
|
/* an make the glitch */
|
|
|
|
fimg_plot_rgb(picz, x, y, fval, fval, fval);
|
2020-12-02 19:24:54 +01:00
|
|
|
fv = fval / 3.0;
|
2020-11-15 11:47:37 +01:00
|
|
|
if (rand() & 8)
|
2020-12-02 19:24:54 +01:00
|
|
|
fimg_plot_rgb(picz, x-1, y, fv, fv, fv);
|
2020-11-15 11:47:37 +01:00
|
|
|
if (rand() & 8)
|
2020-12-02 19:24:54 +01:00
|
|
|
// XXX else
|
|
|
|
fimg_plot_rgb(picz, x+1, y, fv, fv, fv);
|
2020-11-15 11:47:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2020-11-14 22:26:11 +01:00
|
|
|
}
|
|
|
|
/* -------------------------------------------------------------- */
|
2020-11-10 03:58:18 +01:00
|
|
|
|