Image Processing Makes Livecode Appear to Crash

Paul Dupuis paul at researchware.com
Mon Feb 17 16:41:03 EST 2014


No ideas on speeding it up. The only thought looking at the code is you
may want to replace 'char' with 'byte' ( and numToChar with numToByte)
since you are really dealing with bytes rather than characters and in
future LiveCode versions, char may not always correspond to a single byte.

I might suggest avoiding the delete operation and just try indexing the
imageData and alphaData

put the number of bytes in totAlphaData into tLoopSize
repeat with i=1 to tLoopSize
  if byte (i*4-2) to (i*4) of totColorData = binColor then put bin0 into
byte i of totAlphaData -- else byte i remains as is
  set cursor to busy
  wait for 0 milliseconds with messages
end repeat
set the alphadata of img 1 to totAlphaData

On 2/17/2014 3:16 PM, 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?
>
> 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
>

-- 
Paul Dupuis
Cofounder
*Researchware, Inc.*
http://www.researchware.com
http://www.twitter.com/researchware
http://www.facebook.com/researchware
http://www.linkedin.com/company/researchware-inc
https://plus.google.com/+Researchware/
<http://plus.google.com/+Researchware/>




More information about the use-livecode mailing list