Competition #1B: Reversing imageData (4-byte chunks)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Competition #1B: Reversing imageData (4-byte chunks)
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:48 pm, edited 1 time in total.
shiftLock happens
Re: Competition #1B: Reversing imageData (4-byte chunks)
Hi Hermann,
Although the script is longer, this might be quicker:
I didn't download your stack. Let me know your test results.
Kind regards,
Mark
Although the script is longer, this might be quicker:
Code: Select all
function reverse4ByteChunks theData
put 0 into myCounter
repeat for each char myChar in theData
add 1 to myCounter
put myChar after my4ByteChunk
if myCounter is 4 then
put 0 into myCounter
put my4ByteChunk before myNewData
put empty into my4ByteChunk
end if
end repeat
return myNewData
end reverse4ByteChunks
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: Competition #1B: Reversing imageData (4-byte chunks)
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:48 pm, edited 1 time in total.
shiftLock happens
Re: Competition #1B: Reversing imageData (4-byte chunks)
Hi Hermann,
I can only say that the results are interesting. Apparently, repeat with is faster. I would think that finding char x in your script takes "a lot" of time, but updating the counter in my script seems to take even more time. It would be nice if we had some additional function in LiveCode to operate on binary data.
Kind regards,
Mark
I can only say that the results are interesting. Apparently, repeat with is faster. I would think that finding char x in your script takes "a lot" of time, but updating the counter in my script seems to take even more time. It would be nice if we had some additional function in LiveCode to operate on binary 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
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- VIP Livecode Opensource Backer
- Posts: 10058
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Competition #1B: Reversing imageData (4-byte chunks)
If the goal is to reverse an image you might consider the flip command.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Competition #1B: Reversing imageData (4-byte chunks)
Hi,
The goal is not the flip an image but to revert data. One of the applications could be to flip an image, although this isn't necessary.
I tried to use the flip command to revert arbitrary data, but this isn't possible, because the first of every four bytes that represent a pixel is automatically replaced with NULL. If you try to flip arbitrary data, the data will get corrupted. I tried this with the templateImage, which I thought would be a clever way, if it worked.
Kind regards,
Mark
The goal is not the flip an image but to revert data. One of the applications could be to flip an image, although this isn't necessary.
I tried to use the flip command to revert arbitrary data, but this isn't possible, because the first of every four bytes that represent a pixel is automatically replaced with NULL. If you try to flip arbitrary data, the data will get corrupted. I tried this with the templateImage, which I thought would be a clever way, if it worked.
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
-
- VIP Livecode Opensource Backer
- Posts: 10058
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Competition #1B: Reversing imageData (4-byte chunks)
Agreed, I wouldn't attempt to use image-specific commands to work with non-image data. Perhaps the title of this thread could be updated to reflect the actual goal?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Competition #1B: Reversing imageData (4-byte chunks)
Hi,
Currently, I can't think of many more applications besides imageData and Unicode. I'm fine with the title.
Kind regards,
Mark
Currently, I can't think of many more applications besides imageData and Unicode. I'm fine with the title.
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: Competition #1B: Reversing imageData (4-byte chunks)
..........
Last edited by [-hh] on Wed Aug 13, 2014 1:48 pm, edited 1 time in total.
shiftLock happens
-
- VIP Livecode Opensource Backer
- Posts: 10058
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Competition #1B: Reversing imageData (4-byte chunks)
Hence my earlier question about the thread title.[-hh] wrote:Such a procedure will certainly be faster as LCReverse above (as long as the image is not too large) and will win the competition.
But it's not usable for 4-Byte chunks in general, as Mark pointed out.
It also raises another way of looking at things like your other thread about pixel chunk types: Ultimately, when the clever scripting is done, we code to get a result. In this case, the engine makes short work of reversing images, and with the pixel chunk type request I can't help but wonder if there's a similarly higher-level approach for far better performance because it can be optimized for the goal.
For example, a common goal of working with pixels is to apply a convolving matrix, but rather than make it slightly easier to code those by hand wouldn't it be cool if we had a convolve function in the engine?
As a guy who's spent way too much time benchmarking xTalk nuances, when I see a data-intensive task I find myself wondering if the biggest gains could be had with features optimized for them. No too specific so they're only good for one thing, but hopefully not too generalized either so we can get a real boost by handing the task over to the engine.
It's a tough task to find the right dividing lines, but perhaps worth pondering.
In this thread, for example, would it be helpful to have a general reverse function, that would reverse any data regardless of whether it's textual or binary? With a specified chunk length it would seem helpful, no?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Competition #1B: Reversing imageData (4-byte chunks)
Hi Hermann,
I agree there are several weak points in my script. "Put before" is also one of them. I don't think it makes much sense to discuss this at length. The repeat with method seems to be the fastest and it would be nice to have a new function to do quick reversal of data. Perhaps, this function could also allow for several patterns, such as mirroring, horizontal and vertical flip, diagonal, etc. This would also be useful for statistics. That is a reason for a new feature request.
Kind regards,
Mark
I agree there are several weak points in my script. "Put before" is also one of them. I don't think it makes much sense to discuss this at length. The repeat with method seems to be the fastest and it would be nice to have a new function to do quick reversal of data. Perhaps, this function could also allow for several patterns, such as mirroring, horizontal and vertical flip, diagonal, etc. This would also be useful for statistics. That is a reason for a new feature request.
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