Home > Software engineering >  PixelInterleavedSampleModel is confusing with terms like pixel stride, scanline stride and band offs
PixelInterleavedSampleModel is confusing with terms like pixel stride, scanline stride and band offs

Time:06-13

While trying to read about pixel data, I came across PixelInterleavedSampleModel and used this link to get more information. However the terms Pixel Stride, Scanline Stride and bandoffsets in the documentation has confused me. Especially the below details are confusing me :

Pixel stride is the number of data array elements between two samples for the same band on the same scanline. Scanline stride is the number of data array elements between a given sample and the corresponding sample in the same column of the next scanline. Band offsets denote the number of data array elements from the first data array element of the bank of the DataBuffer holding each band to the first sample of the band. The bands are numbered from 0 to N-1. Bank indices denote the correspondence between a bank of the data buffer and a band of image data.

Can anyone please give me an easy explanation with a sample data so that I could see how we can visualize a ARGB data? Also please explain the terms pixel stride and scanline stride and bandoffsets using the sample data.

CodePudding user response:

I'll give it a try... But first some useful "definitions":

  • "interleaved" pixels means the samples for each pixels are stored together in a single array like, R0 G0 B0 R1 G1 B1 ... Rn Gn Bn
  • ...in contrast to "planar" pixels where all samples for one component is stored together, like R0 R1 ... Rn, G0 G1 ... Gn, B0 B1 ... Bn
  • a "scan line" is one line or row of pixels in an image

This answer is only about the interleaved case and the PixelInterleavedSampleModel.

Pixel stride is the number of data array elements between two samples for the same band on the same scanline.

Given a scan line (pixel array) consisting of RGB triplets:

R0 G0 B0 R1 G1 B1 R2 G2 B2 R3 G3 B3 ... Rn Gn Bn
|<-- -->|

...the pixel stride or "the number of data array elements between two samples for the same band" (in the figure, the number of elements from R1 to R2) is simply 3. Similarly, for single band gray samples the pixel stride would be 1, for interleaved RGBA it would be 4.

Scanline stride is the number of data array elements between a given sample and the corresponding sample in the same column of the next scanline.

Again, given a scan line consisting of 320 RGB triplets:

R0 G0 B0 R1 G1 B1 R2 G2 B2 R3 G3 B3 ... R319 G319 B319 R320 B320 G320 ... Rn Gn Bn
|<--               scan line stride               -->|

...the scan line stride would simply be 960, or 3 (the pixel stride) times 320 (the number of pixels in the row).

Some times the data array contains padding at the end of each line. Here's an example where the scan line consists of 320 RGB triplets, but each line in the data array is padded to a multiple of 100, that is 40 samples of padding:

R0 G0 B0 R1 G1 B1 ... R319 G319 B319 ... x0 ... x39 R320 B320 G320 ... Rn Gn Bn X0 ... X39
|<--                 scan line stride          -->|

...the scan line stride is now 1000.

Band offsets denote the number of data array elements from the first data array element of the bank of the DataBuffer holding each band to the first sample of the band. The bands are numbered from 0 to N-1. Bank indices denote the correspondence between a bank of the data buffer and a band of image data.

Given the same scan line consisting of RGB triplets:

R0 G0 B0 R1 G1 B1 R2 G2 B2 R3 G3 B3 ... Rn Gn Bn
0  1  2

...the band offsets would be 0, 1, 2 for R, G and B respectively.

Another possibility is a scan line consisting of ARGB quads, in ABGR order:

A0 B0 G0 R0 A1 B1 G1 R1 ... An Bn Gn Rn
0  1  2  3

...the band offsets would be 3, 2, 1, 0 for R, G, B and A respectively (the band order in the offsets array follow the order of the color model, with any alpha sample last).

Normally it's that simple.

If you want to create an image consisting of the only green sample, or a sub region of the array, that's when these values become more interesting (they would be the same, as they describe the "physical" data layout in memory, but they would differ from that of the raster/image).

  • Related