Page 3 of 3
Re: Params to Python external script?
Posted: Thu Jul 15, 2021 7:32 pm
by jacque
Zax wrote: Thu Jul 15, 2021 7:27 am
@
Jacqueline: as I don't have the Business edition, could you please test
button "GreyTranspa" of card "Main" with the Script Profiler? It's for me the fastest process.
That one is the fastest in the profiler too. I'll attach the text file so you can see the results yourself. The handlers are listed in order of speed results, I believe.
Re: Params to Python external script?
Posted: Fri Jul 16, 2021 8:10 am
by Zax
Thank you very much Jacqueline
Your very accurate results confirm that, in that script,
repeat for... step 4 is the fastest solution.
@
Bernard: I tried
byteToNum() and it's indeed a little bit faster. Thanks for the tip!
Though, there is still a very strange thing that I really don't understand.
Zax wrote: Wed Jul 14, 2021 8:34 am
when commenting line 119 "
put ntcGray & ntcGray & ntcGray into char (tImgPosition + 2) to (tImgPosition + 4) of tImage", process takes 13000 ms! I don't understand why
not modifying the imageData takes longer!
I don't need to modify
imageData: if I comment the following line
Code: Select all
set the imageData of image pixDestName to tImage
and only set a new
alphaData, the result is good.
Maybe I don't well understand how imageData and alphaData work in internal.
Re: Params to Python external script?
Posted: Fri Jul 16, 2021 10:37 am
by Bernard
It bothered me that I was seeing results that made no sense. Zax has found an anomaly.
Code: Select all
repeat with i = 1 to the number of bytes in x step 4
(where in the loop bytes i+1, i+2, i+3 are then addressed - so this is NOT just a question of the size of x being x/4)
is faster than
but only when "step 4" is used. I guess someone who knows the innards of LC better than me would have an explanation.
Bernard wrote: Thu Jul 15, 2021 11:02 am
I spent a lot of time running tests and writing the results here. When I went to post, the stupid forum software/setup demanded I login again. I did so and all my work was lost.
What kind of design trashes a user's work like that?
My tests revealed lots of contradictory results (some back up Zax claims and contradict Jacque's profiling, others back up my expectations). I really can't be bothered to spend more of my time on this when the forum is so badly designed.
Code: Select all
repeat for each ... byteToNum() 3,108 ms
repeat for each... charToNum() 3,356 ms
repeat with ... the number of chars... charToNum() 25,631 ms
repeat with ... the number of bytes in... byteToNum() 3,169 ms
Re: Params to Python external script?
Posted: Fri Jul 16, 2021 5:36 pm
by jacque
I don't know how it works internally either but when using "step" it seems to act like "for each". That makes me think that step has to set a pointer in order to count each step, which is what "for each" does too. But we'd need someone who can read the source code to verify.
BTW, I've lost posts too in the past. I learned to either copy my text to the clipboard before leaving the page, or save a draft if I won't be back for a while.
Re: Params to Python external script?
Posted: Fri Jul 16, 2021 7:26 pm
by Bernard
Code: Select all
when using "step" it seems to act like "for each"
I don't think that's it, as in my experiments it is
only with step 4.
Still, I'm glad that I kept going until I had an explanation, even if it doesn't help Zax with his problem.
Re: Params to Python external script?
Posted: Fri Jul 16, 2021 8:38 pm
by jacque
Bernard wrote: Fri Jul 16, 2021 7:26 pm
I don't think that's it, as in my experiments it is
only with step 4.
Okay, that's weird. I have no clue.
Re: Params to Python external script?
Posted: Fri Jul 16, 2021 9:32 pm
by Zax
jacque wrote: Fri Jul 16, 2021 5:36 pmBTW, I've lost posts too in the past. I learned to either copy my text to the clipboard before leaving the page, or save a draft if I won't be back for a while.
Oh yes, always copy text of long/complicated post before submit!

Re: Params to Python external script?
Posted: Fri Aug 20, 2021 2:41 pm
by Zax
Finally, I wrote a little Python script to process images with
Pillow library. It works fine and it's very fast
At the start of the project, I didn't want to use a library that required be be installed deeply in the core of the OS but I recently realized that it was possible to use the Pillow library placed in any folder once it has been unzipped, so I put the Pillow folder inside my standalone folder.
If one is interested, I can post my Python script (at this time, it has only been tested on Mac: I think it requires some little modifications to work on Windows, concerning file pathes. Of course, Python have to be installed in the OS (it is pre-installed on MacOS, as PHP).
Re: Params to Python external script?
Posted: Wed Sep 08, 2021 4:33 pm
by Bernard
I'm glad it works. I guess you are writing the image out to a file then having Python process the file?
Re: Params to Python external script?
Posted: Thu Sep 09, 2021 8:14 am
by Zax
Bernard wrote: Wed Sep 08, 2021 4:33 pm
I'm glad it works. I guess you are writing the image out to a file then having Python process the file?
Yes, something like that: instead of reading the image file with LC, I send its file path to Python. Python loads the image, modify it, save modified image as temporary file and returns this temporary file path to LC, in order to display the modifed image in a stack.
I was able to finalize this stack:
viewtopic.php?f=7&t=35908
Re: Params to Python external script?
Posted: Thu Sep 09, 2021 8:41 am
by Bernard
That's cool. Scott Raney, the man behind Metacard (the origin of Livecode), used to often cite Metacard as superior to Tcl. Tcl was famously conceived of and known as "a glue language", designed to coordinate/integrate input/output of other programmes.
Re: Params to Python external script?
Posted: Thu Sep 09, 2021 10:28 am
by Zax
The way LC is opened to Applescript, shell and Python is very very convenient

I suppose building externals widely extends LC but I'm not skilled enough to build such things.