Exporting transparent PNGs (again)

Alex Tweedly alex at tweedly.net
Tue Jul 4 17:53:03 EDT 2006


Chris Carroll-Davis 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.
>
Two obvious possible reasons .... and probably more that I didn't 
immediately see.

1. I suspect taking the imagedata of the image may take some time, so 
instead of

  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

I would have done
   put the imagedata of image "A1" into tImageData
  repeat with n = 1 to number of chars in imagedata of image "A1"/4
    put char n*4 of tImageData into char n of temp


2. Putting a value into  "into char N of tVar" happens quickly - but 
slower that putting "after tVar"
so I'd actually make that central line be
    put char n*4 of tImageData after temp

This might still be slower than the other method, because "repeat for 
each char ..." is very fast - possibly fast enough that going around the 
loop 4 times as often beats the cost of accessing "char N*4"



-- 
Alex Tweedly       http://www.tweedly.net



-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.9.8/380 - Release Date: 30/06/2006




More information about the use-livecode mailing list