static void pdp_frei0r_process(t_pdp_frei0r *x) { int encoding; t_pdp *header = 0; char *parname; unsigned pi; int partype; t_atom plist[2]; t_atom tlist[2]; t_atom vlist[2]; f0r_param_info_t param_infos; /* check if image data packets are compatible */ if ( (header = pdp_packet_header(x->x_packet1)) && (PDP_BITMAP == header->type)){ /* pdp_frei0r_process inputs and write into active inlet */ switch(pdp_packet_header(x->x_packet1)->info.image.encoding){ case PDP_BITMAP_RGBA: x->x_packet2 = pdp_packet_clone_rw(x->x_packet1); pdp_queue_add(x, pdp_frei0r_process_rgba, pdp_frei0r_sendpacket, &x->x_queue_id); break; default: /* don't know the type, so dont pdp_frei0r_process */ break; } } // hack to display infos of first loaded plugin if ( ( x->x_plugin_count>0 ) && ( !x->x_infosok ) ) { outlet_symbol(x->x_pname, gensym( x->plugins[x->x_plugin].name ) ); outlet_float(x->x_nparams, (float)x->plugins[x->x_plugin].numparameters); for ( pi=0; pi<x->plugins[x->x_plugin].numparameters; pi++ ) { (*x->plugins[x->x_plugin].f0r_get_param_info)(¶m_infos, pi); SETFLOAT(&plist[0], pi); SETSYMBOL(&plist[1], gensym(param_infos.name) ); outlet_list( x->x_parname, &s_list, 2, &plist[0] ); SETFLOAT(&tlist[0], pi); SETFLOAT(&tlist[1], param_infos.type ); outlet_list( x->x_partype, &s_list, 2, &tlist[0] ); } x->x_infosok = 1; } }
static void pdp_scope_createpacket_grey(t_pdp_scope *x) { t_pdp *header; short int *data; unsigned int w = x->x_width; unsigned int h = x->x_height; unsigned int size = w*h; unsigned int totalnbpixels = size; unsigned int packet_size = totalnbpixels << 1; /* create new packet */ x->x_packet0 = pdp_packet_new_image_grey(w,h); if(x->x_packet0 == -1){ post("pdp_scope: can't allocate packet"); return; } header = pdp_packet_header(x->x_packet0); data = (short int *) pdp_packet_data(x->x_packet0); memset(pdp_packet_data(x->x_packet0), 0, packet_size); }
static void pdp_ca_sendpacket(t_pdp_ca *x) { /* adjust offset before sending */ t_pdp *header0 = pdp_packet_header(x->x_packet0); int offset, width, height, xoffset, yoffset, horshift, vershift; if (!header0) return; offset = pdp_type_ca_info(header0)->offset; width = pdp_type_ca_info(header0)->width; height = pdp_type_ca_info(header0)->height; xoffset = offset % width; yoffset = offset / width; horshift = x->x_horshift; vershift = x->x_vershift; horshift %= width; if (horshift < 0) horshift += width; vershift %= height; if (vershift < 0) vershift += height; xoffset = (xoffset + horshift) % width; yoffset = (yoffset + vershift) % height; offset = yoffset * width + xoffset; pdp_type_ca_info(header0)->offset = offset; /* output the packet */ outlet_pdp(x->x_outlet0, x->x_packet0); }
/* init the current packet with random noise */ static void pdp_ca_rand(t_pdp_ca *x){ t_pdp *header = pdp_packet_header(x->x_packet0); short int *data = (short int *) pdp_packet_data(x->x_packet0); int i; int nbshortints = (pdp_type_ca_info(header)->width >> 4) * pdp_type_ca_info(header)->height; for(i=0; i<nbshortints; i++) data[i] = random(); }
static void pdp_ca_copy_rw_if_valid(t_pdp_ca *x, int packet) { t_pdp *header = pdp_packet_header(packet); t_pdp *header1 = pdp_packet_header(x->x_packet1); int grabpacket; int convertedpacket; /* check if header is valid */ if (!header) return; if (PDP_CA != header->type) return; if (PDP_CA_STANDARD != pdp_type_ca_info(header)->encoding) return; /* packet is a ca, register it */ pdp_packet_mark_unused(x->x_packet0); x->x_packet0 = pdp_packet_copy_rw(packet); /* make sure we have the right header */ header = pdp_packet_header(x->x_packet0); /* make sure that the other packet is compatible */ if ((pdp_type_ca_info(header1)->width != pdp_type_ca_info(header)->width) || (pdp_type_ca_info(header1)->height != pdp_type_ca_info(header)->height)) { /* if not, throw away and clone the new one */ pdp_packet_mark_unused(x->x_packet1); x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); } if (-1 == x->x_packet0) pdp_post("warning: packet 0 invalid"); if (-1 == x->x_packet1) pdp_post("warning: packet 1 invalid"); };
static void pdp_frei0r_process_rgba(t_pdp_frei0r *x) { t_pdp *newheader = pdp_packet_header(x->x_packet2); char *newdata = (char *)pdp_packet_data(x->x_packet2); t_pdp *lheader = pdp_packet_header(x->x_packet1); char *ldata = (char *)pdp_packet_data(x->x_packet1); t_pdp *mheader = pdp_packet_header(x->x_packetm1); char *mdata = (char *)pdp_packet_data(x->x_packetm1); t_pdp *rheader = pdp_packet_header(x->x_packetr1); char *rdata = (char *)pdp_packet_data(x->x_packetr1); if ((x->x_width != (t_int)lheader->info.image.width) || (x->x_height != (t_int)lheader->info.image.height)) { post("pdp_frei0r :: resizing plugins"); fr_freeplugins(x); x->x_width = lheader->info.image.width; x->x_height = lheader->info.image.height; x->x_size = x->x_width*x->x_height; //load the plugins fr_loadplugins(x, x->plugindir); } newheader->info.image.encoding = lheader->info.image.encoding; newheader->info.image.width = x->x_width; newheader->info.image.height = x->x_height; memcpy( newdata, ldata, x->x_size*sizeof(uint32_t) ); fr_processframe(x, x->x_plugin, ldata, mdata, rdata, newdata); }
static void pdp_scope_createpacket_yv12(t_pdp_scope *x) { t_pdp *header; unsigned int w = x->x_width; unsigned int h = x->x_height; unsigned int size = w*h; unsigned int totalnbpixels = size + (size >> 1); unsigned int packet_size = totalnbpixels << 1; x->x_packet0 = pdp_packet_new_image_YCrCb(w, h); if(x->x_packet0 == -1){ post("pdp_scope: can't allocate packet"); return; } header = pdp_packet_header(x->x_packet0); memset(pdp_packet_data(x->x_packet0), 0, packet_size); }
static void process_image (t_pdp_ieee1394 *x) { unsigned int w,h; int object,length,pos,i,encoding; t_pdp* header; t_image* image; short int * data; //fputc ('.', stdout); //fflush (stdout); /* create new packet */ w = x->x_width; h = x->x_height; object = pdp_packet_new_image(PDP_IMAGE_YV12, w, h); header = pdp_packet_header(object); image = pdp_packet_image_info(object); if (!header){ post("pdp_v4l: ERROR: can't allocate packet"); return; } data = (short int *) pdp_packet_data(object); /* convert data to pdp packet */ //pdp_llconv(x->decodedbuf, RIF_YVYU_P____U8, data, RIF_YVU__P411_S16, w, h); pdp_llconv(x->decodedbuf, RIF_RGB__P____U8, data, RIF_YVU__P411_S16, w, h); // pdp_packet_pass_if_valid(x->x_outlet0, &object); }
/* tick advance CA one timestep */ static void pdp_ca_bang_thread(t_pdp_ca *x) { int encoding; int packet; int i; int iterations = x->x_iterations; /* invariant: the two packets are allways valid and compatible so a bang is allways possible. this means that in the pdp an invalid packet needs to be converted to a valid one */ if (-1 == x->x_packet0) pdp_post("warning: packet 0 invalid"); if (-1 == x->x_packet1) pdp_post("warning: packet 1 invalid"); if (PDP_CA_MODE_2D == x->x_mode){ for(i=0; i < iterations; i++){ /* process form packet0 -> packet1 */ pdp_ca_process_ca_2D(x); /* swap */ pdp_ca_swappackets(x); } } else if (PDP_CA_MODE_1D == x->x_mode){ if (x->x_fullscreen1d){ t_pdp *header0 = pdp_packet_header(x->x_packet0); pdp_type_ca_info(header0)->currow = 0; pdp_type_ca_info(header0)->offset = 0; iterations = pdp_type_ca_info(header0)->height; } for(i=0; i < iterations; i++){ pdp_ca_process_ca_1D(x); } } }
static void pdp_dc1394_bang(t_pdp_dc1394 *x) { /* if initialized, grab a frame and output it */ unsigned int w,h,nbpixels,packet_size,plane1,plane2; unsigned char *newimage=NULL; int pdp_packt,length,pos,i,encoding; t_pdp* header; t_image* image; unsigned char * data; static short int gain[4] = {0x7fff, 0x7fff, 0x7fff, 0x7fff}; /*----------------------------------------------------------------------- * capture one frame *-----------------------------------------------------------------------*/ //x->err=dc1394_capture_dequeue(x->camera, DC1394_CAPTURE_POLICY_WAIT, &x->frame); //DC1394_ERR_CLN_RTN(x->err,cleanup_and_exit(x->camera),"Could not capture a frame"); //post("Could not capture a frame"); if (x->err=dc1394_capture_dequeue(x->camera, DC1394_CAPTURE_POLICY_WAIT, &x->frame)!=DC1394_SUCCESS) { post("Failed to capture from camera %d", x->err); return; } /* create new packet */ dc1394_get_image_size_from_video_mode(x->camera, x->video_mode, &x->width, &x->height); pdp_packt = pdp_packet_new_bitmap_rgb(x->width, x->height); header = pdp_packet_header(pdp_packt); //image = pdp_packet_image_info(pdp_packt); if (!header){ post("pdp_dc1394: ERROR: can't allocate packet"); return; } data = ( unsigned char *) pdp_packet_data(pdp_packt); int j; for (i=0; i<x->width; i++) for (j=0; j<x->height; j++) { data[(j*x->width+i)*3] = x->frame->image[j*x->width+i]; data[(j*x->width+i)*3+1] = x->frame->image[j*x->width+i]; data[(j*x->width+i)*3+2] = x->frame->image[j*x->width+i]; } //memcpy( data, x->frame->image, x->width*x->height*sizeof( unsigned char) ); /*FILE* imagefile=fopen(IMAGE_FILE_NAME, "wb"); if( imagefile == NULL) { perror( "Can't create '" IMAGE_FILE_NAME "'"); cleanup_and_exit(x->camera); } fprintf(imagefile,"P5\n%u %u 255\n", x->width, x->height); fwrite(x->frame->image, 1, x->height*x->width, imagefile); fclose(imagefile); fprintf(stderr,"wrote: " IMAGE_FILE_NAME "\n");*/ if (x->frame) dc1394_capture_enqueue (x->camera, x->frame); pdp_packet_pass_if_valid(x->x_outlet0, &pdp_packt); }
/* 2D: process from packet0 -> packet1 */ static void pdp_ca_process_ca_2D(t_pdp_ca *x) { t_pdp *header0 = pdp_packet_header(x->x_packet0); t_pdp *header1 = pdp_packet_header(x->x_packet1); uint32_t *data0 = (uint32_t *)pdp_packet_data (x->x_packet0); uint32_t *data1 = (uint32_t *)pdp_packet_data (x->x_packet1); int width = pdp_type_ca_info(header0)->width; int height = pdp_type_ca_info(header0)->height; int i,j; /* load TOS in middle of buffer to limit the effect of stack errors */ uint32_t *tos = &x->x_data->stack[2*(PDP_CA_STACKSIZE/2)]; uint32_t *env = &x->x_data->env[0]; uint32_t *reg = &x->x_data->reg[0]; void *ca_routine = x->x_ca_routine; uint32_t rtos; int offset = pdp_type_ca_info(header0)->offset; int xoffset = offset % width; int yoffset = offset / width; /* double word width: number of uint32_ts per row */ int dwwidth = width >> 5; unsigned long long result = 0; /* exit if there isn't a valid routine */ if(!ca_routine) return; if(!header0) return; if(!header1) return; //post("pdp_ca: PRE offset: %d, xoffset: %d, yoffset: %d", offset, xoffset, yoffset); /* calculate new offset: lines shift up, rows shift left by 16 cells */ xoffset = (xoffset + width - 16) % width; yoffset = (yoffset + height - 1) % height; offset = yoffset * width + xoffset; //post("pdp_ca: PST offset: %d, xoffset: %d, yoffset: %d", offset, xoffset, yoffset); pdp_type_ca_info(header1)->offset = offset; for(j=0; j<dwwidth*(height - 2); j+=(dwwidth<<1)){ for(i=0; i < (dwwidth-1) ; i+=1){ env[0] = data0[i + j]; env[1] = data0[i + j + 1]; env[2] = data0[i + j + dwwidth]; env[3] = data0[i + j + dwwidth + 1]; env[4] = data0[i + j + (dwwidth<<1)]; env[5] = data0[i + j + (dwwidth<<1) + 1]; env[6] = data0[i + j + (dwwidth<<1) + dwwidth]; env[7] = data0[i + j + (dwwidth<<1) + dwwidth + 1]; result = scaf_feeder(tos, reg, ca_routine, env); data1[i + j] = result & 0xffffffff; data1[i + j + dwwidth] = result >> 32; } // i == dwwidth-1 env[0] = data0[i + j]; env[1] = data0[j]; env[2] = data0[i + j + dwwidth]; env[3] = data0[j + dwwidth]; env[4] = data0[i + j + (dwwidth<<1)]; env[5] = data0[j + (dwwidth<<1)]; env[6] = data0[i + j + (dwwidth<<1) + dwwidth]; env[7] = data0[j + (dwwidth<<1) + dwwidth]; result = scaf_feeder(tos, reg, ca_routine, env); data1[i + j] = result & 0xffffffff; data1[i + j + dwwidth] = result >> 32; } // j == dwwidth*(height - 2) for(i=0; i < (dwwidth-1) ; i+=1){ env[0] = data0[i + j]; env[1] = data0[i + j + 1]; env[2] = data0[i + j + dwwidth]; env[3] = data0[i + j + dwwidth + 1]; env[4] = data0[i]; env[5] = data0[i + 1]; env[6] = data0[i + dwwidth]; env[7] = data0[i + dwwidth + 1]; result = scaf_feeder(tos, reg, ca_routine, env); data1[i + j] = result & 0xffffffff; data1[i + j + dwwidth] = result >> 32; } // j == dwwidth*(height - 2) // i == dwwidth-1 env[0] = data0[i + j]; env[1] = data0[j]; env[2] = data0[i + j + dwwidth]; env[3] = data0[j + dwwidth]; env[4] = data0[i]; env[5] = data0[0]; env[6] = data0[i + dwwidth]; env[7] = data0[dwwidth]; result = scaf_feeder(tos, reg, ca_routine, env); data1[i + j] = result & 0xffffffff; data1[i + j + dwwidth] = result >> 32; check_stack(x, tos, env); return; }
/* 1D: process from packet0 -> packet0 */ static void pdp_ca_process_ca_1D(t_pdp_ca *x) { t_pdp *header = pdp_packet_header(x->x_packet0); uint32_t *data = (uint32_t *)pdp_packet_data (x->x_packet0); int width = pdp_type_ca_info(header)->width; int height = pdp_type_ca_info(header)->height; int i; uint32_t saved; /* load TOS in middle of buffer to limit the effect of stack errors */ uint32_t *tos = &x->x_data->stack[2*(PDP_CA_STACKSIZE/2)]; uint32_t *env = &x->x_data->env[0]; uint32_t *reg = &x->x_data->reg[0]; void *ca_routine = x->x_ca_routine; uint32_t rtos; /* double word width: number of uint32_ts per row */ int dwwidth = width >> 5; int currow = pdp_type_ca_info(header)->currow; unsigned long long result = 0; unsigned short temp; unsigned short *usdata; /* set destination row to 4th row from top (ca time horizon is 3 deep) */ int dwrow0 = (((currow + height - 3) % height) * width) >> 5; int dwrow1 = (((currow + height - 2) % height) * width) >> 5; int dwrow2 = (((currow + height - 1) % height) * width) >> 5; int dwrow3 = (currow * width) >> 5; /* exit if there isn't a valid routine */ if(!ca_routine) return; /* compute new row */ for(i=0; i < (dwwidth-1) ; i+=1){ env[0] = data[dwrow0 + i]; env[1] = data[dwrow0 + i + 1]; env[2] = data[dwrow1 + i]; env[3] = data[dwrow1 + i + 1]; env[4] = data[dwrow2 + i]; env[5] = data[dwrow2 + i + 1]; result = scaf_feeder(tos, reg, ca_routine, env); data[dwrow3 + i] = result & 0xffffffff; } // i == dwwidth-1 /* compute last column in row */ env[0] = data[dwrow0 + i]; env[1] = data[dwrow0]; env[2] = data[dwrow1 + i]; env[3] = data[dwrow1]; env[4] = data[dwrow2 + i]; env[5] = data[dwrow2]; result = scaf_feeder(tos, reg, ca_routine, env); data[dwrow3 + i] = result & 0xffffffff; /* undo the shift */ usdata = (unsigned short *)(&data[dwrow3]); temp = usdata[(dwwidth*2)-1]; for (i = (dwwidth*2 - 1); i > 0; i--){ usdata[i] = usdata[i-1]; } usdata[0] = temp; check_stack(x, tos, env); /* save current row */ pdp_type_ca_info(header)->currow = (currow + 1) % height; }