not sure if this is what im looking for .
let me explain:
i have the following array [1,2,3,4,5]
now, i would like to add 1 to each cell for (int i=0;i<5;i++) array[i]++;
so the final result would be [2,3,4,5,6]
is there another way of doing so?
the problem is that i have around 10^6 cells that needs to be changed
I was thinking about somehow using a static member that all the matrix cells will be defined by their value + the static value.
This is a very interesting idea. It also is easily generalized. You could have a stack of (different) operations and apply them in order when you want to get the value of a specific element. When you want to set the value of a specific element, you'd have to go backwards and also use the inverse operations. However, that would add a small overhead to every Get / Set call that could quickly become very big (if you keep stacking operations). To solve this problem, you could perform a small number of calculations each time you Get / Set some element. You'd need to also keep track of how many elements you have calculated.
The bottom line is that, while, in the end, you have to make all the calculations, this trick allows very good real time responsiveness for even humongous arrays.
How about a lazy update of the cells? It really doesn't matter what the contents of a cell are until you access it for the latest value. Unless the value of a cell depends on all previous cells, you can apply the update as needed rather than en masse, and that would save a huge amount of time.
The only caveat would be an extra bit of storage necessary to flag whether the cell has its latest value or needs to be updated.
If the values do cascade somehow, you'd probably still get some performance benefits, though it would be more amortized than absolute. In that case something like r0shi's idea would work, where you apply the change to all cells dependent on the current cell retroactively or recursively depending on how difficult the cascade is to reverse.
I'm pretty sure I already responded ... weird O_o
anyway what I was saying is that my program takes a jpg image and converts it
once finished i want to have a "slide bar" to move and change the darkness of the image
aka raise the blackness of all cells and lower them accordingly.
any ideas / approachs ?
as i need to present those changes infront of an audience, those changes should
be made swiftly!
or i have no choice but to go oneat a time? :<
If you use SFML, you can load your image in a sf::Image, then create a sf::Sprite using that image and play with the sprite's color property to adjust the brightness. It's a O(1) operation and it affects every pixel of your image. Maybe the library you're using also has a similar feature and you're not aware of it yet.
well still havent decided which one to use.
I'm a bit familier with SFML (still havent got opencv working)
which command were you talking about?
using sfml2 atm and didnt see any brightness modification functions
or am i missing something?
waltP i can use other formats if JPG is problematic, BMP is ok i guess?
Have you checked how long it takes to just run through the array and add 1 to all the values? I suspect it's not that long. I was recently profiling some code that was doing arithmetic on arrays like this and the compiler-optimised, release code was running over each element and multiplying three doubles and dividing by a fourth. It only took 10 nanoseconds per element! On this scale, a million elements could be updated in 0.01 seconds. This sounds easily fast enough that the user wouldn't notice the difference.
I'm not saying you don't need to optimise your code, I'd just recommend profiling a simple solution to see if it's really a limiting step in the whole process. Sometimes raw fire-power will do the job for you :)