Commit 2855ca34 authored by tigital's avatar tigital
Browse files

moved from tv_* to pix_*


git-svn-id: https://pd-gem.svn.sourceforge.net/svnroot/pd-gem/trunk/Gem@152 49b2a0ca-c541-4d49-a7ef-d785e4371512
parent 41187b15
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// zmoelnig@iem.kug.ac.at
//
// Implementation file
//
// Copyright (c) 1997-1998 Mark Danks.
// Copyright (c) Gnther Geiger.
// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::fr::umlute. IEM
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
//
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// pix_biquad
//
// IOhannes m zmoelnig
// mailto:zmoelnig@iem.kug.ac.at
//
// this code is published under the Gnu GeneralPublicLicense that should be distributed with gem & pd
//
/////////////////////////////////////////////////////////
#include "pix_biquad.h"
#include <string.h>
#include <math.h>
CPPEXTERN_NEW(pix_biquad)
/////////////////////////////////////////////////////////
//
// pix_biquad
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
pix_biquad :: pix_biquad()
{
imageStruct image;
image.xsize = image.ysize = 64;
image.format = GL_RGBA;
image.csize = 4;
create_buffer(image);
fb0=fb1=fb2=ff1=ff2=ff3 = 0;
set = false;
}
/////////////////////////////////////////////////////////
// Destructor
//
/////////////////////////////////////////////////////////
pix_biquad :: ~pix_biquad()
{
// clean my buffer
delete_buffer();
}
/////////////////////////////////////////////////////////
// CreateBuffer
//
/////////////////////////////////////////////////////////
void pix_biquad :: create_buffer(imageStruct image)
{
long dataSize;
prev.xsize = image.xsize;
prev.ysize = image.ysize;
prev.csize = image.csize;
last.xsize = image.xsize;
last.ysize = image.ysize;
last.csize = image.csize;
dataSize = prev.xsize * prev.ysize * prev.csize * sizeof(unsigned char);
prev.data = new unsigned char[dataSize];
memset(prev.data, 0, dataSize);
last.data = new unsigned char[dataSize];
memset(last.data, 0, dataSize);
}
/////////////////////////////////////////////////////////
// DeleteBuffer
//
/////////////////////////////////////////////////////////
void pix_biquad :: delete_buffer()
{
delete [] prev.data;
delete [] last.data;
prev.data = NULL;
last.data = NULL;
}
/////////////////////////////////////////////////////////
// ClearBuffer
//
/////////////////////////////////////////////////////////
void pix_biquad :: clear_buffer()
{
memset(last.data, 0, last.xsize * last.ysize * last.csize * sizeof(unsigned char));
memset(prev.data, 0, prev.xsize * prev.ysize * prev.csize * sizeof(unsigned char));
}
/////////////////////////////////////////////////////////
// processImage
//
/////////////////////////////////////////////////////////
void pix_biquad :: processImage(imageStruct &image)
{
// assume that the pix_size does not change !
if (prev.xsize != image.xsize || prev.ysize != image.ysize) {
long dataSize;
delete [] prev.data;
delete [] last.data;
prev.xsize = image.xsize;
prev.ysize = image.ysize;
prev.csize = image.csize;
last.xsize = image.xsize;
last.ysize = image.ysize;
last.csize = image.csize;
dataSize = prev.xsize * prev.ysize * prev.csize * sizeof(unsigned char);
prev.data = new unsigned char[dataSize];
memset(prev.data, 0, dataSize);
last.data = new unsigned char[dataSize];
memset(last.data, 0, dataSize);
}
if (set) {
memcpy(prev.data, image.data, image.ysize * image.xsize * image.csize);
memcpy(last.data, image.data, image.ysize * image.xsize * image.csize);
set = false;
}
int pixsize = image.ysize * image.xsize * image.csize;
unsigned char *this_p = image.data;
unsigned char *last_p= last.data;
unsigned char *prev_p= prev.data;
while(pixsize--) {
float output;
output = fb0 * *this_p + fb1 * *last_p + fb2 * *prev_p;
*this_p++ = (unsigned char)(ff1 * output + ff2 * *last_p + ff3 * *prev_p);
*prev_p++ = *last_p;
*last_p++ = (unsigned char)output;
}
}
/////////////////////////////////////////////////////////
// static member function
//
/////////////////////////////////////////////////////////
void pix_biquad :: obj_setupCallback(t_class *classPtr)
{
//class_addcreator((t_newmethod)_classtv_biquad, gensym("pix_biquad"), A_NULL);
class_addmethod(classPtr, (t_method)&pix_biquad::setMessCallback,
gensym("set"), A_NULL);
class_addlist(classPtr, (t_method)&pix_biquad::faktorMessCallback);
}
void pix_biquad :: faktorMessCallback(void *data, t_symbol *s, int argc, t_atom* argv)
{
if (argc<5 || argc>6){
GetMyClass(data)->fb0=GetMyClass(data)->fb1=GetMyClass(data)->fb2=0;
GetMyClass(data)->ff1=GetMyClass(data)->ff2=GetMyClass(data)->ff3 = 0;
error("pix_biquad: illegal number of arguments");
return;
}
if (argc==6)GetMyClass(data)->fb0=atom_getfloat(argv++);
else GetMyClass(data)->fb0=1;
GetMyClass(data)->fb1=atom_getfloat(argv++);
GetMyClass(data)->fb2=atom_getfloat(argv++);
GetMyClass(data)->ff1=atom_getfloat(argv++);
GetMyClass(data)->ff2=atom_getfloat(argv++);
GetMyClass(data)->ff3=atom_getfloat(argv++);
}
void pix_biquad :: setMessCallback(void *data)
{
GetMyClass(data)->set = true;
}
/*-----------------------------------------------------------------
LOG
GEM - Graphics Environment for Multimedia
apply a 2p2z-filter on a sequence of pixBlocks
Copyright (c) 1997-1999 Mark Danks. mark@danks.org
Copyright (c) Gnther Geiger. geiger@epy.co.at
Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::fr::umlute. IEM. zmoelnig@iem.kug.ac.at
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-----------------------------------------------------------------*/
/*-----------------------------------------------------------------
tv_biquad
IOhannes m zmoelnig
mailto:zmoelnig@iem.kug.ac.at
this code is published under the Gnu GeneralPublicLicense that should be distributed with gem & pd
-----------------------------------------------------------------*/
#ifndef INCLUDE_PIX_BIQUAD_H_
#define INCLUDE_PIX_BIQUAD_H_
#include "Base/GemPixObj.h"
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
pix_biquad
KEYWORDS
pix
DESCRIPTION
-----------------------------------------------------------------*/
class GEM_EXTERN pix_biquad : public GemPixObj
{
CPPEXTERN_HEADER(pix_biquad, GemPixObj)
public:
//////////
// Constructor
pix_biquad();
protected:
//////////
// Destructor
virtual ~pix_biquad();
//////////
// create a buffer that fits to the current imageSize
virtual void create_buffer(imageStruct image);
//////////
// delete the buffer
virtual void delete_buffer();
//////////
// clear the buffer
virtual void clear_buffer();
//////////
// Do the processing
virtual void processImage(imageStruct &image);
//////////
// set-flag
bool set;
//////////
// the image-latches
imageStruct prev;
imageStruct last;
//////////
// the biquad-factors
t_float ff1, ff2, ff3, fb1, fb2, fb0;
//////////
// the methods
static void setMessCallback(void *data);
static void faktorMessCallback(void *data, t_symbol *s, int argc, t_atom* argv);
};
#endif // for header file
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// zmoelnig@iem.kug.ac.at
//
// Implementation file
//
// Copyleft (l) 2002 IOhannes m zmlnig
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
//
/////////////////////////////////////////////////////////
#include "pix_delay.h"
#include <string.h>
CPPEXTERN_NEW_WITH_ONE_ARG(pix_delay, t_float,A_DEFFLOAT)
/////////////////////////////////////////////////////////
//
// pix_delay
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
pix_delay :: pix_delay(t_float &f)
{
m_maxframes=(f>0)?(int)f:DEFAULT_MAX_FRAMES;
myImage.xsize=myImage.ysize=myImage.csize=1;
#ifdef IMAGE_CLASS
myImage.allocate(1*m_maxframes);
#else
myImage.data = new unsigned char[1*m_maxframes];
#endif
m_curframe = m_frame = 0;
inlet_new(this->x_obj, &this->x_obj->ob_pd, &s_float, gensym("delay"));
}
/////////////////////////////////////////////////////////
// Destructor
//
/////////////////////////////////////////////////////////
pix_delay :: ~pix_delay()
{
#ifdef IMAGE_CLASS
myImage.clear();
#else
delete [] myImage.data;
myImage.data = NULL;
#endif
}
/////////////////////////////////////////////////////////
// sizeMess
//
/////////////////////////////////////////////////////////
void pix_delay :: delayMess(int frame)
{
if (frame>=0)m_frame=(frame<m_maxframes)?frame:m_maxframes;
}
/////////////////////////////////////////////////////////
// processImage
//
/////////////////////////////////////////////////////////
void pix_delay :: processImage(imageStruct &image)
{
unsigned char *src = image.data;
unsigned char *dest;
unsigned int dataSize = image.xsize * image.ysize * image.csize;
int readframe;
if (myImage.xsize*myImage.ysize*myImage.csize != image.xsize*image.ysize*image.csize){
#ifdef IMAGE_CLASS
myImage.clear();
myImage.allocate(dataSize*m_maxframes);
#else
delete [] myImage.data;
myImage.data = new unsigned char[m_maxframes * dataSize];
#endif
m_curframe=0;
}
myImage.xsize = image.xsize;
myImage.ysize = image.ysize;
myImage.csize = image.csize;
myImage.type = image.type;
dest = myImage.data+m_curframe*dataSize;
readframe=m_curframe-m_frame;
readframe+=m_maxframes;
readframe%=m_maxframes;
// copy the data to the buffer
//while(dataSize--)*src++=*dest++;
memcpy(dest, src, dataSize);
m_curframe++;
m_curframe%=m_maxframes;
image.data=myImage.data+readframe*dataSize;
}
/////////////////////////////////////////////////////////
// static member function
//
/////////////////////////////////////////////////////////
void pix_delay :: obj_setupCallback(t_class *classPtr)
{
class_addmethod(classPtr, (t_method)&pix_delay::delayMessCallback,
gensym("delay"), A_FLOAT, A_NULL);
}
void pix_delay :: delayMessCallback(void *data, t_floatarg frames)
{
GetMyClass(data)->delayMess((int)frames);
}
/*-----------------------------------------------------------------
LOG
GEM - Graphics Environment for Multimedia
Copyright (c) 1997-1999 Mark Danks. mark@danks.org
Copyleft (l) 2001 IOhannes m zmlnig. zmoelnig@iem.kug.ac.at
Copyleft (l) 2002 James Tittle & Chris Clepper
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-----------------------------------------------------------------*/
#ifndef INCLUDE_PIX_DELAY_H_
#define INCLUDE_PIX_DELAY_H_
#include "Base/GemPixObj.h"
#define DEFAULT_MAX_FRAMES 256
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
pix_delay
change the pixBuf into dots
KEYWORDS
pix
DESCRIPTION
-----------------------------------------------------------------*/
class GEM_EXTERN pix_delay : public GemPixObj
{
CPPEXTERN_HEADER(pix_delay, GemPixObj)
public:
//////////
// Constructor
pix_delay(t_float &f);
protected:
//////////
// Destructor
virtual ~pix_delay();
//////////
// Do the processing
virtual void processImage(imageStruct &image);
imageStruct myImage;
virtual void delayMess(int frames);
int m_maxframes, m_curframe;
int m_frame;
private:
//////////
// static member functions
static void delayMessCallback(void *data, t_floatarg);
};
#endif // for header file
////////////////////////////////////////////////////////
//
// GEM - Graphics Environment for Multimedia
//
// zmoelnig@iem.kug.ac.at
//
// Implementation file
//
// Copyright (c) 1997-1998 Mark Danks.
// Copyright (c) Gnther Geiger.
// Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::fr::umlute. IEM
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
//
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
//
// pix_movement
//
//
/////////////////////////////////////////////////////////
#include "pix_movement.h"
#include <string.h>
#include <math.h>
CPPEXTERN_NEW(pix_movement)
/////////////////////////////////////////////////////////
//
// pix_movement
//
/////////////////////////////////////////////////////////
// Constructor
//
/////////////////////////////////////////////////////////
pix_movement :: pix_movement()
{
imageStruct image;
image.xsize = image.ysize = 64;
image.format = GL_RGBA;
image.csize = 4;
create_buffer(image);
bufcount = 0;
treshold = 127;
}
/////////////////////////////////////////////////////////
// Destructor
//
/////////////////////////////////////////////////////////
pix_movement :: ~pix_movement()
{
// clean my buffer
delete_buffer();
}
/////////////////////////////////////////////////////////
// CreateBuffer
//
/////////////////////////////////////////////////////////
void pix_movement :: create_buffer(imageStruct image)
{
long dataSize;
buffer.xsize = image.xsize;
buffer.ysize = image.ysize;
buffer.csize = 1;
dataSize = buffer.xsize * buffer.ysize * buffer.csize * sizeof(unsigned char);
buffer.data = new unsigned char[dataSize];
memset(buffer.data, 0, dataSize);
}
/////////////////////////////////////////////////////////
// DeleteBuffer
//
/////////////////////////////////////////////////////////
void pix_movement :: delete_buffer()
{
delete [] buffer.data;
buffer.data = NULL;
}
/////////////////////////////////////////////////////////
// ClearBuffer
//
/////////////////////////////////////////////////////////
void pix_movement :: clear_buffer()
{
memset(buffer.data, 0, buffer.xsize * buffer.ysize * buffer.csize * sizeof(unsigned char));
}
/////////////////////////////////////////////////////////
// processImage
//
/////////////////////////////////////////////////////////
void pix_movement :: processImage(imageStruct &image)
{
// assume that the pix_size does not change !
if (image.xsize != buffer.xsize || image.ysize != buffer.ysize) {
long dataSize;
delete [] buffer.data;
buffer.xsize = image.xsize;
buffer.ysize = image.ysize;
// buffer.csize = image.csize;
dataSize = buffer.xsize * buffer.ysize * buffer.csize * sizeof(unsigned char);
buffer.data = new unsigned char[dataSize];
memset(buffer.data, 0, dataSize);
}
int pixsize = image.ysize * image.xsize;
unsigned char *rp = image.data; // read pointer
unsigned char *wp=buffer.data; // write pointer
while(pixsize--) {
unsigned char grey = (unsigned char)(rp[chRed] * 0.3086f + rp[chGreen] * 0.6094f + rp[chBlue] * 0.0820f);
rp[chAlpha] = 255*(fabs((unsigned char)grey-*wp)>treshold);
*wp++=(unsigned char)grey;
rp+=4;
}
}
/////////////////////////////////////////////////////////
// static member function
//
/////////////////////////////////////////////////////////
void pix_movement :: obj_setupCallback(t_class *classPtr)
{
//class_addcreator((t_newmethod)_classtv_movement, gensym("pix_movement"), A_NULL);