Exporting transparent PNGs (again)

Mark Smith mark at maseurope.net
Wed Jul 5 06:13:10 EDT 2006


Chris, when I first came to Rev from HC, I also ignored the 'repeat  
for....' loop for quite a long time. Not anymore, though. It's so  
much faster that it's usually worth whatever extra code (counters  
etc.) that you need to put inside it. As you've found, it can make  
the difference between something being practical to do and not.

Just bear in mind that when you do:

repeat for each line L in someList
   doSomething with L

L is not to be changed, or you are messing with the loop variable,  
and will get 'unexpected' results, so a typical use might be

repeat for each line L in someList
   put L into temp                        -- copy L into a temporary  
variable
   add 4 to item 3 of temp          -- modify as desired
   put temp & cr after newList   -- store modified line in new list
end repeat
delete char -1 of newList        -- delete trailing cr from new list

There must be a huge number of loops that follow this basic theme in  
all the Rev made software out there.


Best,

Mark

On 5 Jul 2006, at 10:53, Chris Carroll-Davis wrote:

> Jim -
>
> I'm sure you are correct here.  I tried testing my loop against  
> Dave's.  On a small image my loop was 75 times slower than his.  On  
> a larger image that took about a third of a second with his  
> routine, I expected mine to take about 20 seconds... After 5  
> minutes I gave up!!!
>
> Chipp - your compositing stack is great - wish I'd seen it a few  
> days ago!
>
> With everyone's help I now have a first draft of handler that  
> correctly exports a transparent PNG of a field containing Japanese  
> text - just what I needed!  (And I've also learned a couple of  
> scripting lessons to boot - I had never used the "repeat for each  
> +var" syntax before!  Doh!  I am a SC dinosaur and I don't think SC  
> has this variant). Thanks so much.
>
> All I need now is a bigger brain.
>
>  - Chris
>
>
>
> On 5 Jul 2006, at 07:27, Jim Ault wrote:
>
>> The key maybe the
>>          repeat for each
>> which is a sequential access rather than
>>  'evaluate the access position each loop'
>>
>> I also think that the larger the data source, the slower 'repeat  
>> with x ='
>> becomes.
>>
>> Try these runs and see if the results are linear or exponential.
>>
>> get ( number of chars in imagedata of image "A1"/4)
>> repeat with n = 1 to it/10
>> repeat with n = 1 to it/5
>> repeat with n = 1 to it/4
>> repeat with n = 1 to it/2
>> repeat with n = 1 to it/1
>>
>>
>> Jim Ault
>> Las Vegas
>>
>> On 7/4/06 2:33 PM, "Chris Carroll-Davis" <asgg35 at dsl.pipex.com>  
>> wrote:
>>
>>> Dave -
>>>
>>> Thanks so much!  Yes, your routine is much faster than mine...  
>>> though
>>> I'm not sure why!!
>>>
>>> Here is my code:
>>>
>>> on mouseUp
>>>    put alphadata of image "black" into temp
>>>    put the milliseconds into tStart ## for speed calc
>>>    repeat with n = 1 to number of chars in imagedata of image "A1"/4
>>>      put char n*4 of imagedata of image "A1" into char n of temp
>>>    end repeat
>>>    put the milliseconds - tStart && length(tMaskData) ##speed score
>>>    set alphadata of image "black" to temp
>>> end mouseUp
>>>
>>> For some reason, even though my loop is only a quarter of the length
>>> of yours with just one line of code in it (and no decisions)  it is
>>> much slower.  It was slower still because I was (for daft reasons I
>>> wont go into!) originally doing the loop backwards.
>>>
>>> I'll try to tweak to improve speed further, but even as it stands I
>>> think it should be fine.
>>>
>>> Also, thanks Ken for the links.  They helped me understand what is
>>> going on now!
>>>
>>> Regards,
>>>
>>> Happy Chris
>>>
>>>
>>> On 4 Jul 2006, at 18:10, Dave Cragg wrote:
>>>
>>>>
>>>> I'm not sure what calculations you are doing in the loop, but it
>>>> sounds too slow. The following routine creates alphaData from a 300
>>>> x 300 grayscale image in less than a second on my not so fast
>>>> machine. (You'll probably need to substitute the calculation inside
>>>> the loop with your own.)
>>>>
>>>> I'm sure others will step up with faster alternatives. :-)
>>>>
>>>>
>>>> on mouseUp
>>>>
>>>>   put the imageData of image 1 into tImageData
>>>>   put the milliseconds into tStart ## for speed calc
>>>>   put 0 into tCount
>>>>   repeat for each char tChar in tImageData
>>>>     add 1 to tCount
>>>>     if tCount = 4 then
>>>>       put numToChar(255 - charToNum(tChar)) after tMaskData
>>>>       put 0 into tCount
>>>>     end if
>>>>   end repeat
>>>>   put the milliseconds - tStart && length(tMaskData) ##speed score
>>>>   set the alphaData of image 1 to tMaskData
>>>> end mouseUp
>>>>
>>>> Cheers
>>>> Dave
>>>> _______________________________________________
>>>> use-revolution mailing list
>>>> use-revolution at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>>
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your  
>>> subscription
>>> preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the use-livecode mailing list