You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -227,7 +232,7 @@ It's important to understand how pixel data is stored in computer memory. Each p
227
232
228
233

229
234
230
-
Observe how the (one-dimensional) list of values have been distributed to successive (two-dimensional) pixel locations in the image — wrapping over the right edge just like English text.
235
+
Observe how a one-dimensional list of values in memory can be arranged into successive rows of a two-dimensional grid of pixels, and vice versa.
231
236
232
237
It frequently happens that you'll need to determine the array-index of a given pixel *(x,y)* in an image that is stored in an `unsigned char*` buffer. This little task comes up often enough that it's worth committing the following pattern to memory:
233
238
@@ -236,9 +241,9 @@ It frequently happens that you'll need to determine the array-index of a given p
236
241
// unsigned char *buffer, an array storing a one-channel image
237
242
// int x, the horizontal coordinate (column) of your query pixel
238
243
// int y, the vertical coordinate (row) of your query pixel
239
-
// int imgW, the width of your image
244
+
// int imgWidth, the width of your image
240
245
241
-
int arrayIndex = y*imgW + x;
246
+
int arrayIndex = y*imgWidth + x;
242
247
243
248
// Now you can GET values at location (x,y), e.g.:
@@ -252,16 +257,16 @@ Reciprocally, you can also fetch the x and y locations of a pixel corresponding
252
257
// Given:
253
258
// A one-channel (e.g. grayscale) image
254
259
// int arrayIndex, an index in that image's array of pixels
255
-
// int imgW, the width of the image
260
+
// int imgWidth, the width of the image
256
261
257
-
int y = arrayIndex / imgW; // NOTE, this is integer division!
258
-
int x = arrayIndex % imgW; // The friendly modulus operator.
262
+
int y = arrayIndex / imgWidth; // NOTE, this is integer division!
263
+
int x = arrayIndex % imgWidth; // The friendly modulus operator.
259
264
```
260
265
261
266
Most of the time, you'll be working with image data that is stored in a higher-level container object, such as an `ofImage`. There are *two* ways to get the values of pixel data stored in such a container. In one method, we can ask the image for its array of unsigned char pixel data, using `.getPixels()`, and then fetch the value we want from this array. Many image containers, such as `ofVideoGrabber`, also support a `.getPixels()` function.
This is the RGB version of the elementary `index = y*width + x` pattern we used earlier to fetch pixel values from monochrome images.
449
+
This is, then, the three-channel "RGB version" of the elementary `index = y*width + x` pattern we used earlier to fetch pixel values from monochrome images.
450
+
451
+
Note that you may occasionally encounter libraries or hardware which deliver RGB bytes in a different order, such as BGR.
0 commit comments