Page 1 of 1

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

Posted: Mon Dec 09, 2013 4:17 pm
by [-hh]
..........

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

Posted: Tue Dec 17, 2013 9:09 am
by Mark
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

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

Posted: Tue Dec 17, 2013 12:12 pm
by [-hh]
..........

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

Posted: Wed Dec 18, 2013 3:21 pm
by Mark
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

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

Posted: Wed Dec 18, 2013 3:51 pm
by FourthWorld
If the goal is to reverse an image you might consider the flip command.

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

Posted: Wed Dec 18, 2013 5:34 pm
by Mark
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

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

Posted: Wed Dec 18, 2013 5:36 pm
by FourthWorld
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?

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

Posted: Wed Dec 18, 2013 5:44 pm
by Mark
Hi,

Currently, I can't think of many more applications besides imageData and Unicode. I'm fine with the title.

Kind regards,

Mark

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

Posted: Thu Dec 19, 2013 2:06 am
by [-hh]
..........

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

Posted: Thu Dec 19, 2013 2:50 am
by FourthWorld
[-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?

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

Posted: Thu Dec 19, 2013 12:43 pm
by Mark
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

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

Posted: Thu Dec 19, 2013 11:45 pm
by [-hh]
..........