C++ TBB simple/silly 2D->1D array question

Started by
5 comments, last by Servant of the Lord 11 years ago

So I've got mandelbrot running in OpenCL: I am to compare it to Intels TBB.

This is something I really should know by now and I feel silly asking.

I have a struct that represents an RGBA pixel, and I create a buffer of them - a bitmap


BGRA8* buffer = (BGRA8*)malloc( width * height * sizeof(BGRA8) );

Then I iterate through x and y doing whatever using parallel_for

Where do I put my x, y in terms of


buffer[ index ]

?

Thanks in advance, I know this is a silly question!

Advertisement

BGRA8& pixel = buffer[(y * width) + x];

Thank you!

Drop the size from the index equation. Pointer arithmetics already takes the size of its type into account.

You would access it by the same way you access anything: by the way you defined it in your struct, except that you don't use this "->" you use this ".".

buffer [index].x

For some reason I assumed that buffer was a pointer to bytes and not a pointer to BGRA8. That was a mistake on my part. I have edited my previous answer to take that into account.

Sorry for the mistake.

I posted in a thread a bit ago trying to explain it. I might not have done that great a job word-wise, but at least there are pretty pictures to illustrate! biggrin.png

This topic is closed to new replies.

Advertisement