hi, i have a problem with a code, the idea is to iterate over the pixels of an image and get the dark pixels and put them in a new vector, then draw my vector into a texture. The thing is that im getting a wierd behaivor, it seems it grabs the pixels fine, but theres a problem in the way how it draws back into the texture, i can see some kind of pattern in the texture , but i dont know what is going wrong, any idea?
here is an example of the result i get:
http://www.moco.dreamhosters.com/imagen-…-exture.png
and here is the code
#include "testApp.h"
#include "stdio.h"
//--------------------------------------------------------------
//testApp::testApp(){
//}
//--------------------------------------------------------------
void testApp::setup(){
if (img.loadImage("ofImage.png")){
cout << "Image loaded." << endl;
unsigned char * pixels = img.getPixels();
int w = img.width;
int h = img.height;
int acu = 0;
int value = 0;
//en que casos conviene hacer dos iteraciones anidadas y en que caso hacer una sola iteracion?
for (int i = 0; i < w * 3; i++){
for (int j = 0; j < h * 3 ; j++){
value = value + pixels[j * w + j * 3];
acu = acu + 1;
if(acu == 4 )
{
acu = 0;
value = 0;
}
//cout << value << endl;
if (value >= 0 && value <= 50)
oscuros.push_back(value);
else if (value >= 51 && value <= 101)
oscuros.push_back(255);
else
oscuros.push_back(255);
}
}
cout << medios.size() << endl;
}
else
cout << "Error: Image not load" << endl;
}
//--------------------------------------------------------------
void testApp::update(){
//cout << claros.size() << endl;
//GL_RGBA
tex.allocate(img.width * 3 , img.height * 3, GL_RGB);
tex.loadData(&oscuros[0], img.width , img.height , GL_RGB);
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetColor(0xffffff);
img.draw(0, 0);
tex.draw(540, 0, img.width , img.height );
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
//cout << key << endl;
if (key == 358){
}
}
//--------------------------------------------------------------
void testApp::keyReleased(int key){
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){
}