示例#1
0
文件: App.cpp 项目: nikki93/spe
void desaturate(ofPixels &pix) {
    // desaturate
    for (int i = 0; i < 1024; ++i)
        for (int j = 0; j < 768; ++j)
        {
            ofColor col = pix.getColor(i, j);
            pix.setColor(i, j, ofColor(col.getBrightness()));
        }
}
示例#2
0
文件: App.cpp 项目: nikki93/spe
void blur(ofPixels &pix) {
    #define PIX(x, y) pix.getColor(ofClamp(x,0,1023), ofClamp(y,0,767))
    #define RAD 0.2
    // blur X
    for (int x = 0; x < 1024; ++x)
        for (int y = 0; y < 768; ++y)
        {
            ofColor col(0);
            col += PIX(x - 4*RAD, y) * 0.000215825;
            col += PIX(x - 3*RAD, y) * 0.00579007;
            col += PIX(x - 2*RAD, y) * 0.059897;
            col += PIX(x - 1*RAD, y) * 0.241811;
            col += PIX(x        , y) * 0.384572;
            col += PIX(x + 1*RAD, y) * 0.241811;
            col += PIX(x + 2*RAD, y) * 0.059897;
            col += PIX(x + 3*RAD, y) * 0.00579007;
            col += PIX(x + 4*RAD, y) * 0.000215825;
            pix.setColor(x, y, col);
        }
    // blur Y
    for (int x = 0; x < 1024; ++x)
        for (int y = 0; y < 768; ++y)
        {
            ofColor col(0);
            col += PIX(x, y - 4*RAD) * 0.000215825;
            col += PIX(x, y - 3*RAD) * 0.00579007;
            col += PIX(x, y - 2*RAD) * 0.059897;
            col += PIX(x, y - 1*RAD) * 0.241811;
            col += PIX(x, y        ) * 0.384572;
            col += PIX(x, y + 1*RAD) * 0.241811;
            col += PIX(x, y + 2*RAD) * 0.059897;
            col += PIX(x, y + 3*RAD) * 0.00579007;
            col += PIX(x, y + 4*RAD) * 0.000215825;
            pix.setColor(x, y, col);
        }
}
示例#3
0
// Called every frame.
void update() {
    // Update our camera.
    grabber.update();
    
    // If the camera has a new frame to offer us ...
    if (grabber.isFrameNew())
    {
        // Get a reference (denoted by &) to the camera's pixels. Getting a 
        // reference means that we won't have to make a copy of all of the 
        // frame's pixels (since we only need one column anyway). This means our
        // program requires less processing power.
        //
        // const prevents us from accidentally modifying the cameras's pixels.
        const ofPixels& cameraPixels = grabber.getPixelsRef();
        
        // Choose a slit location. In this case we'll collect slits from the 
        // column in the middle of the camera feed.
        int slitPositionX = grabber.getWidth() / 2;
        
        // Cycle through each pixel in the selected column and place that pixel
        // at a position x = xPosition and y = to the same position as the 
        // oritinal.
        for (int y = 0; y < grabber.getHeight(); y++)
        {
            // Get the pixel as a color at x / y from the grabber.
            ofColor pixelFromGrabber = cameraPixels.getColor(slitPositionX, y);
            
            // Set that pixel color to the x / y position in the output pixels.
            pixels.setColor(xPosition, y, pixelFromGrabber);
        }
        
        // Increment our xPosition so next update we'll draw a colum shifted to 
        // the right by one pixel.
        xPosition = xPosition + 1;
        
        // If our xPosition is greater than or equal to the width of the display 
        // pixels, reset our x position to 0.
        if (xPosition >= pixels.getWidth())
        {
            xPosition = 0;   
        }
    }
}
示例#4
0
// by now we're copying everything (no pointers)
void ofxGifFile::addFrame(ofPixels _px, int _left, int _top, bool useTexture, GifFrameDisposal disposal, float _duration){
    ofxGifFrame f;

    if(getNumFrames() == 0){
        accumPx = _px; // we assume 1st frame is fully drawn
        if ( !useTexture ){
            f.setUseTexture(false);
        }
        f.setFromPixels(_px , _left, _top, _duration);
		gifDuration = _duration;
    } else {
        // add new pixels to accumPx
        int cropOriginX = _left;
        int cropOriginY = _top;
    
        // [todo] make this loop only travel through _px, not accumPx
        for (int i = 0; i < accumPx.getWidth() * accumPx.getHeight(); i++) {
            int x = i % accumPx.getWidth();
            int y = i / accumPx.getWidth();
            
            if (x >= _left  && x < _left + _px.getWidth()  &&
                y >= _top   && y < _top  + _px.getHeight()){
                int cropX = x - cropOriginX;  //   (i - _left) % _px.getWidth();
                int cropY = y - cropOriginY;
                //int cropI = cropX + cropY * _px.getWidth();
                if ( _px.getColor(cropX, cropY).a == 0 ){
                    switch ( disposal ) {
                        case GIF_DISPOSAL_BACKGROUND:
                            _px.setColor(x,y,bgColor);
                            break;
                            
                        case GIF_DISPOSAL_LEAVE:
                        case GIF_DISPOSAL_UNSPECIFIED:
                            _px.setColor(x,y,accumPx.getColor(cropX, cropY));
//                            accumPx.setColor(x,y,_px.getColor(cropX, cropY));
                            break;
                            
                        case GIF_DISPOSAL_PREVIOUS:
                            _px.setColor(x,y,accumPx.getColor(cropX, cropY));
                            break;
                    }
                } else {
                    accumPx.setColor(x, y, _px.getColor(cropX, cropY) );
                }
            } else {
                if ( _px.getColor(x, y) == bgColor ){
                    switch ( disposal ) {
                        case GIF_DISPOSAL_BACKGROUND:
                            accumPx.setColor(x,y,bgColor);
                            break;
                            
                        case GIF_DISPOSAL_UNSPECIFIED:
                        case GIF_DISPOSAL_LEAVE:
                            accumPx.setColor(x,y,_px.getColor(x, y));
                            break;
                            
                        case GIF_DISPOSAL_PREVIOUS:
                            _px.setColor(x,y,accumPx.getColor(x, y));
                            break;
                    }
                } else {
                    accumPx.setColor(x, y, _px.getColor(x, y) );
                }
            }
        }
        
        if ( !useTexture ){
            f.setUseTexture(false);
        }
        f.setFromPixels(_px,_left, _top, _duration);
    }
    accumPx = _px;
    
    //
    gifFrames.push_back(f);
}