Ejemplo n.º 1
0
void smImage::threshold(float _T)
{
    
    float T = (_T*255)/getWindowWidth();
    
    
    for( int x = 0; x< width; x++)
    {
        for(int y = 0; y<height; y++)
        {
            float grayValue = getPixel(x,y);
            
         
            
            if(grayValue > T){
                
                grayValue = 255;
            }
            else{
                grayValue = 0;
                
            }
            
            grayValue = grayValue / 255;                // convert from 0-255 to 0.0-1.0
            po::setColor( poColor( grayValue, grayValue, grayValue) );  // set the color
            po::drawFilledRect( x*5,y*5, 5, 5 );        // draw the "pixel" rectangle
            
        }
    }
    
   }
Ejemplo n.º 2
0
void smImage::blackandwhite()
{
    
    for( int x = 0; x< width; x++)
    {
        for(int y = 0; y<height; y++)
        {
            
            float grayValue = getPixel(x,y);
            
            if(grayValue > 255/2){
                grayValue = 255;
            }
            else
            {
                grayValue = 0;
            }
            grayValue = grayValue / 255;                // convert from 0-255 to 0.0-1.0
            po::setColor( poColor( grayValue, grayValue, grayValue) );  // set the color
            po::drawFilledRect( x*5,y*5, 5, 5 );        // draw the "pixel" rectangle
            
        }
    }

    
    
}
Ejemplo n.º 3
0
poColor poImage::getPixel(poPoint p) const {
        
	if(!isValid() || p.x < 0 || p.y < 0 || p.x >= getWidth() || p.y >=getHeight())
		return poColor();

	uint x = p.x;
	uint y = p.y;
	
	BYTE* bits = FreeImage_GetScanLine(bitmap, y);
	poColor ret;
	
	switch(getChannels()) {
		case 1:
			ret.set255(bits[x], bits[x], bits[x], 255);
			break;
		case 2:
			ret.set255(bits[x*2], bits[x*2], bits[x*2], bits[x*2+1]);
			break;
		case 3:
			ret.set255(bits[x*3+0], bits[x*3+1], bits[x*3+2], 255);
			break;
		case 4:
			ret.set255(bits[x*4+0], bits[x*4+1], bits[x*4+2], bits[x*4+3]);
			break;
		default:
			;
	}
	
	return ret;
}
Ejemplo n.º 4
0
// APP CONSTRUCTOR. Create all objects here.
MovingImageApp::MovingImageApp() {
	addModifier(new poCamera2D(poColor(.9,.9,.9)));
	
	sprite = new MovingImage("sprites/shifty/", "PT_Shifty");
	sprite->setFrameRate(30);
	sprite->position.set(100,100,0);
	addChild(sprite);
	
	control = new poControlPanel("controls", poColor( 0,.1,.1,.8 ), 9);
	control->addSliderI("framerate", 1, 60, this);
	control->addButton("play", this);
	control->addButton("pause", this);
	control->addButton("reset", this);
	control->addButton("stop", this);
	control->addButton("step forward", this);
	control->addButton("step backward", this);
	control->addToggle("loop", this);
	control->addSliderI("goto frame", 0, sprite->getNumFrames()-1, this);
	
	addChild(control);
	
	addEvent(PO_KEY_DOWN_EVENT, this);
}
Ejemplo n.º 5
0
void    smImage::draw()
{
    // this is an inefficent, but simple mode of drawing an image
    // we draw one rectangle for every pixel
    // use the fastDraw() method if you want something faster
    for( int x=0; x<width; x++ )
    {
        for( int y=0; y<height; y++ )
        {
            float grayValue = getPixel(x,y);            // get the gray value
            grayValue = grayValue / 255;                // convert from 0-255 to 0.0-1.0
            po::setColor( poColor( grayValue, grayValue, grayValue) );  // set the color
            po::drawFilledRect( x*5,y*5, 5, 5 );        // draw the "pixel" rectangle
        }
    }
}
Ejemplo n.º 6
0
void smImage::edgeDetect(float _T)

{
    
    float T = (_T*255)/getWindowWidth();
   
    
    for( int x = 0; x< width; x++)
    {
        for(int y = 0; y<height; y++)
        {
             int index = x +y*width;
            int nextIndex = index+1;
        
            if(nextIndex == width*height){
                
                nextIndex = 0;
                
            }

           
            
            float grayValue = getPixel(x,y);
            
            if(abs(imageData[index]-imageData[nextIndex]) > T)
            {
                
                grayValue = 0;
                
            }
            else{
                grayValue = 255;
            }
               
         
            grayValue = grayValue / 255;                // convert from 0-255 to 0.0-1.0
            po::setColor( poColor( grayValue, grayValue, grayValue) );  // set the color
            po::drawFilledRect( x*5,y*5, 5, 5 );        // draw the "pixel" rectangle
            
            
        }
    }

    
    
}
Ejemplo n.º 7
0
void po::setColor(poColor color, float alpha) {
    poOpenGLState::get()->color = poColor(color, alpha);
}