Optimize short code.

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Walyx
Posts: 9
Joined: Wed May 13, 2020 1:11 pm

Optimize short code.

Post by Walyx »

Dear everyone, I wanted to make a Script in PS that goes through each pixel of the image. Take the hue of each pixel and then summarize by hue.
This would allow me to see what colors are in a photo and be able to show them in a graphic.
But it only takes a long time for these two "for" and I understand I couldn't do it with Script in Photoshop. Am I correct or would there be some way to optimize the code?

Code: Select all

var nAncho = app.activeDocument.width.value
var nLargo = app.activeDocument.height.value

for (var i = 0; i < nAncho; i++) {
	for (var j = 0; j < nLargo; j++) {
		pointSample.move([i,j]);
		// ...
		// some task
		// ...
	}
}
Best regards!

Walter
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Optimize short code.

Post by Kukurykus »

Walyx
Posts: 9
Joined: Wed May 13, 2020 1:11 pm

Re: Optimize short code.

Post by Walyx »

Thank you!
It sounds difficult, but I will try it :)
Walyx
Posts: 9
Joined: Wed May 13, 2020 1:11 pm

Re: Optimize short code.

Post by Walyx »

Hello, I modified the code of http://telegraphics.com.au/sw/product/CountColours so that it counts the amount of Hues.
It only works for 8bits and I think also only for Windows but well, it's something.

Question, how can I pass parameters from a Script to the Plug-in and then return them to the Script?

Thank you!

Walter
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Optimize short code.

Post by Kukurykus »

You may create .txt via plug-in where you store user inputs, then still by plug-in execute .jsx that's going to read data from text file.

btw did you use Bridge to read pixels?
Walyx
Posts: 9
Joined: Wed May 13, 2020 1:11 pm

Re: Optimize short code.

Post by Walyx »

Thanks Kukurykus!
I did not like the Bridge option because I wanted it to be something independent of another application. Some users may not have Bridge installed.

I thought that from the graph that I attached, there was a way to send parameters in filterSelectorStart and then take them from filterSelectorFinish.
PS Flow Filters
PS Flow Filters
PS-Plugin.jpg (50.49 KiB) Viewed 4163 times
I like your opinion but I prefer that the Plug-in is triggered by the Script and not the other way around.

Cheers!
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Optimize short code.

Post by Kukurykus »

I meant not plugin to create .txt with parameters, but .jsx to do it and then running plugin, that would read .txt and rerun script which would read changed (by plugin) .txt content (unless you used enviromental variables, so $.setenv & $.getenv to use instead of text file).
Walyx
Posts: 9
Joined: Wed May 13, 2020 1:11 pm

Re: Optimize short code.

Post by Walyx »

Thank you very much, I finally did it this way.
I generated a Plugin that writes to GetEnv ("Temp") and then the Script takes it from the same place.
If you want to try it, this is the Panel and the Plugin.
It only works on Windows, I have to try to make it work on Mac.

https://bit.ly/2ZLi3jZ (PlugIn)
https://bit.ly/2B8wqET (Panel)

The code is super sloppy, but hey, it does what I need.

Best, regards.

Walter