Exemple #1
0
//--------------------------------------------------------------
void testApp::update(){

  _movie.idleMovie();
  const ofPixelsRef pixels= _movie.getPixelsRef();
  long double reds= 0.0;
  long double blues= 0.0;
  long double greens= 0.0;

  for (int x= 0; x < _movie.width; ++x)
  {
    for (int y= 0; y < _movie.height; ++y)
    {
      reds += pixels.getColor(x, y).r;
      greens += pixels.getColor(x, y).g;
      blues += pixels.getColor(x, y).b;
    }
  }

  // Divide by 10 because ofColor rgb values are in units of 0-1000.
  //
  // Then we multiply by 2.55 to get us on DMX scale and not percentage
  avg_red= int(reds/color_pixels*multiplier)/10*2.55;
  avg_green= int(greens/color_pixels*multiplier)/10*2.55;
  avg_blue= int(blues/color_pixels*multiplier)/10*2.55;

  _dmx.SetChannel(0, avg_red);
  _dmx.SetChannel(1, avg_green);
  _dmx.SetChannel(2, avg_blue);
}
Exemple #2
0
//--------------------------------------------------------------
void scene02::applyLUT(ofPixelsRef pix){
	
    if (LUTloaded) {
		
		for(int y = 0; y < pix.getHeight(); y++){
			for(int x = 0; x < pix.getWidth(); x++){
				
				ofColor color = pix.getColor(x, y);
				
				int lutPos [3];
				for (int m=0; m<3; m++) {
					lutPos[m] = color[m] / 8;
					if (lutPos[m]==31) {
						lutPos[m]=30;
					}
				}
				
				ofVec3f start = lut[lutPos[0]][lutPos[1]][lutPos[2]];
				ofVec3f end = lut[lutPos[0]+1][lutPos[1]+1][lutPos[2]+1];
				
				for (int k=0; k<3; k++) {
					float amount = (color[k] % 8) / 8.0f;
					color[k]= (start[k] + amount * (end[k] - start[k])) * 255;
				}
				
				lutImg.setColor(x, y, color);
				
			}
		}
		
		lutImg.update();
	}
    
}
void ofxFenster::setCursor(ofPixelsRef pixels, int hotX, int hotY) {
	//not compiling on windows right now
#if !defined(TARGET_WIN32)
	if(pixels.getNumChannels()<4) {
		ofLog(OF_LOG_WARNING, "setCursor ignored. please provide a pixelsRef with alpha channel.");
		return;
	}
	GHOST_TUns8 bitmap[pixels.getWidth()*pixels.getHeight()*3];
	GHOST_TUns8 mask[pixels.getWidth()*pixels.getHeight()];
	unsigned char* pixl = pixels.getPixels();
	int bmpCount = 0;
	int mskCount = 0;
	for(int i=0; i<pixels.getWidth()*pixels.getHeight()*4; i+=4) {
		for(int j=0; j<3; j++) {
			bitmap[bmpCount] = pixl[i+j];
			bmpCount++;
		}
		mask[mskCount] = pixl[i+3];
		mskCount++;
	}
	if(!win->setCustomCursorShape(bitmap, mask, pixels.getWidth(), pixels.getHeight(), hotX, hotY, 1, 0))
		ofLog(OF_LOG_WARNING, "setCursor: something went wrong. Maybe it's not supported on your system.");
#else
	ofLog(OF_LOG_WARNING, "setCursor: not supported on windows yet.");
#endif
}
Exemple #4
0
void LaserGroup::setPixelsColors(ofPixelsRef pixels)
{
    for(auto laser: m_lasers)
    {
        const ofPoint& pos = laser->getPosition();
        ofColor color = pixels.getColor(pos.x*pixels.getWidth(), pos.y*pixels.getHeight());
        laser->setColor(color);
    }
    
    this->updateColor();
}
Exemple #5
0
void Video::learnBgColor(ofPixelsRef pixelSource) {
    int wXh = pixelSource.getWidth() * pixelSource.getHeight();
    int numPixels = wXh * pixelSource.getBytesPerPixel();
    int r,g,b;
    r=g=b=0;
    for(int i=0; i<numPixels; i+=pixelSource.getBytesPerPixel()) {
        r+=pixelSource[i];
        g+=pixelSource[i+1];
        b+=pixelSource[i+2];
    }
    r/=wXh;
    g/=wXh;
    b/=wXh;
    bgColor.set(r, g, b);
    removeBgFromAllFrames(); // TODO: Maybe remove this and make caller explicitly call this if they want to remove background?
}
void ofxCvCheckerboardPreview::setTestImage(ofPixelsRef pixels) {

    if(pixels.getImageType() != OF_IMAGE_GRAYSCALE) {
        ofLogError("ofxCvCheckerboardPreview -- must use grayscale image");
        return;
    }

    lock();
    testImage = pixels;
    if(!internalPixels.isAllocated()) {
        internalPixels.allocate(pixels.getWidth(), pixels.getHeight(), OF_IMAGE_GRAYSCALE);
    }
    newBoardToFind = true;
    boardFound = false;
    unlock();
}
Exemple #7
0
//--------------------------------------------------------------
void LedMatrix::grabImageData(ofPixelsRef pixels)
{

    for (unsigned int i = 0; i < pos.size(); i++)
    {
        colors[i] = pixels.getColor(pos[i].x, pos[i].y);
    }

}
//------------------------------------------------------------------------------
void ofxMatrixNetworkServer::sendFrame(const ofPixelsRef pixels)
{
	//for each connected client lets get the data being sent and lets print it to the screen
	for(unsigned int i = 0; i < (unsigned int)getLastID(); i++){
        
		if(isClientConnected(i) && tx_valid[i] == 2){
            tx_valid[i] = 1;
            
            int planecount = pixels.getNumChannels();
            int dimcount = 2; // only sending 2d matrices from of
            int dim[dimcount];
            dim[0]       = pixels.getWidth();
            dim[1]       = pixels.getHeight();
            int typeSize = pixels.getBytesPerChannel();
            int type     = JIT_MATRIX_TYPE_CHAR;
            
            makeMatrixHeader(planecount, typeSize, type, dim, dimcount);
            
            char *matrix = (char*)pixels.getPixels();
            
            
            //////SEND ONE MATRIX
            sendRawBytes(i, (char *)(&m_chunkHeader), sizeof(t_jit_net_packet_header));
            sendRawBytes(i, (char *)(&m_matrixHeader), sizeof(t_jit_net_packet_matrix));
            
            //DELETE THIS LINE
            //int packSize = SWAP32(m_matrixHeader.dimstride[dimcount-1])*SWAP32(m_matrixHeader.dim[dimcount-1]);
            
            //ofLog(OF_LOG_NOTICE, "send frame to client: " + ofToString(i));
            int vector = dim[0] * typeSize * planecount;
            for(int j = 0; j < dim[1]; j++){
                sendRawBytes(i, matrix + j * vector, vector);
            }
        }
    }
}
//------------------------------------------------------------------------------
void ofxJitterNetworkSender::sendFrame(const ofPixelsRef pixels)
{
    int planecount = pixels.getNumChannels();
    int dimcount = 2; // only sending 2d matrices from of
    int dim[dimcount];
    dim[0]       = pixels.getWidth();
    dim[1]       = pixels.getHeight();
    int typeSize = pixels.getBytesPerChannel();
    int type     = JIT_MATRIX_TYPE_CHAR;

    makeMatrixHeader(planecount, typeSize, type, dim, dimcount);

    char *matrix = (char*)pixels.getPixels();
    
    //////SEND ONE MATRIX
    sendRawBytes((char *)(&m_chunkHeader), sizeof(t_jit_net_packet_header));
    sendRawBytes((char *)(&m_matrixHeader), sizeof(t_jit_net_packet_matrix));
    
    int packSize = SWAP32(m_matrixHeader.dimstride[SWAP32(m_matrixHeader.dimcount)-1])
                * SWAP32(m_matrixHeader.dim[SWAP32(m_matrixHeader.dimcount)-1]);

    sendRawBytes(matrix, packSize);

}
void ofxGreenscreen::learnBgColor(ofPixelsRef pixelSource, int x, int y, int w, int h) {
	int wh = w * h;
	int r,g,b;
	r=g=b=0;
	for(int iy=0; iy<h; iy++) {
		for(int ix=0; ix<w; ix++) {
			int i = pixelSource.getPixelIndex(ix+x, iy+y);
			r+=pixelSource[i];
			g+=pixelSource[i+1];
			b+=pixelSource[i+2];
		}
	}
	r/=wh;
	g/=wh;
	b/=wh;
	bgColor.set(r, g, b);
	update();
}
Exemple #11
0
void ofxAcv::apply(const ofPixelsRef src, ofPixelsRef dst) {
    if (src.getWidth() != dst.getWidth()
        || src.getHeight() != dst.getHeight()
        || src.getNumChannels() != dst.getNumChannels()) {
        ofLogNotice() << "reallocating dst";
        dst.allocate(src.getWidth(), src.getHeight(), src.getNumChannels());
    }
    int w = src.getWidth();
    int h = src.getHeight();
    int ch = src.getNumChannels();
    assert(ch <= curves.size());
    unsigned char* srcPixels = src.getPixels();
    unsigned char* dstPixels = dst.getPixels();
    
    for (int y=0; y<h; ++y) {
        for (int x=0; x<w; ++x) {
            for (int c=0; c<ch; ++c) {
                int idx = (y * w + x) * ch + c;
                dstPixels[idx] = curves[c][srcPixels[idx]];
            }
        }
    }
}
void ofxGreenscreen::setPixels(ofPixelsRef pixels) {
	setPixels(pixels.getPixels(), pixels.getWidth(), pixels.getHeight());
}
void ofxGreenscreen::learnBgColor(ofPixelsRef pixelSource) {
	learnBgColor(pixelSource, 0, 0, pixelSource.getWidth(), pixelSource.getHeight());
}
void ofxFenster::setIcon(ofPixelsRef pixels) {
	if(!win->setIcon(pixels.getPixels(), pixels.getWidth(), pixels.getHeight()))
		ofLog(OF_LOG_WARNING, "oops, looks like setIcon is not yet supported on your system");
}
bool ofxFastFboReader::readToPixels(ofFbo &fbo, ofPixelsRef pix, ofImageType type)
{
	genPBOs();
	
	int channels;
	int glType;
	
	if (type == OF_IMAGE_COLOR)
	{
		channels = 3;
		glType = GL_RGB;
	}
	else if (type == OF_IMAGE_COLOR_ALPHA)
	{
		channels = 4;
		glType = GL_RGBA;
	}
	else if (type == OF_IMAGE_GRAYSCALE)
	{
		channels = 1;
		glType = GL_LUMINANCE;
	}
	else
	{
		return false;
	}
	
	const int width = fbo.getWidth();
	const int height = fbo.getHeight();
	
	if (async)
	{
		index = (index + 1) % num_buffers;
		nextIndex = (index + 1) % num_buffers;
	}
	else
	{
		index = nextIndex = 0;
	}
	
	size_t nb = width * height * channels;
	
	if (nb != num_bytes)
	{
		num_bytes = nb;
		setupPBOs(num_bytes);
	}
	
	glReadBuffer(GL_FRONT);
	
	fbo.bind();
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[index]);
	glReadPixels(0, 0, width, height, glType, GL_UNSIGNED_BYTE, NULL);
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[nextIndex]);
	unsigned char* mem = (unsigned char*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
	
	if (mem)
	{
		pix.setFromPixels(mem, width, height, channels);
		glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
	}
	
	glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
	
	fbo.unbind();
	
	return mem != NULL;
}