Reputation: 2741
I'm doing image processing with filters since it's cool currently, and one quick method I use to create filters is to calculate rgb curve profiles, so that I have 3 arrays, redProfile, greenProfile, blueProfile.
I'm usually doing this when I'm applying an effect on pixels in a loop:
*dest++ = bLomoRGB[top(r)];
*dest++ = gLomoRGB[top(g)];
*dest++ = rLomoRGB[top(b)];
*dest++ = 0xff;
x++;
if (x > 639) { x = 0; y++; }
continue;
So, for each color, I pick the color in the profile.
Is this possible to work with matrix, or to execute it more efficiently?
i.e. Coding something like:
Array a = all my pixels
Array b = my index
Apply b on a
I know this is simpler than pseudo-code and doesn't even deserve to be grayed as code, but I still wonder if it is relevant to always maintain a loop to do a single thing like changing all number for their indexed value.
Upvotes: 0
Views: 105
Reputation: 11058
I doubt that there are some magic operations that perform this for the whole matrix.
However, this can be done more efficiently if you write your data by 32-bit blocks at once:
uint32_t *dest;
*dest++ = (bLomoRGB[top(r)] & 0xff) | ((gLomoRGB[top(g)] & 0xff) << 8) |
((rLomoRGB[top(b)] & 0xff) << 16) | 0xff000000;
Also, the code can be quite well parallelized. If you're looking for some standard way of parallelizing such loops, take a look at OpenMP.
Upvotes: 2