Update of /cvsroot/pure-data/externals/pdp/modules/image_basic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6756/modules/image_basic
Added Files: Makefile README pdp_add.c pdp_bq.c pdp_cheby.c pdp_constant.c pdp_conv.c pdp_gain.c pdp_logic.c pdp_mix.c pdp_mul.c pdp_noise.c pdp_plasma.c pdp_randmix.c pdp_stateless.c pdp_zoom.c Log Message: checking in pdp 0.12.4 from http://zwizwa.fartit.com/pd/pdp/pdp-0.12.4.tar.gz
--- NEW FILE: pdp_plasma.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_plasma_struct { t_pdp_imagebase x_base;
int x_packet0; t_outlet *x_outlet0; void *x_plasmagen;
t_symbol *x_type;
unsigned int x_width; unsigned int x_height;
} t_pdp_plasma;
void pdp_plasma_type(t_pdp_plasma *x, t_symbol *s) { x->x_type = s; }
void pdp_plasma_random(t_pdp_plasma *x, t_floatarg seed) { if (seed == 0.0f) seed = (float)random(); pdp_imageproc_plasma_setseed(x->x_plasmagen, seed);
}
void pdp_plasma_turbulence(t_pdp_plasma *x, t_floatarg f) { pdp_imageproc_plasma_setturbulence(x->x_plasmagen, f);
}
/* called inside pdp thread */ static void pdp_plasma_process(t_pdp_plasma *x) { /* seed the 16 bit rng with a new random number from the clib */ pdp_plasma_random(x, 0.0f);
/* create new packet */ if (x->x_type == gensym("grey")) {x->x_packet0 = pdp_packet_new_image_grey(x->x_width, x->x_height);} else if (x->x_type == gensym("yv12")) {x->x_packet0 = pdp_packet_new_image_YCrCb(x->x_width, x->x_height);} else return;
/* call the image processor */ pdp_imageproc_dispatch_1buf(&pdp_imageproc_plasma_process, x->x_plasmagen, -1, x->x_packet0); }
/* called inside pd thread: involves an outlet */ static void pdp_plasma_postproc(t_pdp_plasma *x) { pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet0); }
static void pdp_plasma_bang(t_pdp_plasma *x) { pdp_base_bang(x); }
static void pdp_plasma_dim(t_pdp_plasma *x, t_floatarg w, t_floatarg h) { x->x_width = pdp_imageproc_legalwidth((int)w); x->x_height = pdp_imageproc_legalheight((int)h); //post("dims %d %d", x->x_width, x->x_height); }
static void pdp_plasma_free(t_pdp_plasma *x) { pdp_imagebase_free(x);
/* tidy up */ pdp_packet_mark_unused(x->x_packet0); pdp_imageproc_plasma_delete(x->x_plasmagen); }
t_class *pdp_plasma_class;
void *pdp_plasma_new(void) { int i;
t_pdp_plasma *x = (t_pdp_plasma *)pd_new(pdp_plasma_class);
pdp_imagebase_init(x); pdp_base_disable_active_inlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_plasma_process); pdp_base_set_postproc_method(x, (t_pdp_method)pdp_plasma_postproc);
pdp_base_add_gen_inlet(x, gensym("float"), gensym("turbulence")); x->x_outlet0 = pdp_base_add_pdp_outlet(x); x->x_packet0 = -1;
x->x_width = 320; x->x_height = 240;
x->x_plasmagen = pdp_imageproc_plasma_new();
pdp_plasma_random(x, 0.0f); pdp_plasma_type(x, gensym("yv12")); pdp_plasma_turbulence(x, 0.1);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_plasma_setup(void) {
pdp_plasma_class = class_new(gensym("pdp_plasma"), (t_newmethod)pdp_plasma_new, (t_method)pdp_plasma_free, sizeof(t_pdp_plasma), 0, A_NULL);
pdp_imagebase_setup(pdp_plasma_class);
class_addmethod(pdp_plasma_class, (t_method)pdp_plasma_random, gensym("seed"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_plasma_class, (t_method)pdp_plasma_turbulence, gensym("turbulence"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_plasma_class, (t_method)pdp_plasma_type, gensym("type"), A_SYMBOL, A_NULL); class_addmethod(pdp_plasma_class, (t_method)pdp_plasma_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_plasma_class, (t_method)pdp_plasma_bang, gensym("bang"), A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_noise.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_noise_struct { t_pdp_imagebase x_base;
int x_packet0; t_outlet *x_outlet0; void *x_noisegen;
t_symbol *x_type;
unsigned int x_width; unsigned int x_height;
} t_pdp_noise;
void pdp_noise_type(t_pdp_noise *x, t_symbol *s) { x->x_type = s; }
void pdp_noise_random(t_pdp_noise *x, t_floatarg seed) { if (seed == 0.0f) seed = (float)random(); pdp_imageproc_random_setseed(x->x_noisegen, seed);
}
/* called inside pdp thread */ static void pdp_noise_process(t_pdp_noise *x) { /* seed the 16 bit rng with a new random number from the clib */ pdp_noise_random(x, 0.0f);
/* create new packet */ if (x->x_type == gensym("grey")) { x->x_packet0 = pdp_packet_new_image_grey(x->x_width, x->x_height); } else if (x->x_type == gensym("yv12")) { x->x_packet0 = pdp_packet_new_image_YCrCb(x->x_width, x->x_height); } else return;
/* call the image processor */ pdp_imageproc_dispatch_1buf(&pdp_imageproc_random_process, x->x_noisegen, -1, x->x_packet0); }
/* called inside pd thread: involves an outlet */ static void pdp_noise_postproc(t_pdp_noise *x) { pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet0); }
static void pdp_noise_bang(t_pdp_noise *x) { pdp_base_bang(x); }
static void pdp_noise_dim(t_pdp_noise *x, t_floatarg w, t_floatarg h) { x->x_width = pdp_imageproc_legalwidth((int)w); x->x_height = pdp_imageproc_legalheight((int)h); //post("dims %d %d", x->x_width, x->x_height); }
static void pdp_noise_free(t_pdp_noise *x) { pdp_imagebase_free(x);
/* tidy up */ pdp_packet_mark_unused(x->x_packet0); pdp_imageproc_random_delete(x->x_noisegen); }
t_class *pdp_noise_class;
void *pdp_noise_new(void) { int i;
t_pdp_noise *x = (t_pdp_noise *)pd_new(pdp_noise_class);
pdp_imagebase_init(x); pdp_base_disable_active_inlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_noise_process); pdp_base_set_postproc_method(x, (t_pdp_method)pdp_noise_postproc);
x->x_outlet0 = pdp_base_add_pdp_outlet(x); x->x_packet0 = -1;
x->x_width = 320; x->x_height = 240;
x->x_noisegen = pdp_imageproc_random_new();
pdp_noise_random(x, 0.0f); pdp_noise_type(x, gensym("yv12"));
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_noise_setup(void) {
pdp_noise_class = class_new(gensym("pdp_noise"), (t_newmethod)pdp_noise_new, (t_method)pdp_noise_free, sizeof(t_pdp_noise), 0, A_NULL);
pdp_imagebase_setup(pdp_noise_class);
class_addmethod(pdp_noise_class, (t_method)pdp_noise_random, gensym("seed"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_noise_class, (t_method)pdp_noise_type, gensym("type"), A_SYMBOL, A_NULL); class_addmethod(pdp_noise_class, (t_method)pdp_noise_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_noise_class, (t_method)pdp_noise_bang, gensym("bang"), A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_mul.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_mul_struct { t_pdp_imagebase x_base;
} t_pdp_mul;
static void pdp_mul_process(t_pdp_mul *x) { int p0 = pdp_base_get_packet(x, 0); int p1 = pdp_base_get_packet(x, 1); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_mul_process, 0, mask, p0, p1); }
static void pdp_mul_free(t_pdp_mul *x) { pdp_imagebase_free(x); }
t_class *pdp_mul_class;
void *pdp_mul_new(void) { t_pdp_mul *x = (t_pdp_mul *)pd_new(pdp_mul_class);
/* super init */ pdp_imagebase_init(x); pdp_base_add_pdp_inlet(x); pdp_base_add_pdp_outlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_mul_process);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_mul_setup(void) {
pdp_mul_class = class_new(gensym("pdp_mul"), (t_newmethod)pdp_mul_new, (t_method)pdp_mul_free, sizeof(t_pdp_mul), 0, A_NULL);
pdp_imagebase_setup(pdp_mul_class); }
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_gain.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_gain_struct { t_pdp_imagebase x_base; void *x_gain;
} t_pdp_gain;
static void pdp_gain_process(t_pdp_gain *x) { int p = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x);
pdp_packet_image_set_chanmask(p, mask); pdp_imageproc_dispatch_1buf(&pdp_imageproc_gain_process, x->x_gain, 0, p);
}
static void pdp_gain_gain(t_pdp_gain *x, t_floatarg f) { pdp_imageproc_gain_setgain(x->x_gain, f); }
t_class *pdp_gain_class;
void pdp_gain_free(t_pdp_gain *x) { pdp_imagebase_free(x); pdp_imageproc_gain_delete(x->x_gain); }
void *pdp_gain_new(t_floatarg f) { t_pdp_gain *x = (t_pdp_gain *)pd_new(pdp_gain_class);
/* super init */ pdp_imagebase_init(x);
/* no arg, or zero -> gain = 1 */ if (f==0.0f) f = 1.0f;
/* io */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("gain")); pdp_base_add_pdp_outlet(x);
/* callbacks */ pdp_base_set_process_method(x, (t_pdp_method)pdp_gain_process);
x->x_gain = pdp_imageproc_gain_new(); pdp_gain_gain(x, f);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_gain_setup(void) {
pdp_gain_class = class_new(gensym("pdp_gain"), (t_newmethod)pdp_gain_new, (t_method)pdp_gain_free, sizeof(t_pdp_gain), 0, A_DEFFLOAT, A_NULL);
pdp_imagebase_setup(pdp_gain_class);
class_addmethod(pdp_gain_class, (t_method)pdp_gain_gain, gensym("gain"), A_DEFFLOAT, A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_conv.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_conv_struct { t_pdp_imagebase x_base;
unsigned int x_nbpasses; bool x_horizontal; bool x_vertical;
void *x_convolver_hor; void *x_convolver_ver;
} t_pdp_conv;
static void pdp_conv_process(t_pdp_conv *x) { int p = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x);
if (x->x_vertical){ pdp_imageproc_conv_setnbpasses(x->x_convolver_ver, x->x_nbpasses); pdp_imageproc_dispatch_1buf(&pdp_imageproc_conv_process, x->x_convolver_ver, mask, p); }
if (x->x_horizontal){ pdp_imageproc_conv_setnbpasses(x->x_convolver_hor, x->x_nbpasses); pdp_imageproc_dispatch_1buf(&pdp_imageproc_conv_process, x->x_convolver_hor, mask, p); }
}
static void pdp_conv_passes(t_pdp_conv *x, t_floatarg f) { int passes = (int)f; passes = passes < 0 ? 0 : passes; x->x_nbpasses = passes;
} static void pdp_conv_hor(t_pdp_conv *x, t_floatarg f) { int hor = (int)f; x->x_horizontal = (hor != 0);
} static void pdp_conv_ver(t_pdp_conv *x, t_floatarg f) { int ver = (int)f; x->x_vertical = (ver != 0); } static void pdp_conv_free(t_pdp_conv *x) { pdp_imagebase_free(x); pdp_imageproc_conv_delete(x->x_convolver_hor); pdp_imageproc_conv_delete(x->x_convolver_ver); }
/* setup hmask */
static void pdp_conv_hleft(t_pdp_conv *x, t_floatarg f) { pdp_imageproc_conv_setmin1(x->x_convolver_hor, f);
} static void pdp_conv_hmiddle(t_pdp_conv *x, t_floatarg f) { pdp_imageproc_conv_setzero(x->x_convolver_hor, f); } static void pdp_conv_hright(t_pdp_conv *x, t_floatarg f) { pdp_imageproc_conv_setplus1(x->x_convolver_hor, f); }
static void pdp_conv_hmask(t_pdp_conv *x, t_floatarg l, t_floatarg m, t_floatarg r) { pdp_conv_hleft(x, l); pdp_conv_hmiddle(x, m); pdp_conv_hright(x, r); }
static void pdp_conv_vtop(t_pdp_conv *x, t_floatarg f) { pdp_imageproc_conv_setmin1(x->x_convolver_ver, f); } static void pdp_conv_vmiddle(t_pdp_conv *x, t_floatarg f) { pdp_imageproc_conv_setzero(x->x_convolver_ver, f);
} static void pdp_conv_vbottom(t_pdp_conv *x, t_floatarg f) { pdp_imageproc_conv_setplus1(x->x_convolver_ver, f); }
static void pdp_conv_vmask(t_pdp_conv *x, t_floatarg l, t_floatarg m, t_floatarg r) { pdp_conv_vtop(x, l); pdp_conv_vmiddle(x, m); pdp_conv_vbottom(x, r); }
static void pdp_conv_mask(t_pdp_conv *x, t_floatarg l, t_floatarg m, t_floatarg r) { pdp_conv_hmask(x, l, m, r); pdp_conv_vmask(x, l, m, r); }
t_class *pdp_conv_class;
void *pdp_conv_new(void) { t_pdp_conv *x = (t_pdp_conv *)pd_new(pdp_conv_class);
/* super init */ pdp_imagebase_init(x);
/* inlets & outlets */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("passes")); pdp_base_add_pdp_outlet(x);
/* register */ pdp_base_set_process_method(x, (t_pdp_method)pdp_conv_process);
x->x_nbpasses = 1; x->x_horizontal = true; x->x_vertical = true;
x->x_convolver_hor = pdp_imageproc_conv_new(); x->x_convolver_ver = pdp_imageproc_conv_new();
pdp_imageproc_conv_setbordercolor(x->x_convolver_hor, 0); pdp_imageproc_conv_setbordercolor(x->x_convolver_ver, 0);
pdp_imageproc_conv_setorientation(x->x_convolver_hor, PDP_IMAGEPROC_CONV_HORIZONTAL); pdp_imageproc_conv_setorientation(x->x_convolver_ver, PDP_IMAGEPROC_CONV_VERTICAL);
pdp_conv_mask(x, .25,.5,.25);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_conv_setup(void) {
pdp_conv_class = class_new(gensym("pdp_conv"), (t_newmethod)pdp_conv_new, (t_method)pdp_conv_free, sizeof(t_pdp_conv), 0, A_NULL);
pdp_imagebase_setup(pdp_conv_class);
class_addmethod(pdp_conv_class, (t_method)pdp_conv_passes, gensym("passes"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_hor, gensym("hor"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_ver, gensym("ver"), A_DEFFLOAT, A_NULL);
class_addmethod(pdp_conv_class, (t_method)pdp_conv_hleft, gensym("hleft"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_hmiddle, gensym("hmiddle"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_hright, gensym("hright"), A_DEFFLOAT, A_NULL);
class_addmethod(pdp_conv_class, (t_method)pdp_conv_vtop, gensym("vtop"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_vmiddle, gensym("vmiddle"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_vbottom, gensym("vbottom"), A_DEFFLOAT, A_NULL);
class_addmethod(pdp_conv_class, (t_method)pdp_conv_vmask, gensym("vmask"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_hmask, gensym("hmask"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_conv_class, (t_method)pdp_conv_mask, gensym("mask"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_logic.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_logic_struct { t_pdp_imagebase x_base;
void *x_mask;
} t_pdp_logic;
static void pdp_logic_process_and(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); int p1 = pdp_base_get_packet(x, 1); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_and_process, 0, mask, p0, p1); }
static void pdp_logic_process_or(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); int p1 = pdp_base_get_packet(x, 1); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_or_process, 0, mask, p0, p1); }
static void pdp_logic_process_xor(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); int p1 = pdp_base_get_packet(x, 1); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_xor_process, 0, mask, p0, p1); }
static void pdp_logic_process_not(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_not_process, 0, mask, p0); }
static void pdp_logic_process_mask(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_mask_process, x->x_mask, mask, p0); }
static void pdp_logic_process_softthresh(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_softthresh_process, x->x_mask, mask, p0); }
static void pdp_logic_process_hardthresh(t_pdp_logic *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_hardthresh_process, x->x_mask, mask, p0); }
static void pdp_logic_set_mask(t_pdp_logic *x, t_floatarg f) { /* using a pointer as a variable hmm? */ u32 mask = ((u32)f) & 0xffff; x->x_mask = ((void * )mask); }
static void pdp_logic_set_threshold(t_pdp_logic *x, t_floatarg f) { /* using a pointer as a variable hmm? */ if (f<0.0f) f = 0.0f; if (f>1.0f) f = 1.0f; x->x_mask = (void *)((u32)(((float)0x7fff) * f)); }
static void pdp_logic_set_depth(t_pdp_logic *x, t_floatarg f) { u32 mask; int shift = (16 - ((int)f)); if (shift < 0) shift = 0; if (shift > 16) shift = 16; mask = ((0xffff)<<shift) & 0xffff; x->x_mask = (void *)mask;
}
static void pdp_logic_free(t_pdp_logic *x) { /* remove process method from queue before deleting data */ pdp_imagebase_free(x); }
t_class *pdp_logic_class;
/* common new method */ void *pdp_logic_new(void) { t_pdp_logic *x = (t_pdp_logic *)pd_new(pdp_logic_class);
/* super init */ pdp_imagebase_init(x);
/* outlet */ pdp_base_add_pdp_outlet(x); x->x_mask = 0;
return (void *)x; }
void *pdp_logic_new_and(void) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_pdp_inlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_and);
return (void *)x; }
void *pdp_logic_new_or(void) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_pdp_inlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_or); return (void *)x; }
void *pdp_logic_new_xor(void) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_pdp_inlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_xor); return (void *)x; }
void *pdp_logic_new_not(void) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_not); return (void *)x; }
void *pdp_logic_new_mask(void) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("mask")); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_mask);
x->x_mask = (void *)0xffff; return (void *)x; }
void *pdp_logic_new_depth(void) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("depth")); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_mask);
x->x_mask = (void *)0xffff; return (void *)x; }
void *pdp_logic_new_softthresh(t_floatarg f) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("threshold")); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_softthresh); pdp_logic_set_threshold(x,f);
return (void *)x; }
void *pdp_logic_new_hardthresh(t_floatarg f) { t_pdp_logic *x = pdp_logic_new(); /* init in/out */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("threshold")); pdp_base_set_process_method(x, (t_pdp_method)pdp_logic_process_hardthresh); pdp_logic_set_threshold(x,f);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_logic_setup(void) {
pdp_logic_class = class_new(gensym("pdp_and"), (t_newmethod)pdp_logic_new_and, (t_method)pdp_logic_free, sizeof(t_pdp_logic), 0, A_DEFFLOAT, A_NULL);
pdp_imagebase_setup(pdp_logic_class);
class_addcreator((t_newmethod)pdp_logic_new_or, gensym("pdp_or"), A_NULL); class_addcreator((t_newmethod)pdp_logic_new_xor, gensym("pdp_xor"), A_NULL); class_addcreator((t_newmethod)pdp_logic_new_not, gensym("pdp_not"), A_NULL); class_addcreator((t_newmethod)pdp_logic_new_mask, gensym("pdp_bitmask"), A_NULL); class_addcreator((t_newmethod)pdp_logic_new_depth, gensym("pdp_bitdepth"), A_NULL); class_addcreator((t_newmethod)pdp_logic_new_softthresh, gensym("pdp_sthresh"), A_NULL); class_addcreator((t_newmethod)pdp_logic_new_hardthresh, gensym("pdp_hthresh"), A_NULL);
class_addmethod(pdp_logic_class, (t_method)pdp_logic_set_mask, gensym("mask"), A_FLOAT, A_NULL); class_addmethod(pdp_logic_class, (t_method)pdp_logic_set_depth, gensym("depth"), A_FLOAT, A_NULL); class_addmethod(pdp_logic_class, (t_method)pdp_logic_set_threshold, gensym("threshold"), A_FLOAT, A_NULL); }
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_randmix.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_randmix_struct { t_pdp_imagebase x_base; void *x_randmixer;
} t_pdp_randmix;
void pdp_randmix_random(t_pdp_randmix *x, t_floatarg seed) { pdp_imageproc_randmix_setseed(x->x_randmixer, seed); }
static void pdp_randmix_process(t_pdp_randmix *x) { int p0 = pdp_base_get_packet(x, 0); int p1 = pdp_base_get_packet(x, 1); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_randmix_process, x->x_randmixer, mask, p0, p1);
}
static void pdp_randmix_threshold(t_pdp_randmix *x, t_floatarg f) { pdp_imageproc_randmix_setthreshold(x->x_randmixer, f);
}
static void pdp_randmix_free(t_pdp_randmix *x) { pdp_imagebase_free(x); pdp_imageproc_randmix_delete(x->x_randmixer); }
t_class *pdp_randmix_class;
void *pdp_randmix_new(void) { int i;
t_pdp_randmix *x = (t_pdp_randmix *)pd_new(pdp_randmix_class);
pdp_imagebase_init(x); pdp_base_add_pdp_inlet(x); pdp_base_add_gen_inlet(x, gensym("float"), gensym("threshold"));
pdp_base_set_process_method(x, (t_pdp_method)pdp_randmix_process);
pdp_base_add_pdp_outlet(x); x->x_randmixer = pdp_imageproc_randmix_new();
pdp_randmix_threshold(x, 0.5f); pdp_randmix_random(x, 0.0f);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_randmix_setup(void) {
pdp_randmix_class = class_new(gensym("pdp_randmix"), (t_newmethod)pdp_randmix_new, (t_method)pdp_randmix_free, sizeof(t_pdp_randmix), 0, A_NULL);
pdp_imagebase_setup(pdp_randmix_class);
class_addmethod(pdp_randmix_class, (t_method)pdp_randmix_threshold, gensym("threshold"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_randmix_class, (t_method)pdp_randmix_random, gensym("seed"), A_DEFFLOAT, A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_bq.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h" #include <math.h>
/* computes a transfer function: * * b0 + b1 z^(-1) + b2 z^(-2) * T(z) = -------------------------- * 1 + a1 z^(-1) + a2 z^(-2) * */
typedef struct pdp_bq_struct {
t_pdp_imagebase x_base; //pdp_bq derives from pdp_base
/* state packets for bqt */ int x_packet1; int x_packet2;
unsigned int x_nbpasses;
/* single direction */ unsigned int x_direction;
bool x_reset_on_formatchange;
void *x_biquad;
float x_coefs_a[3]; // a0, -a1, -a2 float x_coefs_b[3]; // b0, b1, b2 float x_state_u[2]; // u0, u1 float x_state_u_save[2]; // u0, u1 (for reset)
} t_pdp_bq;
/************************* COEFFICIENT METHODS ****************************/
static void pdp_bq_a0(t_pdp_bq *x, t_floatarg f){x->x_coefs_a[0] = f;} static void pdp_bq_a1(t_pdp_bq *x, t_floatarg f){x->x_coefs_a[1] = -f;} static void pdp_bq_a2(t_pdp_bq *x, t_floatarg f){x->x_coefs_a[2] = -f;}
static void pdp_bq_b0(t_pdp_bq *x, t_floatarg f){x->x_coefs_b[0] = f;} static void pdp_bq_b1(t_pdp_bq *x, t_floatarg f){x->x_coefs_b[1] = f;} static void pdp_bq_b2(t_pdp_bq *x, t_floatarg f){x->x_coefs_b[2] = f;}
static void pdp_bq_u0(t_pdp_bq *x, t_floatarg f){x->x_state_u_save[0] = f;} static void pdp_bq_u1(t_pdp_bq *x, t_floatarg f){x->x_state_u_save[1] = f;}
static void pdp_bq_setcoefs(t_pdp_bq *x, float a0, float a1, float a2, float b0, float b1, float b2) { pdp_bq_a0(x,a0); pdp_bq_a1(x,a1); pdp_bq_a2(x,a2); pdp_bq_b0(x,b0); pdp_bq_b1(x,b1); pdp_bq_b2(x,b2); pdp_imageproc_bq_setcoef(x->x_biquad, x->x_coefs_a); }
static void pdp_bq_setstate(t_pdp_bq *x, float u0, float u1) { pdp_bq_u0(x,u0); pdp_bq_u1(x,u1); pdp_imageproc_bq_setcoef(x->x_biquad, x->x_coefs_a); }
/* reso lowpass */ static void pdp_bq_lpf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) { float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; w = 2.0 * M_PI * f; cs = cos(w); sn = sin(w); alpha = sn*sinh(1.0f/(2.0f*Q)); b0 = (1.0 - cs)/2.0; b1 = 1.0 - cs; b2 = (1.0 - cs)/2.0; a0 = (1.0 + alpha); a1 = -2.0*cs; a2 = 1.0 - alpha;
pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2);
}
/* reso highpass */ static void pdp_bq_hpf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) { float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; w = 2.0 * M_PI * f; cs = cos(w); sn = sin(w); alpha = sn*sinh(1.0f/(2.0f*Q));
b0 = (1.0 + cs)/2.0; b1 = -1.0 - cs; b2 = (1.0 + cs)/2.0; a0 = (1.0 + alpha); a1 = -2.0*cs; a2 = 1.0 - alpha;
pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2);
}
/* reso allpass */ static void pdp_bq_apf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) { float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; w = 2.0 * M_PI * f; cs = cos(w); sn = sin(w); alpha = sn*sinh(1.0f/(2.0f*Q));
b0 = (1.0 - alpha); b1 = -2.0 * cs; b2 = (1.0 + alpha); a0 = (1.0 + alpha); a1 = -2.0*cs; a2 = 1.0 - alpha;
pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); }
/* reso band stop (notch) */ static void pdp_bq_bsf(t_pdp_bq *x, t_floatarg f, t_floatarg Q) { float a0, a1, a2, b0, b1, b2, cs, sn, w, alpha; w = 2.0 * M_PI * f; cs = cos(w); sn = sin(w); alpha = sn*sinh(1.0f/(2.0f*Q));
b0 = 1.0; b1 = -2.0 * cs; b2 = 1.0; a0 = (1.0 + alpha); a1 = -2.0*cs; a2 = 1.0 - alpha;
pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2);
}
static void pdp_bq_onep(t_pdp_bq *x, t_floatarg f) { float a0,a1,a2,b0,b1,b2;
if (f>1.0f) f = 1.0f; if (f<0.0f) f = 0.0f;
a0 = 1.0f; a1 = -(1.0f - f); a2 = 0.0f; b0 = f; b1 = 0.0f; b2 = 0.0f; pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); }
static void pdp_bq_twop(t_pdp_bq *x, t_floatarg f) { float f1; float a0,a1,a2,b0,b1,b2;
if (f>1.0) f = 1.0; if (f<0.0) f = 0.0;
f1 = 1.0 - f;
a0 = 1.0f; a1 = -2.0f*f1; a2 = f1*f1; b0 = f*f; b1 = 0.0f; b2 = 0.0f;
pdp_bq_setcoefs(x, a0, a1, a2, b0, b1, b2); }
/************************* PROCESS METHODS ****************************/
static void pdp_bqt_process(t_pdp_bq *x) { /* get received packets */ int p0 = pdp_base_get_packet(x, 0);
/* get channel mask */ u32 mask = pdp_imagebase_get_chanmask(x);
pdp_imageproc_dispatch_3buf(&pdp_imageproc_bqt_process, x->x_biquad, mask, p0, x->x_packet1, x->x_packet2); }
static void pdp_bq_process(t_pdp_bq *x) { /* get received packets */ int p0 = pdp_base_get_packet(x, 0);
/* get channel mask */ u32 mask = pdp_imagebase_get_chanmask(x);
pdp_imageproc_bq_setnbpasses(x->x_biquad, x->x_nbpasses); pdp_imageproc_bq_setdirection(x->x_biquad, x->x_direction); pdp_imageproc_dispatch_1buf(&pdp_imageproc_bq_process, x->x_biquad, mask, p0); }
static void pdp_bqt_reset(t_pdp_bq *x) { pdp_imageproc_dispatch_1buf(&pdp_imageproc_zero_process, 0, -1, x->x_packet1); pdp_imageproc_dispatch_1buf(&pdp_imageproc_zero_process, 0, -1, x->x_packet2); }
static void pdp_bqt_preproc(t_pdp_bq *x) { /* get received packets */ int p0 = pdp_base_get_packet(x, 0);
/* check if state packets are compatible */ if (!(pdp_packet_image_compat(p0, x->x_packet1) && pdp_packet_image_compat(p0, x->x_packet1))){
/* if not, create new state packets by copying the input packets */ post("pdp_bqt: created new state packets"); pdp_packet_mark_unused(x->x_packet1); pdp_packet_mark_unused(x->x_packet2); x->x_packet1 = pdp_packet_clone_rw(p0); x->x_packet2 = pdp_packet_clone_rw(p0); /* reset */ if (x->x_reset_on_formatchange) pdp_bqt_reset(x); } }
/************************* CONFIG METHODS ****************************/
static void pdp_bq_passes(t_pdp_bq *x, t_floatarg f) { int passes = (int)f; passes = passes < 0 ? 0 : passes; x->x_nbpasses = passes;
}
static void pdp_bq_lr(t_pdp_bq *x, t_floatarg f) { if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT; if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_LEFT2RIGHT; }
static void pdp_bq_rl(t_pdp_bq *x, t_floatarg f) { if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT; if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_RIGHT2LEFT; } static void pdp_bq_tb(t_pdp_bq *x, t_floatarg f) { if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM; if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_TOP2BOTTOM; }
static void pdp_bq_bt(t_pdp_bq *x, t_floatarg f) { if (f == 1.0f) x->x_direction |= PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP; if (f == 0.0f) x->x_direction &= ~PDP_IMAGEPROC_BIQUAD_BOTTOM2TOP; }
static void pdp_bq_hor(t_pdp_bq *x, t_floatarg f) { pdp_bq_lr(x, f); pdp_bq_rl(x, f); } static void pdp_bq_ver(t_pdp_bq *x, t_floatarg f) { pdp_bq_tb(x, f); pdp_bq_bt(x, f); }
/************************* DES/CONSTRUCTORS ****************************/
static void pdp_bq_free(t_pdp_bq *x) { pdp_imagebase_free(x); pdp_imageproc_bq_delete(x->x_biquad); pdp_packet_mark_unused(x->x_packet1); pdp_packet_mark_unused(x->x_packet2);
}
void pdp_bq_init(t_pdp_bq *x) { x->x_packet1 = -1; x->x_packet2 = -1;
x->x_nbpasses = 1; x->x_reset_on_formatchange = true;
x->x_biquad = pdp_imageproc_bq_new();
pdp_bq_setstate(x, 0.0f, 0.0f); pdp_bq_onep(x, 0.1f);
}
/* class pointers */
t_class *pdp_bq_class; /* biquad spacial processing */ t_class *pdp_bqt_class; /* biquad time processing */
void *pdp_bq_new(void) { t_pdp_bq *x = (t_pdp_bq *)pd_new(pdp_bq_class);
pdp_imagebase_init(x); pdp_base_add_pdp_outlet(x);
pdp_base_set_process_method(x, (t_pdp_method)pdp_bq_process); pdp_base_add_gen_inlet(x, gensym("float"), gensym("passes"));
pdp_bq_init(x); return (void *)x; }
void *pdp_bqt_new(void) { t_pdp_bq *x = (t_pdp_bq *)pd_new(pdp_bqt_class);
pdp_imagebase_init(x); pdp_base_add_pdp_outlet(x);
pdp_base_set_preproc_method(x, (t_pdp_method)pdp_bqt_preproc); pdp_base_set_process_method(x, (t_pdp_method)pdp_bqt_process);
pdp_bq_init(x); return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
/************************* CLASS CONSTRUCTORS ****************************/
void pdp_bq_coefmethods_setup(t_class *c) {
/* raw coefficient methods */ class_addmethod(c, (t_method)pdp_bq_a1, gensym("a1"), A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_a2, gensym("a2"), A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_b0, gensym("b0"), A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_b1, gensym("b1"), A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_b2, gensym("b2"), A_FLOAT, A_NULL); //class_addmethod(c, (t_method)pdp_bq_u1, gensym("u1"), A_FLOAT, A_NULL); //class_addmethod(c, (t_method)pdp_bq_u2, gensym("u2"), A_FLOAT, A_NULL);
/* real pole filters */ class_addmethod(c, (t_method)pdp_bq_onep, gensym("onep"), A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_twop, gensym("twop"), A_FLOAT, A_NULL);
/* resonnant pole filters */ class_addmethod(c, (t_method)pdp_bq_lpf, gensym("lpf"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_hpf, gensym("hpf"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_apf, gensym("apf"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(c, (t_method)pdp_bq_bsf, gensym("bsf"), A_FLOAT, A_FLOAT, A_NULL); }
void pdp_bq_setup(void) {
/* setup spatial processing class */
pdp_bq_class = class_new(gensym("pdp_bq"), (t_newmethod)pdp_bq_new, (t_method)pdp_bq_free, sizeof(t_pdp_bq), 0, A_NULL);
pdp_imagebase_setup(pdp_bq_class); pdp_bq_coefmethods_setup(pdp_bq_class);
class_addmethod(pdp_bq_class, (t_method)pdp_bq_passes, gensym("passes"), A_FLOAT, A_NULL); class_addmethod(pdp_bq_class, (t_method)pdp_bq_hor, gensym("hor"), A_FLOAT, A_NULL); class_addmethod(pdp_bq_class, (t_method)pdp_bq_ver, gensym("ver"), A_FLOAT, A_NULL); class_addmethod(pdp_bq_class, (t_method)pdp_bq_tb, gensym("tb"), A_FLOAT, A_NULL); class_addmethod(pdp_bq_class, (t_method)pdp_bq_bt, gensym("bt"), A_FLOAT, A_NULL); class_addmethod(pdp_bq_class, (t_method)pdp_bq_lr, gensym("lr"), A_FLOAT, A_NULL); class_addmethod(pdp_bq_class, (t_method)pdp_bq_rl, gensym("rl"), A_FLOAT, A_NULL);
/* setup time processing class */ pdp_bqt_class = class_new(gensym("pdp_bqt"), (t_newmethod)pdp_bqt_new, (t_method)pdp_bq_free, sizeof(t_pdp_bq), 0, A_NULL);
pdp_imagebase_setup(pdp_bqt_class); pdp_bq_coefmethods_setup(pdp_bqt_class);
/* control */ class_addmethod(pdp_bqt_class, (t_method)pdp_bqt_reset, gensym("reset"), A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: Makefile --- current: all_modules
include ../../Makefile.config
PDP_MOD = pdp_add.o pdp_conv.o \ pdp_mix.o pdp_mul.o pdp_randmix.o \ pdp_bq.o pdp_noise.o \ pdp_gain.o pdp_zoom.o \ pdp_constant.o \ pdp_logic.o pdp_stateless.o pdp_plasma.o $(PDP_IMAGE_BASIC)
# build basic image processing modules (derived from base class) all_modules: $(PDP_MOD)
clean: rm -f *~ rm -f *.o
--- NEW FILE: pdp_constant.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_constant_struct { t_pdp_imagebase x_base;
t_outlet *x_outlet0;
int x_packet0;
t_symbol *x_type;
unsigned int x_width; unsigned int x_height;
void *x_constant;
} t_pdp_constant;
void pdp_constant_type(t_pdp_constant *x, t_symbol *s) { x->x_type = s; }
void pdp_constant_value(t_pdp_constant *x, t_floatarg f) { if (f>1.0f) f = 1.0f; if (f<-1.0f) f = -1.0f;
x->x_constant = (void *)((s32)(0x7fff * f)); }
static void pdp_constant_process(t_pdp_constant *x) { /* get channel mask */ u32 mask = pdp_imagebase_get_chanmask(x);
/* create new packet */ if (x->x_type == gensym("yv12")){x->x_packet0 = pdp_packet_new_image_YCrCb(x->x_width, x->x_height);} else if (x->x_type == gensym("grey")){x->x_packet0 = pdp_packet_new_image_grey(x->x_width, x->x_height);} else return;
/* this processes the packets using a pdp image processor */ pdp_imageproc_dispatch_1buf(&pdp_imageproc_constant_process, x->x_constant, mask, x->x_packet0); pdp_imageproc_dispatch_1buf(&pdp_imageproc_constant_process, 0, ~mask, x->x_packet0);
return; }
static void pdp_constant_postproc(t_pdp_constant *x) { pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet0); }
static void pdp_constant_bang(t_pdp_constant *x) { pdp_base_bang(x); }
static void pdp_constant_dim(t_pdp_constant *x, t_floatarg w, t_floatarg h) { x->x_width = pdp_imageproc_legalwidth((int)w); x->x_height = pdp_imageproc_legalheight((int)h); //post("dims %d %d", x->x_width, x->x_height); }
static void pdp_constant_free(t_pdp_constant *x) { pdp_imagebase_free(x); pdp_packet_mark_unused(x->x_packet0);
}
t_class *pdp_constant_class;
void *pdp_constant_new(void) { int i; t_pdp_constant *x = (t_pdp_constant *)pd_new(pdp_constant_class);
/* super init */ pdp_imagebase_init(x);
/* in/out*/ pdp_base_add_gen_inlet(x, gensym("float"), gensym("value")); x->x_outlet0 = pdp_base_add_pdp_outlet(x);
/* base callbacks */ pdp_base_disable_active_inlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_constant_process); pdp_base_set_postproc_method(x, (t_pdp_method)pdp_constant_postproc);
/* data init */ x->x_packet0 = -1; pdp_constant_dim(x, 320, 240); pdp_constant_value(x, 0.0f); pdp_constant_type(x, gensym("yv12"));
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_constant_setup(void) {
pdp_constant_class = class_new(gensym("pdp_constant"), (t_newmethod)pdp_constant_new, (t_method)pdp_constant_free, sizeof(t_pdp_constant), 0, A_NULL);
pdp_imagebase_setup(pdp_constant_class);
class_addmethod(pdp_constant_class, (t_method)pdp_constant_value, gensym("value"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_constant_class, (t_method)pdp_constant_type, gensym("type"), A_SYMBOL, A_NULL); class_addmethod(pdp_constant_class, (t_method)pdp_constant_dim, gensym("dim"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_constant_class, (t_method)pdp_constant_bang, gensym("bang"), A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_cheby.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include <stdio.h> #include <gsl/gsl_math.h> #include <gsl/gsl_chebyshev.h> #include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_cheby_struct { t_pdp_imagebase x_base; void *x_cheby; int x_iterations; int x_order; gsl_cheb_series *x_cs; gsl_function x_F; float *x_vec; int x_nbpoints;
} t_pdp_cheby;
static double pdp_cheby_mappingfunction(double f, void *params) { t_pdp_cheby *x = (t_pdp_cheby *)params; int index;
/* if there's no array, return the identity function */ if (!x->x_vec) return f;
/* else interpolate the array */ index = ((f + 1) * 0.5) * (x->x_nbpoints - 1); return x->x_vec[index];
}
static void pdp_cheby_coef(t_pdp_cheby *x, t_floatarg c, t_floatarg f) { pdp_imageproc_cheby_setcoef(x->x_cheby, (int)c, f); }
static void pdp_cheby_approx(t_pdp_cheby *x, t_symbol *s) { int i; t_garray *a;
/* check if array is valid */ if (!(a = (t_garray *)pd_findbyclass(s, garray_class))){ post("pdp_cheby: %s: no such array", s->s_name); } /* get data */ else if (!garray_getfloatarray(a, &x->x_nbpoints, &x->x_vec)){ post("pdp_cheby: %s: bad template", s->s_name);
}
else{
/* calculate approximation */ gsl_cheb_init (x->x_cs, &x->x_F, -1.0, 1.0);
/* propagate coefficients */ for (i=0; i<=x->x_order; i++){ pdp_cheby_coef(x, i, x->x_cs->c[i]); } }
x->x_vec = 0; return;
}
static void pdp_cheby_process(t_pdp_cheby *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_cheby_setnbpasses(x->x_cheby, x->x_iterations); pdp_imageproc_dispatch_1buf(&pdp_imageproc_cheby_process, x->x_cheby, mask, p0); }
static void pdp_cheby_reset(t_pdp_cheby *x) { int i; for (i = 0; i <= x->x_order; i++) pdp_imageproc_cheby_setcoef(x->x_cheby, i, 0); }
static void pdp_cheby_iterations(t_pdp_cheby *x, t_floatarg f) { int i = (int)f; if (i<0) i = 0; x->x_iterations = i;
} static void pdp_cheby_free(t_pdp_cheby *x) { pdp_imagebase_free(x); pdp_imageproc_cheby_delete(x->x_cheby); gsl_cheb_free(x->x_cs);
}
t_class *pdp_cheby_class;
void *pdp_cheby_new(t_floatarg f) { t_pdp_cheby *x = (t_pdp_cheby *)pd_new(pdp_cheby_class); int order = (int)(f);
/* super init */ pdp_imagebase_init(x);
/* create i/o */ pdp_base_add_gen_inlet(x, gensym("float"), gensym("iterations")); pdp_base_add_pdp_outlet(x);
/* setup callback */ pdp_base_set_process_method(x, (t_pdp_method)pdp_cheby_process);
/* data init */ x->x_cheby = pdp_imageproc_cheby_new(order); x->x_iterations = 1;
if (order < 2) order = 2; x->x_order = order;
/* init gls chebychev series object */ x->x_cs = gsl_cheb_alloc(order); x->x_F.function = pdp_cheby_mappingfunction; x->x_F.params = x; x->x_vec = 0;
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_cheby_setup(void) {
pdp_cheby_class = class_new(gensym("pdp_cheby"), (t_newmethod)pdp_cheby_new, (t_method)pdp_cheby_free, sizeof(t_pdp_cheby), 0, A_DEFFLOAT, A_NULL);
pdp_imagebase_setup(pdp_cheby_class);
class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_coef, gensym("coef"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_iterations, gensym("iterations"), A_FLOAT, A_NULL); class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_reset, gensym("reset"), A_NULL); class_addmethod(pdp_cheby_class, (t_method)pdp_cheby_approx, gensym("approx"), A_SYMBOL, A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: README --- This directory contains "normal" planar 16 bit unsigned image packet processors, derived from the t_pdp_imagebase class defined in pdp_imagebase.h
Most modules are wrappers around monochrome bitmap processors (pdp_imageproc_*)
--- NEW FILE: pdp_zoom.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_zoom_struct { t_pdp_imagebase x_base;
int x_packet1; t_outlet *x_outlet0; void *x_zoom;
int x_quality; //not used
} t_pdp_zoom;
static void pdp_zoom_process(t_pdp_zoom *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_resample_affinemap_process, x->x_zoom, mask, p0, x->x_packet1); }
static void pdp_zoom_postproc(t_pdp_zoom *x) { /* delete source packet */ pdp_packet_mark_unused(pdp_base_move_packet(x, 0));
/* unregister and propagate if valid dest packet */ pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet1); }
static void pdp_zoom_preproc(t_pdp_zoom *x) { int p = pdp_base_get_packet(x, 0); t_pdp *header0 = pdp_packet_header(p); if ((header0) && (PDP_IMAGE == header0->type)){ x->x_packet1 = pdp_packet_clone_rw(p); }
}
static void pdp_zoom_zoom_x(t_pdp_zoom *x, t_floatarg f) { pdp_imageproc_resample_affinemap_setzoomx(x->x_zoom, f); }
static void pdp_zoom_angle(t_pdp_zoom *x, t_floatarg f) { pdp_imageproc_resample_affinemap_setangle(x->x_zoom, f); }
static void pdp_zoom_zoom_y(t_pdp_zoom *x, t_floatarg f) { pdp_imageproc_resample_affinemap_setzoomy(x->x_zoom, f); }
static void pdp_zoom_zoom(t_pdp_zoom *x, t_floatarg f) { pdp_zoom_zoom_x(x, f); pdp_zoom_zoom_y(x, f); }
static void pdp_zoom_center_x(t_pdp_zoom *x, t_floatarg f) { pdp_imageproc_resample_affinemap_setcenterx(x->x_zoom, f); }
static void pdp_zoom_center_y(t_pdp_zoom *x, t_floatarg f) { pdp_imageproc_resample_affinemap_setcentery(x->x_zoom, f); } static void pdp_zoom_center(t_pdp_zoom *x, t_floatarg fx, t_floatarg fy) { pdp_zoom_center_x(x, fx); pdp_zoom_center_y(x, fy); }
// not used static void pdp_zoom_quality(t_pdp_zoom *x, t_floatarg f) { if (f==0) x->x_quality = 0; if (f==1) x->x_quality = 1; }
t_class *pdp_zoom_class;
void pdp_zoom_free(t_pdp_zoom *x) { pdp_imagebase_free(x); pdp_imageproc_resample_affinemap_delete(x->x_zoom); pdp_packet_mark_unused(x->x_packet1); }
void pdp_zoom_init_common(t_pdp_zoom *x) { pdp_imagebase_init(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_zoom_process); pdp_base_set_postproc_method(x, (t_pdp_method)pdp_zoom_postproc); pdp_base_set_preproc_method(x, (t_pdp_method)pdp_zoom_preproc);
x->x_outlet0 = pdp_base_add_pdp_outlet(x); x->x_packet1 = -1; x->x_zoom = pdp_imageproc_resample_affinemap_new();
//quality is not used: all routines are "high quality" bilinear //pdp_zoom_quality(x, 1); pdp_zoom_center_x(x, 0.5f); pdp_zoom_center_y(x, 0.5f);
}
void *pdp_zoom_new(t_floatarg zoom) { t_pdp_zoom *x = (t_pdp_zoom *)pd_new(pdp_zoom_class);
pdp_zoom_init_common(x); pdp_base_add_gen_inlet(x, gensym("float"), gensym("zoom"));
if (zoom == 0.0f) zoom = 1.0f; pdp_zoom_zoom(x, zoom); pdp_zoom_angle(x, 0.0f);
return (void *)x; }
void *pdp_zrot_new(t_floatarg zoom, t_floatarg angle) { t_pdp_zoom *x = (t_pdp_zoom *)pd_new(pdp_zoom_class);
pdp_zoom_init_common(x); pdp_base_add_gen_inlet(x, gensym("float"), gensym("zoom")); pdp_base_add_gen_inlet(x, gensym("float"), gensym("angle"));
if (zoom == 0.0f) zoom = 1.0f; pdp_zoom_zoom(x, zoom); pdp_zoom_angle(x, angle);
return (void *)x; }
void *pdp_rotate_new(t_floatarg angle) { t_pdp_zoom *x = (t_pdp_zoom *)pd_new(pdp_zoom_class);
pdp_zoom_init_common(x);
pdp_base_add_gen_inlet(x, gensym("float"), gensym("angle"));
pdp_zoom_zoom(x, 1.0f); pdp_zoom_angle(x, angle);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_zoom_setup(void) {
pdp_zoom_class = class_new(gensym("pdp_zoom"), (t_newmethod)pdp_zoom_new, (t_method)pdp_zoom_free, sizeof(t_pdp_zoom), 0, A_DEFFLOAT, A_NULL);
class_addcreator((t_newmethod)pdp_zrot_new, gensym("pdp_zrot"), A_DEFFLOAT, A_DEFFLOAT, A_NULL); class_addcreator((t_newmethod)pdp_rotate_new, gensym("pdp_rotate"), A_DEFFLOAT, A_NULL);
pdp_imagebase_setup(pdp_zoom_class);
class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_quality, gensym("quality"), A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_center_x, gensym("centerx"), A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_center_y, gensym("centery"), A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_center, gensym("center"), A_FLOAT, A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_zoom_x, gensym("zoomx"), A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_zoom_y, gensym("zoomy"), A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_zoom, gensym("zoom"), A_FLOAT, A_NULL); class_addmethod(pdp_zoom_class, (t_method)pdp_zoom_angle, gensym("angle"), A_FLOAT, A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_stateless.c --- /* * Pure Data Packet module. Some stateless image operations. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_stateless_struct { t_pdp_imagebase x_base;
} t_pdp_stateless;
static void pdp_stateless_process_abs(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_abs_process, 0, mask, p0); }
static void pdp_stateless_process_hardthresh(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_hardthresh_process, 0, mask, p0); }
static void pdp_stateless_process_zthresh(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_zthresh_process, 0, mask, p0); }
static void pdp_stateless_process_positive(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_ispositive_process, 0, mask, p0); }
static void pdp_stateless_process_sign(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_sign_process, 0, mask, p0); }
static void pdp_stateless_process_flip_tb(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_flip_tb_process, 0, mask, p0); }
static void pdp_stateless_process_flip_lr(t_pdp_stateless *x) { int p0 = pdp_base_get_packet(x, 0); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_1buf(&pdp_imageproc_flip_lr_process, 0, mask, p0); }
static void pdp_stateless_free(t_pdp_stateless *x) { /* remove process method from queue before deleting data */ pdp_imagebase_free(x); }
t_class *pdp_stateless_class;
/* common new method */ void *pdp_stateless_new(void) { t_pdp_stateless *x = (t_pdp_stateless *)pd_new(pdp_stateless_class);
/* super init */ pdp_imagebase_init(x);
/* outlet */ pdp_base_add_pdp_outlet(x);
return (void *)x; }
void *pdp_stateless_new_abs(void) { t_pdp_stateless *x = pdp_stateless_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_stateless_process_abs); return (void *)x; }
void *pdp_stateless_new_zthresh(void) { t_pdp_stateless *x = pdp_stateless_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_stateless_process_zthresh); return (void *)x; }
void *pdp_stateless_new_positive(void) { t_pdp_stateless *x = pdp_stateless_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_stateless_process_positive); return (void *)x; }
void *pdp_stateless_new_sign(void) { t_pdp_stateless *x = pdp_stateless_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_stateless_process_sign); return (void *)x; }
void *pdp_stateless_new_flip_tb(void) { t_pdp_stateless *x = pdp_stateless_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_stateless_process_flip_tb); return (void *)x; }
void *pdp_stateless_new_flip_lr(void) { t_pdp_stateless *x = pdp_stateless_new(); /* init in/out */ pdp_base_set_process_method(x, (t_pdp_method)pdp_stateless_process_flip_lr); return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_stateless_setup(void) {
pdp_stateless_class = class_new(gensym("pdp_abs"), (t_newmethod)pdp_stateless_new_abs, (t_method)pdp_stateless_free, sizeof(t_pdp_stateless), 0, A_NULL);
pdp_imagebase_setup(pdp_stateless_class);
class_addcreator((t_newmethod)pdp_stateless_new_zthresh, gensym("pdp_zthresh"), A_NULL); class_addcreator((t_newmethod)pdp_stateless_new_positive, gensym("pdp_positive"), A_NULL); class_addcreator((t_newmethod)pdp_stateless_new_sign, gensym("pdp_sign"), A_NULL); class_addcreator((t_newmethod)pdp_stateless_new_flip_tb, gensym("pdp_flip_tb"), A_NULL); class_addcreator((t_newmethod)pdp_stateless_new_flip_lr, gensym("pdp_flip_lr"), A_NULL);
/* future extensions */ //class_addcreator((t_newmethod)pdp_stateless_new_garble, gensym("pdp_garble"), A_NULL);
}
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_add.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_add_struct { /* a pdp derived class has the t_pdp_imagebase data member as first entry */ /* it contains the pd object and the data members for the pdp_base class */ t_pdp_imagebase x_base;
} t_pdp_add;
/* the process method */ static void pdp_add_process(t_pdp_add *x) { /* get received packets */ int p0, p1;
/* get channel mask */ int mask = pdp_imagebase_get_chanmask(x);
/* this processes the packets using a pdp image processor */ /* replace this with your own processing code */ /* for raw packet acces: use pdp_pacjet_header() and pdp_packet_data() */ p0 = pdp_base_get_packet(x,0); p1 = pdp_base_get_packet(x,1);
pdp_imageproc_dispatch_2buf(&pdp_imageproc_add_process, 0, mask, p0, p1);
}
static void pdp_add_free(t_pdp_add *x) { /* free super: this is mandatory (it stops the thread if there is one running and frees all packets) */ pdp_imagebase_free(x);
/* if you have allocated more packets this is the place to free them with pdp_mark_unused */ }
t_class *pdp_add_class;
void *pdp_add_new(void) { /* allocate */ t_pdp_add *x = (t_pdp_add *)pd_new(pdp_add_class);
/* init super: this is mandatory */ pdp_imagebase_init(x);
/* set the pdp processing method */ pdp_base_set_process_method(x, (t_pdp_method)pdp_add_process);
/* create additional cold (readonly) pdp inlets (there is already one pdp inlet) */ pdp_base_add_pdp_inlet(x);
/* create a pdp_outlet */ pdp_base_add_pdp_outlet(x);
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_add_setup(void) { /* create a standard pd class */ pdp_add_class = class_new(gensym("pdp_add"), (t_newmethod)pdp_add_new, (t_method)pdp_add_free, sizeof(t_pdp_add), 0, A_NULL);
/* inherit pdp base class methods */ pdp_imagebase_setup(pdp_add_class); }
#ifdef __cplusplus } #endif
--- NEW FILE: pdp_mix.c --- /* * Pure Data Packet module. * Copyright (c) by Tom Schouten pdp@zzz.kotnet.org * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
#include "pdp.h" #include "pdp_imagebase.h"
typedef struct pdp_mix_struct { t_pdp_imagebase x_base;
t_outlet *x_outlet0; t_outlet *x_outlet1;
void *x_mixer;
int x_extrapolate;
} t_pdp_mix;
static void pdp_mix_process(t_pdp_mix *x) { int p0 = pdp_base_get_packet(x, 0); int p1 = pdp_base_get_packet(x, 1); u32 mask = pdp_imagebase_get_chanmask(x); pdp_imageproc_dispatch_2buf(&pdp_imageproc_mix_process, x->x_mixer, mask, p0, p1); }
static void pdp_mix_mix(t_pdp_mix *x, t_floatarg f) { float f2; if (!x->x_extrapolate){ if (f < 0.0f) f = 0.0f; if (f > 1.0f) f = 1.0f; }
f2 = (1.0f - f); pdp_imageproc_mix_setleftgain(x->x_mixer, f2); pdp_imageproc_mix_setrightgain(x->x_mixer, f);
}
static void pdp_mix_mix1(t_pdp_mix *x, t_floatarg f) { pdp_imageproc_mix_setleftgain(x->x_mixer, f);
} static void pdp_mix_mix2(t_pdp_mix *x, t_floatarg f2) { pdp_imageproc_mix_setrightgain(x->x_mixer, f2); }
static void pdp_mix_extrapolate(t_pdp_mix *x, t_floatarg f) { if (f == 0.0f) x->x_extrapolate = 0; if (f == 1.0f) x->x_extrapolate = 1; }
static void pdp_mix_free(t_pdp_mix *x) { pdp_imagebase_free(x); pdp_imageproc_mix_delete(x->x_mixer); }
t_class *pdp_mix_class; t_class *pdp_mix2_class;
void *pdp_mix_common_init(t_pdp_mix *x) { int i;
pdp_imagebase_init(x); pdp_base_add_pdp_inlet(x); pdp_base_add_pdp_outlet(x); pdp_base_set_process_method(x, (t_pdp_method)pdp_mix_process);
x->x_extrapolate = 0; x->x_mixer = pdp_imageproc_mix_new(); pdp_mix_mix(x, 0.0f);
return (void *)x; }
void *pdp_mix_new(t_floatarg mix) { t_pdp_mix *x = (t_pdp_mix *)pd_new(pdp_mix_class); pdp_mix_common_init(x); pdp_base_add_gen_inlet(x, gensym("float"), gensym("mix"));
if (mix == 0.0f) mix = 0.5f; pdp_mix_mix(x, mix); return (void *)x; }
void *pdp_mix2_new(t_floatarg mix1, t_floatarg mix2) { t_pdp_mix *x = (t_pdp_mix *)pd_new(pdp_mix2_class); pdp_mix_common_init(x);
pdp_base_add_gen_inlet(x, gensym("float"), gensym("mix1")); pdp_base_add_gen_inlet(x, gensym("float"), gensym("mix2"));
if ((mix1 == 0.0f) && (mix2 == 0.0f)) mix1 = mix2 = 0.5f; pdp_mix_mix1(x, mix1); pdp_mix_mix2(x, mix2); return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_mix_setup(void) {
pdp_mix_class = class_new(gensym("pdp_mix"), (t_newmethod)pdp_mix_new, (t_method)pdp_mix_free, sizeof(t_pdp_mix), 0, A_DEFFLOAT, A_NULL);
pdp_imagebase_setup(pdp_mix_class); class_addmethod(pdp_mix_class, (t_method)pdp_mix_mix, gensym("mix"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_mix_class, (t_method)pdp_mix_extrapolate, gensym("extrapolate"), A_DEFFLOAT, A_NULL);
pdp_mix2_class = class_new(gensym("pdp_mix2"), (t_newmethod)pdp_mix2_new, (t_method)pdp_mix_free, sizeof(t_pdp_mix), 0, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
pdp_imagebase_setup(pdp_mix2_class); class_addmethod(pdp_mix2_class, (t_method)pdp_mix_mix1, gensym("mix1"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_mix2_class, (t_method)pdp_mix_mix2, gensym("mix2"), A_DEFFLOAT, A_NULL); class_addmethod(pdp_mix2_class, (t_method)pdp_mix_extrapolate, gensym("extrapolate"), A_DEFFLOAT, A_NULL);
}
#ifdef __cplusplus } #endif