New keyword pixel?

Something you want to see in a LiveCode product? Want a new forum set up for a specific topic? Talk about it here.

Moderator: Klaus

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

New keyword pixel?

Post by [-hh] » Tue Dec 10, 2013 12:25 am

Would like to know your opinion to add a new keyword

one pixel= one 4-byte chunk of imageData

This may speed up nearly all imageData operations as one could enumerate the fast way

repeat for each pixel pxl in iData
-- access one of the 4 chars of pxl
end repeat

And we would have in a natural way:
(the width of img "A") * (the height of img "A") = the number of pixels of img "A".
shiftLock happens

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: New keyword pixel?

Post by Mark » Tue Dec 10, 2013 1:12 pm

Hi,

it might be more useful to add an optional step clause to the repeat control structure:

Code: Select all

repeat for each byte myBytes in myImageData step 4
where myBytes would contain 4 bytes. This would also allow you to process unicode data with

Code: Select all

repeat for each byte myChar in myUnicodeData step 2
et cetera. To get every 4th byte you might do

Code: Select all

repeat for each byte myBytes in mySomeOtherData
  put byte 1 of myBytes into myFirstByte
end repeat
Just an idea. Probably there is a better way to do this. The point is that it might be useful to have a more general to enhance repeat for loops, which can be applied to more than just image data.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: New keyword pixel?

Post by [-hh] » Tue Dec 10, 2013 3:25 pm

Mark,

as I understand the current logic of "step" with repeats, this method

Code: Select all

repeat for each obj o1 in myData step x start y
would enumerate the obj in myData, starting with obj y and thereafter pick up every x-th obj (x may be negative to count down) and name it o1.

This would be fine. You have my vote with this.

Your examples are capable of being misunterstood because you use 'byte' twice, with the current definition of LC and with a new (4-chars?) definition. For example your last example one could read as follows: 'myBytes' is the name for a byte, so it IS a byte, so byte 1 of myBytes IS myBytes itself, no matter if you use the current byte=one-char definition of LC or a new 'byte'=x-chars definition.

Anyway, it is not worth any discussion how you name the child ('iByte' may be already in use). With a new keyword
        <name the child somehow> = 4 contiguous bytes
you could handle imageData, UTF32 data (which consists of 4 byte-chunks only), UTF16 data (which consists of 2 to 4 byte-chunks), UTF8 data (which consists of 1 to 4 byte-chunks).

Nevertheles, for Unicode I would prefer to the above objects 'uniChars' of length 1 to 4 bytes, and we mostly don't have to care about their length, just walk through with "each uniChar u in myUnicodeText" or pick up chunks by "uniChar <number1> to <number2> of myUnicodeText".

Hermann
shiftLock happens

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: New keyword pixel?

Post by Mark » Tue Dec 10, 2013 3:42 pm

Hi Hermann,

No, you misunderstand me. Both times when I write "byte", I mean the same type of byte, i.e. really one byte at a time from any binary data stream, but if you'd add the step x clause, you'd get x bytes instead of 1.

Also, repeat loops don't work with objects as far as I know. Repeat for each obj wouldn't make sense.

There is no need for a start clause. LiveCode can already do this. So, the syntax to read 4 bytes at a time would become

Code: Select all

repeat for each byte myByte in byte myStartByte to -1 of myData step 4
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: New keyword pixel?

Post by [-hh] » Tue Dec 10, 2013 6:23 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:51 pm, edited 1 time in total.
shiftLock happens

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: New keyword pixel?

Post by Mark » Tue Dec 10, 2013 6:33 pm

Hi Hermann,

Do what with my previous example? I think I explained it all already. I would stick to the syntax I gave earlier. It would do what you want and adheres to the LiveCode spirit.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: New keyword pixel?

Post by [-hh] » Tue Dec 10, 2013 11:28 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:52 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: New keyword pixel?

Post by dunbarx » Wed Dec 11, 2013 1:07 am

Hermann.

Several things going on here, but one thing you mentioned, about referencing objects in a repeat loop. There is no valid:

repeat for each field tField --or button or whatever

If you want to do something to a set of fields, you do it the other way around:

Code: Select all

put "9,10,12,14,18" into fontList
repeat with y = 1 to the number of items of fontList
  set the textSize of fld y to item y of fontList
end repeat
That sort of thing.

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: New keyword pixel?

Post by [-hh] » Wed Dec 11, 2013 3:42 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:51 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: New keyword pixel?

Post by dunbarx » Wed Dec 11, 2013 6:38 pm

Hermann.

I probably misunderstood what you meant.

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: New keyword pixel?

Post by [-hh] » Wed Dec 11, 2013 8:54 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:51 pm, edited 1 time in total.
shiftLock happens

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: New keyword pixel?

Post by Mark » Fri Dec 13, 2013 3:25 pm

Hello Hermann,

Let me just answer your question about repeat loops. Teachers tend to start with repeat loops with 1 parameter. This is also the type of repeat loop that I discuss before all other types in my book. It is easy to explain the "repeat 2" will do everything between repeat and end repeat twice. Repeat without parameter is a little more difficult, because one needs to add a condition to exit the loop. All other repeat structures are difficult, one way or another.

However, this doesn't have much to do with your original suggestion, to add pixel as a keyword (or rather chunk reference).I think it would be nice if RunRev figured out how to do this.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

ThatOneGuy
Posts: 77
Joined: Fri Jan 04, 2013 9:57 am

Re: New keyword pixel?

Post by ThatOneGuy » Mon Dec 16, 2013 3:24 am

I remember thinking about this before.

Right now, the only way to change the color of a pixel is to select the pencil tool and drag it on the desired space. It would be nice to just set the data in specific pixels to what you want and to read the data out of specific pixels without needing to place the cursor there first or do some other odd action that is difficult to hide from the user.

When dealing with images, a new keyword would speed up editing quite a bit and add the ability to do much more than can be done now. This is a good idea.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: New keyword pixel?

Post by jacque » Mon Dec 16, 2013 5:33 am

It's possible to work with individual pixels. This might get you started: http://lessons.runrev.com/s/lessons/m/4 ... processing
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: New keyword pixel?

Post by Mark » Mon Dec 16, 2013 11:54 am

Hi ThatOneGuy,

THe ImageData of an image object are series of 4 bytes. the first byte contains zeros only. I believe there was a plan to use them for something, but it never happened. The remaining 3 bytes define the RGB colour of the pixel. If you replace a series of bytes with a different value, you can change the colour:

Code: Select all

put the imageData of img 1 into myData
put numToChar(255) into myWhite
put NULL & myWhite & myWhite & myWhite into char 17 to 20 of myData
set the imageData of img 1 to myData
This replaces the fifth pixel with a white dot.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply