Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, your assumptions about the OpenCL layout are correct. OpenCL indeed uses the layout you describe and the formulas you provide for both the 2D and the 3D case are correct, component after component, pixel after pixel, row after row, slice after slice. And I (having an OpenGL background) consider this pretty standard.</p> <p>Yet there is a bit of a naming confusion here, since what row-major <em>in general</em> means is what <em>Wikipedia</em> says, the first dimension changes with the lowest frequency and the last dimension is contiguous. Yet with images, the row isn't actually the <em>first</em> dimension, but the <em>y</em>-dimension, and columns are <em>x</em>. So while OpenCL (at least in 2D) uses literal <em>"row-major"</em> layout (since rows change less often), it is generally seen (in the terminology as used by <em>Wikipedia</em>) rather column-major, since the first dimension (<em>x</em>) is contiguous. And this translates well to 3D, where the last dimension (<em>z</em>) changes with lowest frequency. So you got <em>Wikipedia</em> wrong, what it is actually saying is that general column-major (as extended to 3D) is </p> <pre><code>index = z*WIDTH*HEIGHT + y*WIDTH + x </code></pre> <p>which, given that <code>x=col</code> and <code>y=row</code>, is indeed</p> <pre><code>index = slice*NUM_ROWS*NUM_COLS + row*NUM_COLS + col </code></pre> <p>which is exactly what OpenCL uses. So to answer you actual questions:</p> <ol> <li><p>Exactly like you explained in the first part of your question.</p></li> <li><p>Because you got Wikipedia wrong and confused matrix-based <code>(row,col)</code>-indexing with image-based <code>(x,y)</code>-indexing and what OpenCL uses corresponds to what <em>Wikipedia</em> generally calls column-major.</p></li> </ol> <p><strong>EDIT:</strong> This confusion of index-based addressing (like matrices) and coordinate-based addressing (like images) is a common source of confusion. For example in OpenCV (a famous image processing library) images are represented and addressed as matrices and thus like <code>(row,col)</code>, which for an actual image means <code>(y,x)</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload