Page 1 of 2

New keyword pixel?

Posted: Tue Dec 10, 2013 12:25 am
by [-hh]
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".

Re: New keyword pixel?

Posted: Tue Dec 10, 2013 1:12 pm
by Mark
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

Re: New keyword pixel?

Posted: Tue Dec 10, 2013 3:25 pm
by [-hh]
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

Re: New keyword pixel?

Posted: Tue Dec 10, 2013 3:42 pm
by Mark
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

Re: New keyword pixel?

Posted: Tue Dec 10, 2013 6:23 pm
by [-hh]
..........

Re: New keyword pixel?

Posted: Tue Dec 10, 2013 6:33 pm
by Mark
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

Re: New keyword pixel?

Posted: Tue Dec 10, 2013 11:28 pm
by [-hh]
..........

Re: New keyword pixel?

Posted: Wed Dec 11, 2013 1:07 am
by dunbarx
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

Re: New keyword pixel?

Posted: Wed Dec 11, 2013 3:42 pm
by [-hh]
..........

Re: New keyword pixel?

Posted: Wed Dec 11, 2013 6:38 pm
by dunbarx
Hermann.

I probably misunderstood what you meant.

Craig

Re: New keyword pixel?

Posted: Wed Dec 11, 2013 8:54 pm
by [-hh]
..........

Re: New keyword pixel?

Posted: Fri Dec 13, 2013 3:25 pm
by Mark
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

Re: New keyword pixel?

Posted: Mon Dec 16, 2013 3:24 am
by ThatOneGuy
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.

Re: New keyword pixel?

Posted: Mon Dec 16, 2013 5:33 am
by jacque
It's possible to work with individual pixels. This might get you started: http://lessons.runrev.com/s/lessons/m/4 ... processing

Re: New keyword pixel?

Posted: Mon Dec 16, 2013 11:54 am
by Mark
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