Page 1 of 1

ImageData question

Posted: Tue Jan 19, 2021 3:37 pm
by dunbarx
Purely academic.

In the user guide the following appears on page 466:
For example, the numeric value of the red, green and blue channels respectively for the tenth pixel are given by the expressions:
charToNum(char (4 * 9 + 2 of the imageData of image <image>)
charToNum(char (4 * 9 + 3 of the imageData of image <image>)
charToNum(char (4 * 9 + 4 of the imageData of image <image>
I am not an image kind of guy, using them only for decoration. But what does the above mean, in terms of characterizing the "tenth" pixel? Why the "4 * 9" + "some sort of offset" thing? In other words, why "38", "39" and "40"? Why not just "42" for all and be done with it?

This is not urgent.

Craig

Re: ImageData question

Posted: Tue Jan 19, 2021 4:21 pm
by FourthWorld
I believe the benefit there is merely readability, reminding the reader that each of the component values relate to a single thing.

It's also note more likely to reflect real world usage, as pixel manipulation is most commonly done on the image as a whole in a stepped loop, rather than a single pixel for which a single hard-coded integer would work.

Re: ImageData question

Posted: Tue Jan 19, 2021 4:34 pm
by dunbarx
I believe the benefit there is merely readability,
I like to do that as well, since I cannot understand my own code ten minutes after I write it.

We do not have to waste time here, but any idea why the tenth pixel has three channels identified by "38,39,40? Are there headers in the string that offset those values?

This is even less urgent than before.

Craig

Re: ImageData question

Posted: Tue Jan 19, 2021 4:50 pm
by bogs
dunbarx wrote:
Tue Jan 19, 2021 4:34 pm
any idea why the tenth pixel has three channels identified by "38,39,40?
I'm wondering if I understand your question Craig, since any pixel would be comprised of 3 values. How could it be otherwise?

Re: ImageData question

Posted: Tue Jan 19, 2021 5:38 pm
by dunbarx
Hi.

I get the characterization of three channels.

The user Guide explicitly gives an example for the tenth pixel. I was just wondering how the imageData string was ordered. I suspect it is not important.

Craig

Re: ImageData question

Posted: Tue Jan 19, 2021 6:16 pm
by FourthWorld
I believe the order of each pixel is Alpha channel, R, G, B.

Re: ImageData question

Posted: Tue Jan 19, 2021 7:55 pm
by kdjanz
For example, the numeric value of the red, green and blue channels respectively for the tenth pixel are given by the expressions:
charToNum(char (4 * 9 + 2 of the imageData of image <image>)
charToNum(char (4 * 9 + 3 of the imageData of image <image>)
charToNum(char (4 * 9 + 4 of the imageData of image <image>
My understanding is they wrote it this way to reflect the structure of the file.
There are 4 bytes per colour of image data and you want the 10th pixel, so you step over the 9x4 bytes of the first pixels.
So now you are at the beginning of the 10th pixel. But the first pixel is alpha and not RGB so you step over that one to get to the R pixel.
Step over one more byte to get to G pixel, and then one more to get to the B pixel.

The numbers work that way because you are working in bytes and there are 4 bytes to each pixel - alpha and RGB.

Since I am a newbie and beginner I may be way off and stand to be corrected by someone who really understands what they are doing.

Kelly

Re: ImageData question

Posted: Tue Jan 19, 2021 9:21 pm
by dunbarx
Kelly and Richard.

Ah, if you need four characters to, er, characterize a pixel, then I get it. The "missing" ten chars were never missing.

Craig

Re: ImageData question

Posted: Tue Jan 19, 2021 11:15 pm
by bogs
There is this excellent article on the topic btw - https://www.sonsothunder.com/devres/liv ... mag003.htm

Re: ImageData question

Posted: Tue Jan 19, 2021 11:24 pm
by FourthWorld
dunbarx wrote:
Tue Jan 19, 2021 9:21 pm
Kelly and Richard.

Ah, if you need four characters to, er, characterize a pixel, then I get it. The "missing" ten chars were never missing.
The first ten pixels are never mentioned because they contain steganographically hidden secrets of space alien technology.

Never process the first ten pixels of an image. Ever. You'll be sorry.

;)

Or it might have been just an arbitrary number for the example.

But I'm sticking with the space alien theory, and you can't talk me out of it.

Re: ImageData question

Posted: Wed Jan 20, 2021 1:02 am
by kdjanz
If the aliens can compress secret technology into 40 bytes of information or ten pixels, then we had better start bowing to a superior race!

Re: ImageData question

Posted: Wed Jan 20, 2021 6:57 pm
by jacque
FourthWorld wrote:
Tue Jan 19, 2021 6:16 pm
I believe the order of each pixel is Alpha channel, R, G, B.
I thought the alpha pixel was last but I'm too lazy to look it up.

Re: ImageData question

Posted: Wed Jan 20, 2021 7:52 pm
by FourthWorld
Yeah, I was also too lazy to look it up. I wrote that from memory, but it's been a few weeks since I actually did pixel parsing, so I may be misremembering. At least it's consistent with the example, which skips byte 1 to get RGB from bytes 2 thru 4.

Re: ImageData question

Posted: Wed Jan 20, 2021 9:04 pm
by jacque
I looked it up. You're right, the first pixel is the alpha channel.