# Is noise too much for mobile devices to handle in p5js?

**URL:** <https://discourse.processing.org/t/is-noise-too-much-for-mobile-devices-to-handle-in-p5js/23048>\
**Category:** Coding Questions\
**Created:** [August 5, 2020, 3:37am UTC](https://discourse.processing.org/t/is-noise-too-much-for-mobile-devices-to-handle-in-p5js/23048 "2020-08-05T03:37:04Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 13, 2020, 5:53am UTC](https://discourse.processing.org/t/is-noise-too-much-for-mobile-devices-to-handle-in-p5js/23048/10 "2020-08-13T05:53:00Z")

</div>

> [@mnoble](#):
>
> I noticed this line of code had some effect over color:

Just theoretically, b/c I’ve just read that we should expect that almost all mobile devices are configured to use little endian byte order:

> <https://stackoverflow.com/questions/58614504/is-ios-guaranteed-to-be-little-endian>

That utility function is just to make 100% sure our code is indeed running on a little endian device (which statistically should always be so):

> **[Endianness](https://en.wikipedia.org/wiki/Endianness)**
>
> In computing, endianness is the order or sequence of bytes of a word of digital data in computer memory or data communication which is identified by describing the impact of the "first" bytes, meaning at the smallest address or sent first. Danny Cohen introduced the terms big-endian and little-endian into computer science for data ordering in an Internet Experiment Note published in 1980. The adjective endian has its origin in the writings of 18th century Anglo-Irish writer Jonathan Swift. In Co...

The datatype of _pixels[]_ is Uint8ClampedArray: [reference | p5.js](http://p5js.org/reference/#/p5/pixels)

And there are 11 Typed Array versions:

> **[TypedArray - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)**
>
> A TypedArray object describes an array-like view of an
> underlying binary data buffer.
> There is no global property named TypedArray, nor is there a
> directly visible TypedArray constructor. Instead, there are a number of
> different global...

As long as we’re using 1 of the 3 8-bit versions of Typed Arrays we can fully ignore endianness.

But as you can see within Blurry::**resetImageColor()** method there’s a Uint32Array viewer of the p5.Image::_pixels[]_ there:  
`const pix32 = new Uint32Array(img.pixels.buffer),`

It means that instead of needing 4 indices from p5.Image::_pixels[]_ in order to get a pixel’s RGBa color, 1 index now represents the whole 4-byte (32-bit) color value.

The problem about using a multibyte viewer on a little endian device is that its byte order is inverted.

That is, when we read an RGBa pixel we get aBGR mirror of it instead.

And when we write a pixel, we gotta arrange its values in aBGR order, so it’s correctly stored as RGBa:  
`c[3] << 0o30 | c[2] << 0o20 | c[1] << 0o10 | c[0] : // aBGR`

Above the _c[]_ array’s 4 indices represent RGBa, but they’re ordered as aBGR for the sake of the Uint32Array viewer.

But again, all this complex explanation can be skipped if you don’t use a viewer for _pixels[]_. 😉

---

_[View the full topic](https://discourse.processing.org/t/is-noise-too-much-for-mobile-devices-to-handle-in-p5js/23048)._
