Why do you bother making vectorX and vectorY at all? You already have that data in the myPixels vector.
That said... if you know the final size of the vector, you should allocate space for it up front with reserve(). If you don't do this, as the vector grows it will [incorrectly] guess how much space it needs, then will reallocate/move the data when it exceeds that bounds. Depending on how large this image is, this could be happening like 5 or 6 times
per vector (of which you have 3).
Also... per-pixel access in software is going to be slow. Moving images from the CPU to GPU is extremely time consuming. Moving pixel data from GPU to CPU is even slower. So it's likely that that's your bottleneck here. Consider doing these kinds of effects with shaders (GPU side software), rather than in your main program (CPU side software).
Lastly.... over 3 seconds seems ub]incredibly[/b] slow. How big is this image? And/or are you compiling with optimizations enabled? If you do not have optimizations on (ie: "Release" mode), then any times you have are
meaningless. Rebuild with optimizations on and get new times.
So yeah... do the following:
1) Reserve space in myPixels up front:
1 2 3 4
|
myPixels.reserve(largeur * hauteur);
for( ... )
{ /* fill 'myPixels' with coords for non-black pixels */ }
|
2) Don't create separate vectorX and vectorY vectors. Just use myPixels.
3) Turn on optimizations, rebuild, get new times.
4) Better yet, use shaders rather than cpu pixel access.