New keyword pixel?
Moderator: Klaus
New keyword pixel?
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".
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
Re: New keyword pixel?
Hi,
it might be more useful to add an optional step clause to the repeat control structure:
where myBytes would contain 4 bytes. This would also allow you to process unicode data with
et cetera. To get every 4th byte you might do
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
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
Code: Select all
repeat for each byte myChar in myUnicodeData step 2
Code: Select all
repeat for each byte myBytes in mySomeOtherData
put byte 1 of myBytes into myFirstByte
end repeat
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: New keyword pixel?
Mark,
as I understand the current logic of "step" with repeats, this method
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
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
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
Re: New keyword pixel?
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
Kind regards,
Mark
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: New keyword pixel?
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:51 pm, edited 1 time in total.
shiftLock happens
Re: New keyword pixel?
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: New keyword pixel?
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:52 pm, edited 1 time in total.
shiftLock happens
Re: New keyword pixel?
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:
That sort of thing.
Craig
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
Craig
Re: New keyword pixel?
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:51 pm, edited 1 time in total.
shiftLock happens
Re: New keyword pixel?
Hermann.
I probably misunderstood what you meant.
Craig
I probably misunderstood what you meant.
Craig
Re: New keyword pixel?
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:51 pm, edited 1 time in total.
shiftLock happens
Re: New keyword pixel?
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 77
- Joined: Fri Jan 04, 2013 9:57 am
Re: New keyword pixel?
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.
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.
Re: New keyword pixel?
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
HyperActive Software | http://www.hyperactivesw.com
Re: New keyword pixel?
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:
This replaces the fifth pixel with a white dot.
Kind regards,
Mark
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
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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode