Hi All
I’ve been doing quite a bit of reading tonight looking at unsigned chars and ofpixels. I think ive gotten my head around some of the different syntaxes to begin with.
can someone confirm im reading this right, some projects creating a pointer to videoplayer.getpixels(), some people just referencing it with a “&” before, this is esstially the same right? (ive been tryning to get my head around pointers too)
in this snippet of code from the examples, the author creates a varible called pixels which referers to fingerMovie.getPixels()…so what ever happens to fingerMovie.getPixels() also happens to pixels; pixels is not a copy right?
void ofApp::draw(){
ofSetHexColor(0xFFFFFF);
fingerMovie.draw(20,20);
ofSetHexColor(0x000000);
ofPixels & pixels = fingerMovie.getPixels();
int vidWidth = pixels.getWidth();
int vidHeight = pixels.getHeight();
int nChannels = pixels.getNumChannels();
// let's move through the "RGB(A)" char array
// using the red pixel to control the size of a circle.
for (int i = 4; i < vidWidth; i+=8){
for (int j = 4; j < vidHeight; j+=8){
unsigned char r = pixels[(j * 320 + i)*nChannels];
float val = 1 - ((float)r / 255.0f);
ofDrawCircle(400 + i,20+j,10*val);
}
}
in this snippet of code from the ofbook videoplayer::getpixels(), the author creats a pointer called pixels which has the memory address where myMovie.getPixels() is stored right? same thing happening in a different way?
unsigned char * pixels = myMovie.getPixels();
int nChannels = movie.getPixelsRef().getNumChannels();
int widthOfLine = myMovie.width; // how long is a line of pixels
int red = pixels[(20 * widthOfLine + 100) * nChannels ];
int green = pixels[(20 * widthOfLine + 100) * nChannels + 1];
int blue = pixels[(20 * widthOfLine + 100) * nChannels + 2];
so im pretty confused about the pointer stuff above but im much more confused about whats going on after that in the different snippets of code.
when i had the idea of messing around with video i thought it was as easy as iterating through every pixel, which would have a 3 values between 0 and 255, manipulating those values, and then reasigning them in the pixel.
i found this https://github.com/ofcourseio/SPRING2016/blob/master/week4/pixels.md which was suppppper helpful explaining how images are stored
but it didnt quite explain the maths for the pixels array index in the [ ] brackets and the maths with the number of channels (this is referencing the second snippet of code) my feeling is it has something to do with memory address’ and arrays but i have no idea at this point.
If anyone could give me a nudge in the right direction i would be very grateful! ive completley hit a brick wall.
Thanks!