简体   繁体   中英

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, 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.

假设数据存储为一系列行(不是疯狂的假设),则可以在y*WIDTH*3 + 3*x + z处找到字节x,y, y*WIDTH*3 + 3*x + z

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM