Pixel list from a list of integers

I'm sure I've done this before but I can't remember how
So I have an RGBA bitmap that I've loaded into a variable tile image
Each value is the 32bit representation of a pixel

image

How can I convert it to the same format as you get from the pixels of costume reporter?

I feel there's a shortcut available to me somewhere to save me the trouble of decoding the integers

Here's what I would do. Convert the 32 bit to hex, then just convert that to rgba. Of course there's probably a much better way to do that though.

That's the sort of thing I'm trying to avoid the effort of doing :slight_smile:

Something in the back of my mind says there's an easy way to do this

RGBA mod 256 to get the lowest byte
RGBA = round( RGBA/256) to shift bytes
Repeat 4 times for 32bit :wink:

Ta for that but it turns out my data isn't quite right - it's not actually integers :frowning:

It's sort of in bytes (but not quite!)

The data length should be exactly 520000 but it looks like some some of the byes are being returned as 16bit values - very strange - I need to work out what's going on! :slight_smile:

I'm down a deep rabbit hole
I'm getting my data via my MQTT extension and it turns out that JavaScript fails to convert it cleanly and gets confused due to unicode :frowning:

I'm off out for the evening so I'll have to look at it later!

I see nothing wrong with Chrome@Win10
untitled script pic - 2022-05-26T215024.695

When I google stuff, there seems to be problems with large arrays using that approach (as shown in my project)

The use of the spread operator ("..."), which simulates calling a proc with zillions of parameters, usually causes a problem.
But it seems that "typed array".toString() is skewed on your platform.
In this case toString() should return text "53,89,137..." without any unicode consideration.

I found this solution and it seems to work

image
image

With HOF in JS
result = payload.reduce( (res, val) => res+String.fromCharCode( val), "")

Much neater thank you :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.