Esempio n. 1
0
// We can invert the image by subtracting each R,G,B value from 255
void invertArea( Surface *surface, Area area )
{
    Surface::Iter iter = surface->getIter( area );
    while( iter.line() ) {
        while( iter.pixel() ) {
            iter.r() = 255 - iter.r();
            iter.g() = 255 - iter.g();
            iter.b() = 255 - iter.b();
        }
    }
}
Esempio n. 2
0
void BuddhabrotApp::update()
{
	runBrot();
	
	Surface::Iter iter = mSurface.getIter();
	
	int x = 0;
	int y = 0;
	int index;
	
	while( iter.line() ) {
		y = iter.y();
		
		while( iter.pixel() ) {
			x = iter.x();
			index = y * TEXTURE_WIDTH + x;
			
			double r = 0;
			double g = 0;
			double b = 0;
			
			int rMax = mVMaxR;
			while( rMax > 0 && mRedHistory[ rMax ] <= 4 ){
				rMax --;
			}
			
			int gMax = mVMaxG;
			while( gMax > 0 && mGreenHistory[ gMax ] <= 4 ){
				gMax --;
			}
			
			int bMax = mVMaxB;
			while( bMax > 0 && mBlueHistory[ bMax ] <= 4 ){
				bMax --;
			}
			
			if( rMax > 0 ){
				r = (double)mRedBuffer[index]/(double)rMax;
				if( r > 1 ) r = 1;
			}
			
			if( gMax > 0 ){
				g = (double)mGreenBuffer[index]/(double)gMax;
				if( g > 1 ) g = 1;
			}
			
			if( bMax > 0 ){
				b = (double)mBlueBuffer[index]/(double)bMax;
				if( b > 1 ) b = 1;
			}
			
			iter.r() = (int)( r * 255 );
			iter.g() = (int)( g * 255 );
			iter.b() = (int)( b * 255 );
		}
	}
	mTexture = gl::Texture( mSurface );
}
Esempio n. 3
0
void _repeat(Surface& source, Surface& dest, int scaleFactor)
{
    Surface::ConstIter srcIt = source.getIter();
    Surface::Iter destIt = dest.getIter();
    while (srcIt.line())
    {
        // back to the start of source line
        Surface::ConstIter copy = srcIt;
        for (int i = 0; i < scaleFactor; i++)
        {
            destIt.line();
            while (srcIt.pixel())
            {
                for (int j = 0; j < scaleFactor; j++)
                {
                    destIt.pixel();
                    destIt.r() = srcIt.r();
                    destIt.g() = srcIt.g();
                    destIt.b() = srcIt.b();
                }
            }
            // reset srcIt
            srcIt = copy;
        }
    }
}
Esempio n. 4
0
void Video::update()
{
    if( mMovie.checkPlayable() ){
        Area area = mMovie.getSurface().getBounds();
        mFrameSurface = ci::Surface(area.getWidth(), area.getHeight(), true);
		mFrameSurface.copyFrom(mMovie.getSurface(), mFrameSurface.getBounds() );
        
        /*
        mFrameSurface = ci::Surface(mMovie.getSurface());
        mFrameTexture = gl::Texture(mFrameSurface, mFrameFormat);
        */
        
        Surface::Iter iter = mFrameSurface.getIter( mFrameSurface.getBounds() );

        while( iter.line() ) {
            while( iter.pixel() ) {
                //if (iter.b() > 50 && iter.r() < 50 && iter.g() < 50){
                if (iter.g() > 50 && iter.g() > iter.r() && iter.g() > iter.b()){
                    //std::cout << "yes" << std::endl;
                    //iter.r() = 0;
                    //iter.g() = 0;
                    //iter.b() = 0;
                    iter.a() = 0;
                }
                else{
                    iter.a() = 255;
                    //std::cout << "no" << std::endl;
                }
            }
        }
        //mFrameSurface = ci::Surface( loadImage( loadResource( "bomb.png")) );
        mFrameTexture = gl::Texture(mFrameSurface, mFrameFormat);
         
    }
    //mCenteredRect = Rectf( mFrameTexture.getBounds() ).getCenteredFit( getWindowBounds(), true );
    mCenteredRect = Rectf(-40,0,800,600);
    
   
     
}
Esempio n. 5
0
/**
 * Apply Rainbow-Crush Distortion
 * @param intensity a double-precision number between 0 and 1
 */
void distortion::applyRainbowCrush(const double intensity) {
  
  Surface::Iter iter = mSurface.getIter();
  
  // int a = time(0);
  int t = 0;
  
  while (iter.line()) {
    while (iter.pixel()) {
      t++;
      iter.rClamped(0, 0) = iter.gClamped(7, 3);
      iter.gClamped(0, 0) = iter.rClamped(7, 1);
      iter.bClamped(0, 0) = iter.bClamped(7, 2);
      
    }
  }
  app::console() << t << "\n";
}
Esempio n. 6
0
 void PerlinContent::generateNoiseForPosition(const ci::Vec2f & position)
 {
     Surface::Iter iter = mNoiseSurface.getIter();
     while( iter.line() )
     {
         while( iter.pixel() )
         {
             //float v = mPerlin.noise(((iter.x() + position.x) * mFrequency),
                                     //((iter.y() + position.y) * mFrequency));
             //float val = 0.5 + v;
             float val = getValueAtPosition(Vec2f(iter.x() + position.x,
                                                  iter.y() + position.y));
             iter.r() = iter.g() = iter.b() = ci::math<int>::clamp(val * 255, 0, 255);
         }
     }
 }
Esempio n. 7
0
void Item::setColors()
{
	Surface::Iter iter = mPalette.getIter();
	while( iter.line() ) {
		while( iter.pixel() ) {
			int index = iter.x();
			Color col( iter.r()/255.0f, iter.g()/255.0f, iter.b()/255.0f );
			vec2 pos = vec2( index%4, floor(index/4.0f) ) * 5.0f - vec2( 12.0f, 8.0f );
			Rectf rect( -2.0f, -2.0f, 2.0f, 2.0f );
			Swatch swatch( col, mTitleStart + pos + vec2( -10.0f, 10.0f ), rect );
			mSwatches.push_back( swatch );
		}
	}
}
Esempio n. 8
0
File: cApp.cpp Progetto: stdmtb/n9
void cApp::loadColorSample( fs::path filepath, vector<Colorf>& col){
    Surface sur( loadImage( filepath ) );
    Surface::Iter itr = sur.getIter();
    
    while ( itr.line() ) {
        while ( itr.pixel() ) {
            float r = itr.r() / 255.0f;
            float g = itr.g() / 255.0f;
            float b = itr.b() / 255.0f;
            col.push_back( Colorf(r,g,b) );
        }
    }
    cout << "Load Success: " << col.size() << " ColorSample" << endl;
    
}
void ocvColorQuantizeApp::updateImage()
{
    const int colorCount = 32;
    const int sampleCount = mInputImage.getHeight() * mInputImage.getWidth();
    cv::Mat colorSamples( sampleCount, 1, CV_32FC3 );

    // build our matrix of samples
    Surface::ConstIter imageIt = mInputImage.getIter();
    cv::MatIterator_<cv::Vec3f> sampleIt = colorSamples.begin<cv::Vec3f>();
    while( imageIt.line() )
        while( imageIt.pixel() )
            *sampleIt++ = cv::Vec3f( imageIt.r(), imageIt.g(), imageIt.b() );

    // call kmeans
    cv::Mat labels, clusters;
    cv::kmeans( colorSamples, colorCount, labels, cv::TermCriteria( cv::TermCriteria::COUNT, 8, 0 ), 2, cv::KMEANS_RANDOM_CENTERS, &clusters );

    Color8u clusterColors[colorCount];
    for( int i = 0; i < colorCount; ++i )
        clusterColors[i] = Color8u( clusters.at<cv::Vec3f>(i,0)[0], clusters.at<cv::Vec3f>(i,0)[1], clusters.at<cv::Vec3f>(i,0)[2] );

    Surface result( mInputImage.getWidth(), mInputImage.getHeight(), false );
    Surface::Iter resultIt = result.getIter();
    cv::MatIterator_<int> labelIt = labels.begin<int>();
    while( resultIt.line() ) {
        while( resultIt.pixel() ) {
            resultIt.r() = clusterColors[*labelIt].r;
            resultIt.g() = clusterColors[*labelIt].g;
            resultIt.b() = clusterColors[*labelIt].b;
            ++labelIt;
        }
    }

    // draw the color palette across the bottom of the image
    const int swatchSize = 12;
    for( int i = 0; i < colorCount; ++i ) {
        ip::fill( &result, clusterColors[i], Area( i * swatchSize, result.getHeight() - swatchSize, ( i + 1 ) * swatchSize, result.getHeight() ) );
    }

    mTexture = gl::Texture( result );
}
Esempio n. 10
0
void VectorBlur::drawArrowMap()
{
	gl::ScopedColor blue(Color(0, 0, 1));
	Surface pix(fboBlurMap->getColorTexture()->createSource());
	int inc = 8;
	float arrowLength = 5.0f;
	Surface::Iter iter = pix.getIter(fboBlurMap->getBounds());
	while (iter.line()) {
		while (iter.pixel()) {
			ivec2 pos = iter.getPos();
			if (pos.x%inc == 0 && pos.y%inc == 0) {
				vec2 dir(iter.r(), iter.g());
				dir = dir / 255.0f * 2.0f - vec2(1, 1);
				glm::normalize(dir);
				vec2 p0 = pos;
				vec2 p1 = p0 + dir*arrowLength;
				gl::drawLine(p0, p1);
			}
		}
	}
}
Esempio n. 11
0
// We can create a thresholded image by taking the grayscale value of each pixel and assigning the
// result to be black for gray <= 50%, and white for gray > 50%
void thresholdArea( Surface *surface, Area area )
{
    Surface::Iter iter = surface->getIter( area );
    while( iter.line() ) {
        while( iter.pixel() ) {
            // this is not the best way to determine grayscale - see CHANTRAIT<>::grayscale()
            uint8_t gray = ( iter.r() + iter.g() + iter.b() ) / 3;
            if( gray > 128 )
                iter.r() = iter.g() = iter.b() = 255;
            else
                iter.r() = iter.g() = iter.b() = 0;
        }
    }
}
void FrownLogoParticlesApp::setup()
{
    mKeyPressed = false;
    // Lets load a font from the the installed fonts of the OS
    // and set its size to 90

    mFont = Font("Arial",90 );
    
    //Clear the layout to black
    
    mLayout.clear(Color::black() );
    //Set the text color of the layout
    mLayout.setColor(Color(1,1,1));
    
    //Set the font of the layout
    mLayout.setFont(mFont);
    
    //Add the following line to the layout
    mLayout.addLine("FROWN");
    
    //Render the layout into a cinder Surface
    mSurface = mLayout.render();

    //We will now iterate through every pixel in the surface:
    //First get the iterator
    Surface::Iter iter = mSurface.getIter();
    // For every line in the surface
    //
    while ( iter.line() )
    {
        // For every pixel in the line
        while (iter.pixel()) {
            //Check if the color of the current pixel is not black
            if ( ( iter.r() != 0.0f ) && ( iter.g() != 0.0f ) && ( iter.b() != 0.0f ) )
            {
                //If its not black, push the position of the pixel into
                // the initial positions
                mInitialPositions.push_back(ci::Vec2f(iter.x(), iter.y()));
                // Also, lets make the current positions equal to the initial
                // ones
                mCurrentPositions.push_back(ci::Vec2f(iter.x(), iter.y()));
                //lets also keep the color of every pixel
                mPixelColors.push_back(Colorf(iter.r(), iter.g(), iter.b()));
            }
        }
    }
    //Print the size of non-black pixels found in the surface
    console() << "We found " << mInitialPositions.size() <<
    " non black pixels" << endl;
    
    console() << "Spacebar changes: explode /move back" << endl;
    console() << "P or p changes: whether the particles are paused or not" << endl;
}
Esempio n. 13
0
void HodginDidItApp::processDepth()
{
	mPoints.clear();
	Surface::Iter sit = mSurfDepth.getIter(Area(0,0,mDepthW,mDepthH));
	while(sit.line())
	{
		while(sit.pixel())
		{
			float cDepth = (float)mDepthBuffer[sit.y()*mDepthW+sit.x()];
			sit.r() = 0;
			sit.g() = 0;
			sit.b() = 0;
			sit.a() = 0;
			if(cDepth<32000)
			{
				float cScaled = cDepth/1000.0f;
				if(cDepth<300)
				{
					uint8_t v = (uint8_t)lmap<float>(cDepth,0,300,0,255);
					sit.r() = v;
					sit.a() = v;
				}
				if(sit.x()%2==0&&sit.y()%2==0)
					mPoints.push_back(niDepthToWorld(Vec3f(sit.x(),sit.y(),1.0f*cScaled)));

			}
		}
	}
}
void CinderOpenNISkeleton::setDepthSurface() {
	int texWidth =  gCinderOpenNISkeleton->mDepthMD.XRes();
	int texHeight = gCinderOpenNISkeleton->mDepthMD.YRes();
	
	const XnDepthPixel* pDepth = gCinderOpenNISkeleton->mDepthMD.Data();
	const XnLabel* pLabels = gCinderOpenNISkeleton->mSceneMD.Data();
	
	// Calculate the accumulative histogram -  whatever that means
	memset(gCinderOpenNISkeleton->pDepthHist, 0, MAX_DEPTH*sizeof(float));
	
	unsigned int nX = 0;
	unsigned int nValue = 0;
	unsigned int nIndex = 0;
	unsigned int nY = 0;
	unsigned int nNumberOfPoints = 0;
	unsigned int nHistValue = 0;
	
	if(!gCinderOpenNISkeleton->bInitialized)
	{
	
		gCinderOpenNISkeleton->pDepthTexBuf = new unsigned char[texWidth*texHeight*3];
		
		app::console() << "Initialised Buffer" <<endl;
		
		gCinderOpenNISkeleton->bInitialized = true;
		
		gCinderOpenNISkeleton->mDepthSurface = Surface8u( texWidth, texHeight, false ); // width, height, alpha?

	}
	
	
	for (nY=0; nY<texHeight; nY++)
	{
		for (nX=0; nX<texWidth; nX++)
		{
			nValue = *pDepth;
			
			if (nValue != 0)
			{
				gCinderOpenNISkeleton->pDepthHist[nValue]++;
				nNumberOfPoints++;
			}
			
			pDepth++;
		}
	}
	
	for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
	{
		gCinderOpenNISkeleton->pDepthHist[nIndex] += gCinderOpenNISkeleton->pDepthHist[nIndex-1];
	}
	if (nNumberOfPoints)
	{
		for (nIndex=1; nIndex<MAX_DEPTH; nIndex++)
		{
			gCinderOpenNISkeleton->pDepthHist[nIndex] = 
			(unsigned int)(256 * (1.0f - (gCinderOpenNISkeleton->pDepthHist[nIndex] / nNumberOfPoints)));
		}
	}
	
	pDepth = gCinderOpenNISkeleton->mDepthMD.Data();

	Area area( 0, 0, texWidth, texHeight );

	Surface::Iter iter = gCinderOpenNISkeleton->mDepthSurface.getIter( area );
	while( iter.line() ) {
		while( iter.pixel() ) {
			iter.r() = 0;
			iter.g() = 0;
			iter.b() = 0;
			
			if ( *pLabels != 0) // Buh?
			{
				nValue = *pDepth;
				XnLabel label = *pLabels;
				XnUInt32 nColorID = label % nColors;
				if (label == 0)
				{
					nColorID = nColors;
				}
				
				if (nValue != 0)
				{
					nHistValue = gCinderOpenNISkeleton->pDepthHist[nValue];
					
					iter.r() = nHistValue * Colors[nColorID][0]; 
					iter.g() = nHistValue * Colors[nColorID][1];
					iter.b() = nHistValue * Colors[nColorID][2];
				}
				
				//app::console() << "PLABEL with Colour: " << label % nColors << endl;
			}
			else {
				nValue = *pDepth;
				//app::console() << "nValue: " << nValue << endl;
				if (nValue != 0)
				{
					nHistValue = gCinderOpenNISkeleton->pDepthHist[nValue];
					
					//app::console() << "nHistValue: " << nHistValue << endl;
					
					iter.r() = nHistValue; 
					iter.g() = nHistValue;
					iter.b() = nHistValue;
				}
			}
			
			pDepth++;
			pLabels++;
			
		}
	}

	gl::clear( Color( 0, 0, 0 ) );
	gl::draw(gl::Texture(gCinderOpenNISkeleton->mDepthSurface));
}