Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Stride of an array
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Example of multidimensional array with non-unit stride=== Non-unit stride is particularly useful for images. It allows for creating subimages without copying the pixel data. Java example: <syntaxhighlight lang="java"> public class GrayscaleImage { private final int width, height, widthStride; /** Pixel data. Pixel in single row are always considered contiguous in this example. */ private final byte[] pixels; /** Offset of the first pixel within pixels */ private final int offset; /** Constructor for contiguous data */ public Image(int width, int height, byte[] pixels) { this.width = width; this.height = height; this.pixels = pixels; this.offset = 0; this.widthStride = width; } /** Subsection constructor */ public Image(int width, int height, byte[] pixels, int offset, int widthStride) { this.width = width; this.height = height; this.pixels = pixels; this.offset = offset; this.widthStride = widthStride; } /** Returns a subregion of this Image as a new Image. This and the new image share the pixels, so changes to the returned image will be reflected in this image. */ public Image crop(int x1, int y1, int x2, int y2) { return new Image(x2 - x1, y2 - y1, pixels, offset + y1 * widthStride + x1, widthStride); } /** Returns pixel value at specified coordinate */ public byte getPixelAt(int x, int y) { return pixels[offset + y * widthStride + x]; } } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)