Image Processing Makes Livecode Appear to Crash

Alex Tweedly alex at tweedly.net
Mon Feb 17 16:40:08 EST 2014


On 17/02/2014 20:16, Ray wrote:
> That works great!  And a little experimenting shows that waiting 0 
> milliseconds accomplishes the same goal without significantly slowing 
> down an already slow handler.  Not to sound greedy but you wouldn't 
> also have any idea how to speed up this loop would you?
>

Sure, but I haven't been able to test (and I'm not sure I exactly 
understand what it's doing), this is simply typed straight into email - 
so at your own risk ....

replace

  repeat for each char curBin in totAlphaData
       if char 2 to 4 of totColorData = binColor then
          put bin0 after newAlphaData
       else put curBin after newAlphaData
       delete char 1 to 4 of totColorData
       set the cursor to busy
    end repeat

with
  put 2 into tStart
  repeat for each char curBin in totAlphaData
       if char tStart to (tStart+2) of totColorData = binColor then
          put bin0 after newAlphaData
       else put curBin after newAlphaData
  -- -- --     delete char 1 to 4 of totColorData
       add 4 to tStart
       set the cursor to busy
    end repeat

This avoids the deleting of chars which is (very) expensive because it 
moves all the rest of the data.
Although you often see the advice to avoid "counting" chunks, in this 
case it's OK because indexing by char is fast; it's really counting 
lines, items or words that is so expensive.

If I get time later tonight, I'll test this version (and also try out 
something else that might be even faster).


-- Alex.
> Thanks,
>
> Ray
>
> On 2/17/2014 2:57 PM, Paul Dupuis wrote:
>> Ray,
>>
>> Is this behavior (title bar saying "not responding", etc.) happening
>> under Windows 8 perchance?
>>
>> If so, we've seen the same or similar behavior under Windows 8 in long
>> repeat loops. We've found that including a "wait for 1 millisecond with
>> messages" line in the loop and this mostly lets Windows think the
>> application is in fact responding. I say mostly because if you watch the
>> task manager, the app switches between "not responding" and responding
>> (i.e. no note next to the name) with some regularity. Without the "wait"
>> statement in the loop the app is listed in the task bar continuously as
>> "not responding" while the loop is executing.
>>
>> Paul Dupuis
>> Researchware
>>
>> On 2/17/2014 1:24 PM, Ray wrote:
>>> Fellow LC Users,
>>>
>>> I'm trying to provide users with a 'magic wand' style tool. Click an
>>> image, pick up the color clicked and turn every pixel of that same
>>> color in the image transparent.
>>>
>>> The loop I've written takes about 30 seconds to run on a 600 by 700
>>> pixel image, which is a problem, but worse, click anywhere before it's
>>> finished and Livecode 'appears' to crash.  I say 'appears' because the
>>> cursor turns into the crash cursor and the title bar displays 'not
>>> responding'.  After the loop is done Livecode returns to normal.
>>>
>>> I'll include the loop, below.
>>>
>>> How do I stop LC from appearing to crash while running this loop, or
>>> how to speed it up.
>>>
>>> Thanks,
>>>
>>> Ray
>>> LinkIt! Software
>>>
>>> on mouseUp
>>>     lock messages
>>>     put the mousecolor into myColor
>>>     put the mouseloc into myLoc
>>>     put the imagedata of img 1 into totColorData
>>>     put the alphadata of img 1 into totAlphaData
>>>     put numToChar(item 1 of myColor) into binColor
>>>     put numToChar(item 2 of myColor) after binColor
>>>     put numToChar(item 3 of myColor) after binColor
>>>     put numtochar(0) into bin0               -- transparency
>>>     repeat for each char curBin in totAlphaData
>>>        if char 2 to 4 of totColorData = binColor then
>>>           put bin0 after newAlphaData
>>>        else put curBin after newAlphaData
>>>        delete char 1 to 4 of totColorData
>>>        set the cursor to busy
>>>     end repeat
>>>     set the alphadata of img 1 to newAlphaData
>>> end mouseUp
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your 
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your 
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list