I am trying to do pixel point processes where I iteratively add some number to every component of every pixel of an image. I can update the red and green components of every pixel but for some reason this fails for the blue component. Here is my ofApp.cpp:
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
img.load("lineflower.png");
W = ofGetWidth();
H = ofGetHeight();
img.resize(W, H);
src = img.getPixels().getData();
}
//--------------------------------------------------------------
void ofApp::update(){
for (int x = 0; x < W; x++) {
for (int y = 0; y < H; y++) {
int idx = 3 * (y * W + x);
src[idx+2] += 4;
}
}
img.update();
}
//--------------------------------------------------------------
void ofApp::draw(){
img.draw(0, 0, W, H);
}
When I replace idx + 2 with idx or idx + 1 I get a constantly changing visual, but when I use idx + 2 I get a still image. It seems like for some reason it cannot access the blue components of pixels?
24 posts - 4 participants