diff options
author | Tom Schouten <doelie@users.sourceforge.net> | 2003-02-28 09:49:56 +0000 |
---|---|---|
committer | Tom Schouten <doelie@users.sourceforge.net> | 2003-02-28 09:49:56 +0000 |
commit | d5032cebbca8ea62fe427fac9b6a98eeba1e647f (patch) | |
tree | 4d2db1b27350a1d29d832064379de8f4d00a7d64 /modules | |
parent | 8227dc75b8e236f7f9629d1bc49fae0addee3def (diff) |
pdp modules
svn path=/trunk/externals/pdp/; revision=441
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pdp_constant.c | 220 | ||||
-rw-r--r-- | modules/pdp_grey2mask.c | 199 | ||||
-rw-r--r-- | modules/pdp_scanxy.c | 207 | ||||
-rw-r--r-- | modules/pdp_slice_cut.c | 300 | ||||
-rw-r--r-- | modules/pdp_slice_glue.c | 214 |
5 files changed, 1140 insertions, 0 deletions
diff --git a/modules/pdp_constant.c b/modules/pdp_constant.c new file mode 100644 index 0000000..c9a1e61 --- /dev/null +++ b/modules/pdp_constant.c @@ -0,0 +1,220 @@ +/* + * 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" + + + +typedef struct pdp_constant_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + + int x_packet0; + int x_queue_id; + + int x_pdp_image_type; + + unsigned int x_width; + unsigned int x_height; + + s8 x_fillbyte; + +} t_pdp_constant; + + + +void pdp_constant_type(t_pdp_constant *x, t_symbol *s) +{ + if (gensym("yv12") == s) {x->x_pdp_image_type = PDP_IMAGE_YV12; return;} + if (gensym("grey") == s) {x->x_pdp_image_type = PDP_IMAGE_GREY; return;} + + x->x_pdp_image_type = -1; + +} + + +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_fillbyte = (s8)(0x7f * f); + +} + + + +static void pdp_constant_createpacket_yv12(t_pdp_constant *x) +{ + /* create new packet */ + x->x_packet0 = pdp_packet_new_image_yv12(x->x_width, x->x_height); + +} + +static void pdp_constant_generate_yv12(t_pdp_constant *x) +{ + short int *data; + unsigned int w = x->x_width; + unsigned int h = x->x_height; + + data = (short int *) pdp_packet_data(x->x_packet0); + + memset(data, x->x_fillbyte, (w*h + ((w*h)>>2)) * sizeof(s16)); + + + return; + +} + +static void pdp_constant_createpacket_grey(t_pdp_constant *x) +{ + /* create new packet */ + x->x_packet0 = pdp_packet_new_image_grey(x->x_width, x->x_height); + +} + +static void pdp_constant_generate_grey(t_pdp_constant *x) +{ + unsigned int w = x->x_width; + unsigned int h = x->x_height; + short int *data = (short int *) pdp_packet_data(x->x_packet0); + + data = (short int *) pdp_packet_data(x->x_packet0); + + memset(data, x->x_fillbyte, (w*h) * sizeof(s16)); + + return; +} + +static void pdp_constant_sendpacket(t_pdp_constant *x, t_floatarg w, t_floatarg h) +{ + /* propagate if valid */ + pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); +} + + +static void pdp_constant_bang(t_pdp_constant *x) +{ + + int encoding; + + /* if we have an active packet, don't do anything */ + if (-1 != x->x_packet0) return; + + switch(x->x_pdp_image_type){ + + case PDP_IMAGE_YV12: + pdp_constant_createpacket_yv12(x); // don't create inside thread!!! + pdp_queue_add(x, pdp_constant_generate_yv12, pdp_constant_sendpacket, &x->x_queue_id); + break; + + case PDP_IMAGE_GREY: + pdp_constant_createpacket_grey(x); // don't create inside thread!!! + pdp_queue_add(x, pdp_constant_generate_grey, pdp_constant_sendpacket, &x->x_queue_id); + break; + + default: + break; + + } + + + /* release the packet */ + + +} + +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) +{ + + /* remove callback from process queue */ + pdp_queue_finish(x->x_queue_id); + + + /* tidy up */ + 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); + + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("value")); + x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); + + x->x_packet0 = -1; + x->x_queue_id = -1; + x->x_width = 320; + x->x_height = 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); + + 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 diff --git a/modules/pdp_grey2mask.c b/modules/pdp_grey2mask.c new file mode 100644 index 0000000..af6a99f --- /dev/null +++ b/modules/pdp_grey2mask.c @@ -0,0 +1,199 @@ +/* + * 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. + * + */ + + +/* this module converts a greyscale image or the luma channel of a colour image + to a colour image intensity mask, usable for multiplication */ + +#include "pdp.h" +#include "pdp_resample.h" + +typedef struct pdp_grey2mask_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + + int x_packet0; + int x_dropped; + int x_queue_id; + + +} t_pdp_grey2mask; + + + +static void pdp_grey2mask_process_grey(t_pdp_grey2mask *x) +{ + t_pdp *header = pdp_packet_header(x->x_packet0); + short int *data = (short int *)pdp_packet_data (x->x_packet0); + t_pdp *newheader = 0; + short int *newdata = 0; + int newpacket = -1; + + unsigned int w = header->info.image.width; + unsigned int h = header->info.image.height; + + unsigned int size = w*h; + unsigned int totalnbpixels = size; + unsigned int u_offset = size; + unsigned int v_offset = size + (size>>2); + + unsigned int row, col; + + newpacket = pdp_packet_new(PDP_IMAGE, (size + (size>>1))<<1); + newheader = pdp_packet_header(newpacket); + newdata = (short int *)pdp_packet_data(newpacket); + + newheader->info.image.encoding = PDP_IMAGE_YV12; + newheader->info.image.width = w; + newheader->info.image.height = h; + + + /* copy luma channel */ + memcpy(newdata, data, size * sizeof(s16)); + + /* subsample luma -> chroma channel */ + pdp_resample_halve(data, newdata+u_offset, w, h); + + /* copy this to the other chroma channel */ + memcpy(newdata+v_offset, newdata+u_offset, (size>>2)*sizeof(s16)); + + /* delete source packet and replace with new packet */ + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = newpacket; + return; +} + +static void pdp_grey2mask_process_yv12(t_pdp_grey2mask *x) +{ + /* process only the luminance channel */ + pdp_grey2mask_process_grey(x); +} + + + +static void pdp_grey2mask_process(t_pdp_grey2mask *x) +{ + int encoding; + t_pdp *header = 0; + + /* check if image data packets are compatible */ + if ( (header = pdp_packet_header(x->x_packet0)) + && (PDP_IMAGE == header->type)){ + + /* pdp_grey2mask_process inputs and write into active inlet */ + switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ + + case PDP_IMAGE_YV12: + pdp_grey2mask_process_yv12(x); + break; + + case PDP_IMAGE_GREY: + pdp_grey2mask_process_grey(x); + break; + + default: + /* don't know the type, so dont pdp_grey2mask_process */ + + break; + } + } +} + +static void pdp_grey2mask_sendpacket(t_pdp_grey2mask *x) +{ + /* unregister and propagate if valid packet */ + pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); +} + +static void pdp_grey2mask_input_0(t_pdp_grey2mask *x, t_symbol *s, t_floatarg f) +{ + + int p = (int)f; + + if (s== gensym("register_ro")) x->x_dropped = pdp_packet_copy_ro_or_drop(&x->x_packet0, p); + + + if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)){ + + + /* add the process method and callback to the process queue */ + + //pdp_queue_add(x, pdp_grey2mask_process, pdp_grey2mask_sendpacket, &x->x_queue_id); + // since the process method creates a packet, this is not processed in the thread + // $$$TODO: fix this + pdp_grey2mask_process(x); + pdp_grey2mask_sendpacket(x); + } + +} + + + +static void pdp_grey2mask_free(t_pdp_grey2mask *x) +{ + pdp_queue_finish(x->x_queue_id); + pdp_packet_mark_unused(x->x_packet0); + +} + +t_class *pdp_grey2mask_class; + + + +void *pdp_grey2mask_new(void) +{ + int i; + + t_pdp_grey2mask *x = (t_pdp_grey2mask *)pd_new(pdp_grey2mask_class); + + x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); + x->x_packet0 = -1; + x->x_queue_id = -1; + + + return (void *)x; +} + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_grey2mask_setup(void) +{ + + + pdp_grey2mask_class = class_new(gensym("pdp_grey2mask"), (t_newmethod)pdp_grey2mask_new, + (t_method)pdp_grey2mask_free, sizeof(t_pdp_grey2mask), 0, A_NULL); + + + class_addmethod(pdp_grey2mask_class, (t_method)pdp_grey2mask_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); + + +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/pdp_scanxy.c b/modules/pdp_scanxy.c new file mode 100644 index 0000000..84efd84 --- /dev/null +++ b/modules/pdp_scanxy.c @@ -0,0 +1,207 @@ +/* + * 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 <math.h> + +typedef struct pdp_scanxy_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + t_outlet *x_outlet1; + + int x_packet0; + int x_packet1; + + int x_interpolate; + + +} t_pdp_scanxy; + + +static t_int *pdp_scanxy_perform(t_int *w) +{ + + t_pdp_scanxy *x = (t_pdp_scanxy *)(w[1]); + t_int n = (t_int)(w[2]); + t_float *inx = (float *)(w[3]); + t_float *iny = (float *)(w[4]); + t_float *out = (float *)(w[5]); + + + /* check if valid image */ + if (-1 == x->x_packet0){ + while (n--) *out++ = 0; + return (w+6); + } + else{ + + t_pdp *header0 = pdp_packet_header(x->x_packet0); + short int *data0 = (short int *)pdp_packet_data (x->x_packet0); + short int *data1 = (short int *)pdp_packet_data (x->x_packet1); + int width = (float)header0->info.image.width; + int height = (float)header0->info.image.height; + int i; + + float scale = 1.0f / 32767.0f; + float scalein = 0x10000; + + if (x->x_interpolate && (-1 != x->x_packet1)){ + float a_old = 1.0f; + float a_new = 0.0f; + float a_inc = 1.0f / (float)n; + float old, new; + + while(n--){ + int xxx = ((((int)(scalein * *inx++)) & 0xffff) * width) >> 16; + int yyy = ((((int)(scalein * *iny++)) & 0xffff) * height) >> 16; + int offset = yyy*width+xxx; + new = ((float)(data0[offset])) * scale; + old = ((float)(data1[offset])) * scale; + *out++ = a_old * old + a_new * new; + a_new += a_inc; + a_old -= a_inc; + } + + pdp_packet_mark_unused(x->x_packet1); + x->x_packet1 = -1; + } + else{ + while(n--){ + int xxx = ((((int)(scalein * *inx++)) & 0xffff) * width) >> 16; + int yyy = ((((int)(scalein * *iny++)) & 0xffff) * height) >> 16; + int offset = yyy*width+xxx; + *out++ = ((float)(data0[offset])) * scale; + } + } + + return (w+6); + + } +} + + + + +static void pdp_scanxy_input_0(t_pdp_scanxy *x, t_symbol *s, t_floatarg f) +{ + int packet = (int)f; + + /* register */ + if (s== gensym("register_ro")){ + t_pdp *header = pdp_packet_header(packet); + if (!header) return; + if (PDP_IMAGE != header->type) return; + if ((header->info.image.encoding != PDP_IMAGE_YV12) && (header->info.image.encoding != PDP_IMAGE_GREY)) return; + + /* replace if not compatible or we are not interpolating */ + if (!x->x_interpolate || (!pdp_type_compat_image(x->x_packet0, packet))){ + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = pdp_packet_copy_ro(packet); + } + /* otherwize keep the old one */ + else{ + pdp_packet_mark_unused(x->x_packet1); + x->x_packet1 = x->x_packet0; + x->x_packet0 = pdp_packet_copy_ro(packet); + } + } + + /* pass packet */ + if (s== gensym("process")){ + //if (-1 != x->x_packet0) outlet_pdp (x->x_outlet0, x->x_packet0); + } + + +} + + + + +static void pdp_scanxy_dsp (t_pdp_scanxy *x, t_signal **sp) +{ + dsp_add(pdp_scanxy_perform, 5, x, sp[0]->s_n, sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec); + +} + + +static void pdp_scanxy_interpolate(t_pdp_scanxy *x, t_floatarg f) +{ + if (0.0 == f){ + x->x_interpolate = 0; + pdp_packet_mark_unused(x->x_packet1); + } + if (1.0 == f) x->x_interpolate = 1; +} + +static void pdp_scanxy_free(t_pdp_scanxy *x) +{ + pdp_packet_mark_unused(x->x_packet0); +} + + +t_class *pdp_scanxy_class; + + + +void *pdp_scanxy_new(void) +{ + t_pdp_scanxy *x = (t_pdp_scanxy *)pd_new(pdp_scanxy_class); + + + inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("signal"), gensym("signal")); + x->x_outlet1 = outlet_new(&x->x_obj, &s_signal); + x->x_packet0 = -1; + x->x_packet1 = -1; + + pdp_scanxy_interpolate(x, 0); + + return (void *)x; +} + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_scanxy_setup(void) +{ + + pdp_scanxy_class = class_new(gensym("pdp_scanxy~"), (t_newmethod)pdp_scanxy_new, + (t_method)pdp_scanxy_free, sizeof(t_pdp_scanxy), 0, A_NULL); + + CLASS_MAINSIGNALIN(pdp_scanxy_class, t_pdp_scanxy, x_f); + + class_addmethod(pdp_scanxy_class, (t_method)pdp_scanxy_interpolate, gensym("interpolate"), A_FLOAT, A_NULL); + class_addmethod(pdp_scanxy_class, (t_method)pdp_scanxy_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); + class_addmethod(pdp_scanxy_class, (t_method)pdp_scanxy_dsp, gensym("dsp"), A_NULL); + + +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/pdp_slice_cut.c b/modules/pdp_slice_cut.c new file mode 100644 index 0000000..0d689ea --- /dev/null +++ b/modules/pdp_slice_cut.c @@ -0,0 +1,300 @@ +/* + * 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. + * + */ + + +/* this module converts a greyscale image or the luma channel of a colour image + to a colour image intensity mask, usable for multiplication */ + +#include "pdp.h" +#include "pdp_resample.h" +#include "pdp_imageproc.h" + +typedef struct pdp_slice_cut_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + + int x_packet0; + //int x_dropped; + //int x_queue_id; + + unsigned int x_slice_height; + + +} t_pdp_slice_cut; + + + +static void pdp_slice_cut_process_grey(t_pdp_slice_cut *x) +{ + t_pdp *header = pdp_packet_header(x->x_packet0); + short int *data = (short int *)pdp_packet_data (x->x_packet0); + t_pdp *newheader = 0; + short int *newdata = 0; + int newpacket = -1; + + unsigned int w = header->info.image.width; + unsigned int h = header->info.image.height; + + unsigned int size = w*h; + unsigned int height_left = h; + unsigned int slice_height = 0; + unsigned int slice_yoffset = 0; + unsigned int slice_offset = 0; + unsigned int slice_size_bytes = 0; + + #define min(x,y) (((x)<(y)) ? (x) : (y)) + + while(height_left){ + + /* compute slice size */ + slice_height = min(x->x_slice_height, height_left); + height_left -= slice_height; + slice_size_bytes = (w << 1) * slice_height; + + /* create new slice packet */ + newpacket = pdp_packet_new(PDP_IMAGE, slice_size_bytes); + newheader = pdp_packet_header(newpacket); + newdata = (s16*)pdp_packet_data(newpacket); + + newheader->info.image.encoding = PDP_IMAGE_GREY; + newheader->info.image.width = w; + newheader->info.image.height = slice_height; + + newheader->info.image.orig_height = h; + newheader->info.image.slice_yoff = slice_yoffset; + + if (slice_height + height_left == h) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_FIRST; + else if (height_left == 0) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_LAST; + else newheader->info.image.slice_sync = PDP_IMAGE_SLICE_BODY; + + /* copy slice data */ + memcpy(newdata, data+slice_offset, slice_size_bytes); + + /* unregister and propagate if valid packet */ + pdp_packet_mark_unused(newpacket); + outlet_pdp(x->x_outlet0, newpacket); + + /* advance pointer stuff */ + slice_offset += (slice_size_bytes>>1); + slice_yoffset += slice_height; + + } + + + + /* delete source packet when finished */ + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = -1; + return; +} + +static void pdp_slice_cut_process_yv12(t_pdp_slice_cut *x) +{ + + t_pdp *header = pdp_packet_header(x->x_packet0); + short int *data = (short int *)pdp_packet_data (x->x_packet0); + t_pdp *newheader = 0; + short int *newdata = 0; + int newpacket = -1; + + unsigned int w = header->info.image.width; + unsigned int h = header->info.image.height; + + unsigned int size = w*h; + unsigned int height_left = h; + unsigned int slice_height = 0; + unsigned int sequence_number = 0; + unsigned int slice_offset = 0; + unsigned int slice_yoffset = 0; + unsigned int slice_size_bytes = 0; + unsigned int slice_size = 0; + + #define min(x,y) (((x)<(y)) ? (x) : (y)) + + while(height_left){ + + /* compute slice size */ + slice_height = min(x->x_slice_height, height_left); + height_left -= slice_height; + slice_size = w * slice_height; + slice_size_bytes = slice_size << 1; + + /* create new slice packet */ + newpacket = pdp_packet_new(PDP_IMAGE, slice_size_bytes + (slice_size_bytes >> 1)); + newheader = pdp_packet_header(newpacket); + newdata = (s16*)pdp_packet_data(newpacket); + newheader->info.image.encoding = PDP_IMAGE_YV12; + newheader->info.image.width = w; + newheader->info.image.height = slice_height; + newheader->info.image.orig_height = h; + newheader->info.image.slice_yoff = slice_yoffset; + + if (slice_height + height_left == h) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_FIRST; + else if (height_left == 0) newheader->info.image.slice_sync = PDP_IMAGE_SLICE_LAST; + else newheader->info.image.slice_sync = PDP_IMAGE_SLICE_BODY; + + + /* copy slice data */ + memcpy(newdata, + data + slice_offset, + slice_size_bytes); + + memcpy(newdata + slice_size, + data + size + (slice_offset>>2), + slice_size_bytes>>2); + + memcpy(newdata + slice_size + (slice_size >> 2), + data + size + (size >> 2) + (slice_offset >> 2), + slice_size_bytes>>2); + + /* unregister and propagate if valid packet */ + pdp_packet_mark_unused(newpacket); + outlet_pdp(x->x_outlet0, newpacket); + + /* advance pointer stuff */ + slice_offset += (slice_size_bytes>>1); + slice_yoffset += slice_height; + + } + + + + /* delete source packet when finished */ + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = -1; + return; + +} + + + +static void pdp_slice_cut_process(t_pdp_slice_cut *x) +{ + int encoding; + t_pdp *header = 0; + + + /* check if image data packets are compatible */ + if ( (header = pdp_packet_header(x->x_packet0)) + && (PDP_IMAGE == header->type)){ + + /* pdp_slice_cut_process inputs and write into active inlet */ + switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ + + case PDP_IMAGE_YV12: + pdp_slice_cut_process_yv12(x); + break; + + case PDP_IMAGE_GREY: + pdp_slice_cut_process_grey(x); + break; + + default: + /* don't know the type, so dont pdp_slice_cut_process */ + + break; + } + } +} + +static void pdp_slice_cut_input_0(t_pdp_slice_cut *x, t_symbol *s, t_floatarg f) +{ + + int p = (int)f; + + if (s== gensym("register_ro")) x->x_packet0 = pdp_packet_copy_ro(p); + if ((s == gensym("process")) && (-1 != x->x_packet0)) pdp_slice_cut_process(x); + +} + + + +static void pdp_slice_cut_height(t_pdp_slice_cut *x, t_floatarg f) +{ + int i = (int)f; + x->x_slice_height = pdp_imageproc_legalheight(i); + post("pdp_slice: height set to %d", x->x_slice_height); + +} +static void pdp_slice_cut_forceheight(t_pdp_slice_cut *x, t_floatarg f) +{ + int i = (int)f; + if (i<1) i = 1; + x->x_slice_height = i; + post("pdp_slice: WARNING: forceheight is a debug message. setting this to an abritrary"); + post("pdp_slice: WARNING: value can crash pdp. set it to a multiple of 2 and only use pixel"); + post("pdp_slice: WARNING: operations (no convolution or biquad) in the mmx version."); + post("pdp_slice: height forced to %d", x->x_slice_height); + +} + + +static void pdp_slice_cut_free(t_pdp_slice_cut *x) +{ + pdp_packet_mark_unused(x->x_packet0); +} + +t_class *pdp_slice_cut_class; + + + +void *pdp_slice_cut_new(void) +{ + int i; + + t_pdp_slice_cut *x = (t_pdp_slice_cut *)pd_new(pdp_slice_cut_class); + + x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); + x->x_packet0 = -1; + //x->x_queue_id = -1; + + x->x_slice_height = 8; + + return (void *)x; +} + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_slice_cut_setup(void) +{ + + + pdp_slice_cut_class = class_new(gensym("pdp_slice_cut"), (t_newmethod)pdp_slice_cut_new, + (t_method)pdp_slice_cut_free, sizeof(t_pdp_slice_cut), 0, A_NULL); + + + class_addmethod(pdp_slice_cut_class, (t_method)pdp_slice_cut_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); + class_addmethod(pdp_slice_cut_class, (t_method)pdp_slice_cut_height, gensym("height"), A_FLOAT, A_NULL); + class_addmethod(pdp_slice_cut_class, (t_method)pdp_slice_cut_forceheight, gensym("forceheight"), A_FLOAT, A_NULL); + + +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/pdp_slice_glue.c b/modules/pdp_slice_glue.c new file mode 100644 index 0000000..601bd32 --- /dev/null +++ b/modules/pdp_slice_glue.c @@ -0,0 +1,214 @@ +/* + * 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. + * + */ + + +/* this module converts a greyscale image or the luma channel of a colour image + to a colour image intensity mask, usable for multiplication */ + +#include "pdp.h" +#include "pdp_resample.h" + +typedef struct pdp_slice_glue_struct +{ + t_object x_obj; + t_float x_f; + + t_outlet *x_outlet0; + + int x_packet0; //input packet + int x_packet1; //output packet + +} t_pdp_slice_glue; + + + +static void pdp_slice_glue_process_grey(t_pdp_slice_glue *x) +{ + t_pdp *header0 = pdp_packet_header(x->x_packet0); + t_pdp *header1 = pdp_packet_header(x->x_packet1); + short int *data0 = (short int *)pdp_packet_data (x->x_packet0); + short int *data1 = (short int *)pdp_packet_data (x->x_packet1); + + + unsigned int offset = header0->info.image.width * header0->info.image.slice_yoff; + unsigned int slice_size = header0->info.image.width * header0->info.image.height; + + memcpy(data1 + offset, data0, slice_size << 1); + + + return; +} + +static void pdp_slice_glue_process_yv12(t_pdp_slice_glue *x) +{ + + t_pdp *header0 = pdp_packet_header(x->x_packet0); + t_pdp *header1 = pdp_packet_header(x->x_packet1); + short int *data0 = (short int *)pdp_packet_data (x->x_packet0); + short int *data1 = (short int *)pdp_packet_data (x->x_packet1); + + unsigned int w = header0->info.image.width; + unsigned int h = header0->info.image.height; + + unsigned int dw = header1->info.image.width; + unsigned int dh = header1->info.image.height; + unsigned int dsize = dh*dw; + + unsigned int offset = w * header0->info.image.slice_yoff; + unsigned int slice_size = w * h; + + memcpy(data1 + offset, data0, slice_size << 1); + memcpy(data1 + dsize + (offset >> 2), data0 + slice_size, slice_size >> 1); + memcpy(data1 + dsize + (dsize >>2) + (offset>>2), data0 + slice_size + (slice_size >> 2), slice_size >> 1); + + + return; + +} + + + +static void pdp_slice_glue_process(t_pdp_slice_glue *x) +{ + int encoding; + int newpacket; + t_pdp *header = 0; + t_pdp *dest_header = 0; + + + /* check if the packet is a valid slice packet */ + /* if not pass it along */ + if (!((header = pdp_packet_header(x->x_packet0)) && + (PDP_IMAGE == header->type) && (header->info.image.orig_height))) goto passalong; + + /* if this is the first slice of a sequence, or we don't have a dest packet yet */ + /* create a new destination packet */ + if ((x->x_packet1 == -1) || (header->info.image.slice_sync & PDP_IMAGE_SLICE_FIRST)){ + pdp_packet_mark_unused(x->x_packet1); + x->x_packet1 = pdp_packet_new(PDP_IMAGE, ((header->size - PDP_HEADER_SIZE) / header->info.image.height) + * header->info.image.orig_height); + dest_header = pdp_packet_header(x->x_packet1); + dest_header->info.image.encoding = header->info.image.encoding; + dest_header->info.image.width = header->info.image.width; + dest_header->info.image.height = header->info.image.orig_height; + } + + /* if this is a body or last slice, it has to be compatible with the current dest packet */ + /* else ignore it */ + else{ + dest_header = pdp_packet_header(x->x_packet1); + if (!((dest_header->info.image.encoding == header->info.image.encoding) && + ((dest_header->info.image.width == header->info.image.width)))) goto dispose; + } + + /* now we have a dest packet and the source packet is compatible with it, so copy the data */ + + + switch(pdp_packet_header(x->x_packet0)->info.image.encoding){ + + case PDP_IMAGE_YV12: + pdp_slice_glue_process_yv12(x); + break; + + case PDP_IMAGE_GREY: + pdp_slice_glue_process_grey(x); + break; + + default: + /* don't know the type, so dont pdp_slice_glue_process */ + + break; + } + + /* if the source packet was a final slice, pass on the constructed packet */ + if (header->info.image.slice_sync & PDP_IMAGE_SLICE_LAST){ + pdp_pass_if_valid(x->x_outlet0, &x->x_packet1); + } + + + /* processing is done so we delete the source packet */ + dispose: + pdp_packet_mark_unused(x->x_packet0); + x->x_packet0 = -1; + return; + + + passalong: + pdp_pass_if_valid(x->x_outlet0, &x->x_packet0); + return; + +} + +static void pdp_slice_glue_input_0(t_pdp_slice_glue *x, t_symbol *s, t_floatarg f) +{ + + int p = (int)f; + + if (s== gensym("register_ro")) x->x_packet0 = pdp_packet_copy_ro(p); + if ((s == gensym("process")) && (-1 != x->x_packet0)) pdp_slice_glue_process(x); + +} + + + + +static void pdp_slice_glue_free(t_pdp_slice_glue *x) +{ + pdp_packet_mark_unused(x->x_packet0); +} + +t_class *pdp_slice_glue_class; + + + +void *pdp_slice_glue_new(void) +{ + int i; + + t_pdp_slice_glue *x = (t_pdp_slice_glue *)pd_new(pdp_slice_glue_class); + + x->x_outlet0 = outlet_new(&x->x_obj, &s_anything); + x->x_packet0 = -1; + + return (void *)x; +} + + +#ifdef __cplusplus +extern "C" +{ +#endif + + +void pdp_slice_glue_setup(void) +{ + + + pdp_slice_glue_class = class_new(gensym("pdp_slice_glue"), (t_newmethod)pdp_slice_glue_new, + (t_method)pdp_slice_glue_free, sizeof(t_pdp_slice_glue), 0, A_NULL); + + + class_addmethod(pdp_slice_glue_class, (t_method)pdp_slice_glue_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); + +} + +#ifdef __cplusplus +} +#endif |