开发者

x,y,z to vector offset

I know this may sound stupid but I'm goin crazy with this XD

I'm loading ad image (with ImageMagick) into a 1D vector, so that I have something like:

012345678...
RGBRGBRGB...

Where 0-. Are obviously the indexes of the vector, and R, G, and B are respectively the red byte, green byte, and blue byte. So I have a WIDTHxHEIGHTx3 bytes vector.

Now, let's say I want to access the x,y,z byte,开发者_JS百科 where z is the index of the color, which is the transformation formula to have a linear offset into the vector?


This expression produces an index to color component z at pixel (x,y):

((y * WIDTH) + x) * 3 + z

Assumptions are:

  • Data is placed in row-major order.
  • No padding/alignment bytes are used between rows.


Assuming your data is stored as a series of rows (not a crazy assumption), you can find byte x,y,z at y*WIDTH*3 + 3*x + z

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜