[GEM-dev] pix_noise
cyrille henry
cyrille.henry at la-kitchen.fr
Sat Sep 15 12:59:41 CEST 2007
hello,
before possible inclusion in Gem, the help patch should be better (have a look at the other gem help patch).
i noticed that changing colorspace is done with "colorspace YUV" while in pix_set this is made with only a "YUV" message
i also think that every noise generator should have a "seed" input in order to be able to have predictible output.
last point : it is very necessary to have a mode where the noise does not change at every frame. i personnaly think it should be defaut. computing a new frame could be made by sending a bang, or by sending a new seed by exemple.
just my 2 cents
Cyrille
Thomas Holzmann a écrit :
> Hello!
>
> Georg Holzmann schrieb:
>> chris clepper schrieb:
>>
>>> Is this a random noise or Perlin noise object?
>>
>> Only random noise ATM.
>>
>>
>>
> Here is my (very simple) random noise object for gem.
> Cris, if you think its useful you could add it to the main branch.
>
>
> Thomas
>
>
> ------------------------------------------------------------------------
>
> #N canvas 42 78 561 477 10;
> #X obj 30 -36 cnv 15 100 60 empty empty empty 20 12 0 14 -195568 -66577
> 0;
> #N canvas 0 0 450 300 gemwin 0;
> #X obj 132 136 gemwin;
> #X obj 67 89 outlet;
> #X obj 67 10 inlet;
> #X msg 67 70 set destroy;
> #X msg 132 112 create \, 1;
> #X msg 198 112 destroy;
> #X msg 156 71 set create;
> #X obj 67 41 route create;
> #X connect 2 0 7 0;
> #X connect 3 0 1 0;
> #X connect 4 0 0 0;
> #X connect 5 0 0 0;
> #X connect 6 0 1 0;
> #X connect 7 0 3 0;
> #X connect 7 0 4 0;
> #X connect 7 1 6 0;
> #X connect 7 1 5 0;
> #X restore 35 3 pd gemwin;
> #X msg 35 -16 destroy;
> #X text 31 -37 Create window:;
> #X obj 193 40 gemhead;
> #X obj 196 225 pix_texture;
> #X obj 196 247 rectangle 4 3;
> #X msg 266 50 dimen 600 400;
> #X msg 283 82 dimen 300 200;
> #X msg 290 114 dimen 60 40;
> #X obj 201 169 pix_noise 40 30;
> #X msg 376 159 colorspace YUV;
> #X msg 378 191 colorspace GRAY;
> #X msg 381 132 colorspace RGBA;
> #X connect 1 0 2 0;
> #X connect 2 0 1 0;
> #X connect 4 0 10 0;
> #X connect 5 0 6 0;
> #X connect 7 0 10 0;
> #X connect 8 0 10 0;
> #X connect 9 0 10 0;
> #X connect 10 0 5 0;
> #X connect 11 0 10 0;
> #X connect 12 0 10 0;
> #X connect 13 0 10 0;
>
>
> ------------------------------------------------------------------------
>
> ////////////////////////////////////////////////////////
> //
> // GEM - Graphics Environment for Multimedia
> //
> // zmoelnig at iem.kug.ac.at
> //
> // Implementation file
> //
> // Copyright (c) 1997-2000 Mark Danks.
> // Copyright (c) G�nther Geiger.
> // Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f�r::uml�ute. IEM
> // Copyright (c) 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.
> //
> /////////////////////////////////////////////////////////
>
> #include "pix_noise.h"
>
> CPPEXTERN_NEW_WITH_TWO_ARGS(pix_noise, t_float, A_DEFFLOAT, t_float, A_DEFFLOAT)
>
> /////////////////////////////////////////////////////////
> //
> // pix_noise
> //
> /////////////////////////////////////////////////////////
> // Constructor
> //
> /////////////////////////////////////////////////////////
> pix_noise :: pix_noise(t_float w, t_float h) : m_reqFormat(GL_YUV422_GEM)
> {
> m_width = (int) w;
> m_height = (int) h;
> createFrame();
> }
>
> /////////////////////////////////////////////////////////
> // Destructor
> //
> /////////////////////////////////////////////////////////
> pix_noise :: ~pix_noise()
> {
> m_pixBlock.image.clear();
> }
>
> /////////////////////////////////////////////////////////
> // createNoise
> //
> /////////////////////////////////////////////////////////
> void pix_noise :: produceNoise()
> {
> unsigned char *data = m_pixBlock.image.data;
> int n = m_width * m_height;
>
> switch(m_pixBlock.image.format){
> case GL_RGBA: default:
> while(n--){
> data[chRed] = rand() % 256;
> data[chGreen] = rand() % 256;
> data[chBlue] = rand() % 256;
> data[chAlpha] = 0;
> data+=4;
> }
> break;
> case GL_YUV422_GEM:
> n/=2;
> while(n--)
> {
> data[chY0] = rand() % 256;
> data[chY1] = rand() % 256;
> data[chU ] = rand() % 256;
> data[chV ] = rand() % 256;
>
> data+=4;
> }
> break;
> case GL_LUMINANCE:
> while(n--){
> *data++ = rand() % 256;
> }
> break;
> }
>
> m_pixBlock.newimage = 1;
> }
>
> void pix_noise :: render(GemState *state)
> {
> produceNoise();
> state->image = &m_pixBlock;
> }
>
> void pix_noise:: postrender(GemState *state)
> {
> m_pixBlock.newimage = 0;
> state->image = NULL;
> }
>
> void pix_noise:: startRendering()
> {
> m_pixBlock.newimage = 1;
> }
>
> void pix_noise::createFrame()
> {
> // check bounds
> m_width = (m_width<=0) ? 8 : m_width;
> m_width = (m_width>10000) ? 400 : m_width;
> m_height = (m_height<=0) ? 8 : m_height;
> m_height = (m_height>10000) ? 300 : m_height;
>
> m_pixBlock.image.xsize = m_width;
> m_pixBlock.image.ysize = m_height;
> m_pixBlock.image.setCsizeByFormat(m_reqFormat);
>
> m_pixsize = m_pixBlock.image.xsize*m_pixBlock.image.ysize;
> m_pixBlock.image.reallocate();
> m_pixBlock.image.setBlack();
> }
>
> void pix_noise::setDimension(int w, int h)
> {
> m_width = w;
> m_height = h;
> createFrame();
> }
>
> void pix_noise::csMess(GLint cs)
> {
> m_reqFormat=cs;
> m_pixBlock.image.setCsizeByFormat(m_reqFormat);
> m_pixsize = m_pixBlock.image.xsize*m_pixBlock.image.ysize;
> m_pixBlock.image.reallocate();
> m_pixBlock.image.setBlack();
> }
>
> /////////////////////////////////////////////////////////
> // static member function
> //
> /////////////////////////////////////////////////////////
>
> void pix_noise :: obj_setupCallback(t_class *classPtr)
> {
> class_addcreator((t_newmethod)_classpix_noise,
> gensym("pix_noise"), A_NULL);
> class_addmethod(classPtr,(t_method)pix_noise::dimenCallback,
> gensym("dimen"), A_DEFFLOAT, A_DEFFLOAT,A_NULL);
> class_addmethod(classPtr, (t_method)&pix_noise::csMessCallback,
> gensym("colorspace"), A_DEFSYMBOL, A_NULL);
> }
>
> void pix_noise::dimenCallback(void *data, float x, float y)
> {
> GetMyClass(data)->setDimension((int)x, (int)y);
> }
>
> void pix_noise ::csMessCallback(void *data, t_symbol *s)
> {
> int cs = getPixFormat(s->s_name);
> if(cs>0)GetMyClass(data)->csMess(cs);
> else GetMyClass(data)->error("pix_noise: colorspace must be Grey, YUV or RGBA");
> }
>
>
> ------------------------------------------------------------------------
>
> /*-----------------------------------------------------------------
> LOG
> GEM - Graphics Environment for Multimedia
>
> Change pix to greyscale
>
> Copyright (c) 1997-1999 Mark Danks. mark at danks.org
> Copyright (c) G�nther Geiger. geiger at epy.co.at
> Copyright (c) 2001-2002 IOhannes m zmoelnig. forum::f�r::uml�ute. IEM. zmoelnig at iem.kug.ac.at
> Copyright (c) 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_NOISE_H_
> #define INCLUDE_PIX_NOISE_H_
>
> const int RGBA_SIZE = 4;
> //const int X_SIZE = 100;
> //const int Y_SIZE = 100;
>
>
> #include "Base/GemBase.h"
> #include "Base/GemPixUtil.h"
>
> /*-----------------------------------------------------------------
> -------------------------------------------------------------------
> CLASS
> pix_noise
>
> Creates noise
>
> KEYWORDS
> pix
>
> DESCRIPTION
>
> -----------------------------------------------------------------*/
> class GEM_EXTERN pix_noise : public GemBase
> {
> CPPEXTERN_HEADER(pix_noise, GemBase)
>
> public:
>
> //////////
> // Constructor
> pix_noise(t_float w, t_float h);
>
> protected:
>
> //////////
> // Destructor
> virtual ~pix_noise();
>
> //////////
> // A frame will be created
> virtual void produceNoise();
>
> //////////
> // Do the rendering
> virtual void render(GemState *state) ;
>
> //////////
> // Clear the dirty flag on the pixBlock
> virtual void postrender(GemState *state) ;
>
> //////////
> virtual void startRendering() ;
>
> /////////
> // allocates Frame
> virtual void createFrame();
>
> //////////
> // setting dimension and colourspace
> virtual void setDimension(int w, int h);
> virtual void csMess(GLint cs);
>
> private:
>
> //////////
> // The pixBlock with the current image
> pixBlock m_pixBlock;
> int m_pixsize;
> int m_width, m_height;
>
> //////////////
> // which colorspace do we want ? currently only GL_RGBA
> GLint m_reqFormat;
>
> private:
>
> //////////
> // static member functions
> static void dimenCallback(void *data, float x, float y);
> static void csMessCallback(void *data, t_symbol*s);
> };
>
> #endif // for header file
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> GEM-dev mailing list
> GEM-dev at iem.at
> http://lists.puredata.info/listinfo/gem-dev
More information about the GEM-dev
mailing list