Params to Python external script?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Params to Python external script?

Post by jacque » Thu Jul 15, 2021 7:32 pm

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.
Attachments
scriptProfile-grayscale.txt.zip
(35.68 KiB) Downloaded 105 times
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 432
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Params to Python external script?

Post by Zax » Fri Jul 16, 2021 8:10 am

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.

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Params to Python external script?

Post by Bernard » Fri Jul 16, 2021 10:37 am

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

Code: Select all

repeat for each byte in x
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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Params to Python external script?

Post by jacque » Fri Jul 16, 2021 5:36 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Params to Python external script?

Post by Bernard » Fri Jul 16, 2021 7:26 pm

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Params to Python external script?

Post by jacque » Fri Jul 16, 2021 8:38 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Zax
Posts: 432
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Params to Python external script?

Post by Zax » Fri Jul 16, 2021 9:32 pm

jacque wrote:
Fri Jul 16, 2021 5:36 pm
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.
Oh yes, always copy text of long/complicated post before submit! ;)

Zax
Posts: 432
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Params to Python external script?

Post by Zax » Fri Aug 20, 2021 2:41 pm

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).

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Params to Python external script?

Post by Bernard » 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?

Zax
Posts: 432
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Params to Python external script?

Post by Zax » Thu Sep 09, 2021 8:14 am

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
screen.jpg

Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm
Location: London, England

Re: Params to Python external script?

Post by Bernard » Thu Sep 09, 2021 8:41 am

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.

Zax
Posts: 432
Joined: Mon May 28, 2007 10:12 am
Location: France

Re: Params to Python external script?

Post by Zax » Thu Sep 09, 2021 10:28 am

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.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”