ImageData question

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

ImageData question

Post by dunbarx » Tue Jan 19, 2021 3:37 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: ImageData question

Post by FourthWorld » Tue Jan 19, 2021 4:21 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: ImageData question

Post by dunbarx » Tue Jan 19, 2021 4:34 pm

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: ImageData question

Post by bogs » Tue Jan 19, 2021 4:50 pm

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?
Image

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: ImageData question

Post by dunbarx » Tue Jan 19, 2021 5:38 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: ImageData question

Post by FourthWorld » Tue Jan 19, 2021 6:16 pm

I believe the order of each pixel is Alpha channel, R, G, B.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: ImageData question

Post by kdjanz » Tue Jan 19, 2021 7:55 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: ImageData question

Post by dunbarx » 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.

Craig

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: ImageData question

Post by bogs » Tue Jan 19, 2021 11:15 pm

There is this excellent article on the topic btw - https://www.sonsothunder.com/devres/liv ... mag003.htm
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: ImageData question

Post by FourthWorld » Tue Jan 19, 2021 11:24 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

kdjanz
Posts: 300
Joined: Fri Dec 09, 2011 12:12 pm
Location: Fort Saskatchewan, AB Canada

Re: ImageData question

Post by kdjanz » Wed Jan 20, 2021 1:02 am

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!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: ImageData question

Post by jacque » Wed Jan 20, 2021 6:57 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9824
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: ImageData question

Post by FourthWorld » Wed Jan 20, 2021 7:52 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7229
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: ImageData question

Post by jacque » Wed Jan 20, 2021 9:04 pm

I looked it up. You're right, the first pixel is the alpha channel.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Talking LiveCode”