You see, i was trying to make mi first genetic algorithm project, so i decided to make one about a program that evolved to be like a certain image, a simple image (using SDL as mi graphical compiler).
the problem is, i need to make a fuction that compares the colors of each pixel of the model image, with those of the current generation organisms. but i dont know how to obtain the colours as information to use in a fuction (i have a good idea of how to make a comparing function wich is quite easy, but i dont know how to apply that with pixels and their colours).
You could simplify the problem to only take into account the hue of the pixel. http://en.wikipedia.org/wiki/HSL_and_HSV#General_approach
I assume that would make it easier, since you're only taking into account a single dimension.
However, if it is no to much of a problem, can you give a general example or idea of how to obtain the hue information from the pixels of another image.
What i actually need is to get the colour information for every pixel of a .bmp archieve and be able to use it as a variable. (for example, making an array, in wich every member represents one of the pixels, and their values are that of the colors, and later compare each of those pixels with those of another randome generated image in the program.)
Yes, i understand that, however mi doubt is not about how to load the image, i need to get an idea/example of how to get the color value of each pixel of that image so i can use that information in a compare function. something that can say, for example, that the pixel(x,y)=red (or the color code).
The basic layout of a pixel manipulation function looks like this:
1. Lock the surface to access (SDL_LockSurface(), IIRC).
2. Get the pointer to the pixel data from the SDL_Surface structure.
3. Perform pixel operations. Be careful not to read or write outside the boundaries. SDL_Surface has all the size and format information about the surface. Mainly keep an eye out for the pitch and the height. You can access the color components using either bitwise operations or array operations, depending on the bit depth.
4. Unlock the surface.
Check the documentation for the identifiers I mentioned. A recommendation: only use 32 or 24 bpp surfaces. For smaller pixels, accessing the individual color components gets annoying.