Competition #1B: Reversing imageData (4-byte chunks)

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Competition #1B: Reversing imageData (4-byte chunks)

Post by [-hh] » Mon Dec 09, 2013 4:17 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:48 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: Competition #1B: Reversing imageData (4-byte chunks)

Post by Mark » Tue Dec 17, 2013 9:09 am

Hi Hermann,

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
I didn't download your stack. Let me know your test results.

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: Competition #1B: Reversing imageData (4-byte chunks)

Post by [-hh] » Tue Dec 17, 2013 12:12 pm

..........
Last edited by [-hh] on Wed Aug 13, 2014 1:48 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: Competition #1B: Reversing imageData (4-byte chunks)

Post by Mark » Wed Dec 18, 2013 3:21 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by FourthWorld » Wed Dec 18, 2013 3:51 pm

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

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

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by Mark » Wed Dec 18, 2013 5:34 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by FourthWorld » Wed Dec 18, 2013 5:36 pm

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

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

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by Mark » Wed Dec 18, 2013 5:44 pm

Hi,

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

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

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by [-hh] » Thu Dec 19, 2013 2:06 am

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by FourthWorld » Thu Dec 19, 2013 2:50 am

[-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.
Hence my earlier question about the thread title.

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

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

Re: Competition #1B: Reversing imageData (4-byte chunks)

Post by Mark » Thu Dec 19, 2013 12:43 pm

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
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: Competition #1B: Reversing imageData (4-byte chunks)

Post by [-hh] » Thu Dec 19, 2013 11:45 pm

..........
shiftLock happens

Post Reply