Copy link to clipboard
Copied
Hello,
i just started to develop a Photoshop plugin / script.
i try to get all colors in a pixel row and compare them.
my problem is to get the information what color is on pixel 0|0, 0|1, 1|1 and so on.
i have found two solution for that:
a. save the file in raw format and read every pixel out of the file
b. add a color sampler and move it throw the image
both solutions are every slow and took 2-5 minutes to get throw the hole file with a image of 200 x 200 pixels.
is there any smarter solution for this?
i hope anybody can help me
best regards
alex
Copy link to clipboard
Copied
I tried the same basing on experts attepmts and it always took few minutes for even not so big images to read all single px.
And I'm not talking of slow graphics process with using color sampler, but reading not opened file, so outside of Photoshop.
Copy link to clipboard
Copied
You should create custom plugin in C++
All fast things in Photoshop uses C++
Copy link to clipboard
Copied
Hello Jarda,
could you give me a tutorial how to develop custom plugins in C++ ?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Quite a steep learning curve 🙂
Copy link to clipboard
Copied
In SDK examples... there should be "hidden" filter plugin. Hidden because you can control it only with scripting. And according description... there should be option read/write pixels in channel. But I am not exactly sure how script should look.
Copy link to clipboard
Copied
do you know how to call a selfmade c++ plugin?
i have now a working VS2015 Solution and can debug the samples
but, i dont know :
1. how to execute my plugin function in Javascript
2. how i can change the settings if a plugin. change the display name or change the location where the menu item will be
oliverIntergrafika​ i will try this out, when this way the performance is not so bad, i can complete my work without c++ stuff 🙂
Thanks for all answers so far
Copy link to clipboard
Copied
Actually I didn't try that long time so I thought that takes longer time (for bigger documents for sure). But if you say that is 2 - 5 minutes for 200 * 200 pixels then your method is the worst there exists. This code for same document works one-forth s.
#target bridge
reading(new BitmapData(new Thumbnail(File
(fle = Folder.desktop + '/File.jpg' )).spec, true))
function reading(v) {
for(r = [], j = 0; j < v.height; j++) {
for(c = [], i = 0; i < v.width; i++) {
c.push(new Color(v.getPixel(i, j)).toString())
if (i == v.width - 1) r.push(c)
}
}
(txt = File(fle.slice(0, -3) + 'txt')).open('w' )
txt.write(r.toSource()), txt.close()
}
Copy link to clipboard
Copied
Works good.
But how to call this function from Photoshop and post data from Bridge to Photoshop?
I think there should be "Bridge" class which can comunicate between aplications?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
If You are using a HTML panel, with a generator instance inside, you can fetch the pixmap of the layer. This is a raw array or RGBA pixels. From this point only the chromium V8 is the limit.
generator-core
line: 1045
It is possible to avoid an npm install generator-core and use only the
executeAction(stringIDToTypeID("sendLayerThumbnailT0oNetworkClient"), actionDescriptor, DialogModes.NO);
as seen in: generator-core
but this is much more laborous approach because You have to estabilish a socket connections yourself.
Copy link to clipboard
Copied
oliverIntergrafika the problem is setPixmap (which doesn't exist – I've logged a feature request in the past...)
Davide
Copy link to clipboard
Copied
Davide_Barranca​ he wants to get the pixels not write them as I see. But You are right: a .setPixmap( pixMap ); would be awesome. This method would open up a new world. I really don't understand these emoji, touchbar, animated tool help and colorful svg font updates, when the whole underlying scripting architecture is in ruins.
Copy link to clipboard
Copied
There is documentation in SDK how to make plugin scriptable. I can't help you because it is not my skill yet.
Copy link to clipboard
Copied
I think we don't need "new Thumbnail" so without this it could be even faster.
#target bridge
var fle = new File(Folder.desktop + '/myImage.jpg' );
reading(new BitmapData(fle, true))
function reading(v) {
for(r = [], j = 0; j < v.height; j++) {
for(c = [], i = 0; i < v.width; i++) {
c.push(new Color(v.getPixel(i, j)).toString())
if (i == v.width - 1) r.push(c)
}
}
(txt = File(fle.toString().slice(0, -3) + 'txt')).open('w' )
txt.write(r.toSource()), txt.close()
}
And there is more things to optimize 🙂 But this is good for demontration purposes.
Copy link to clipboard
Copied
I moved second push beyond inner for. Now script does not check each time is a row finished but does it only at its end. So now it's faster. I updated also second push of a code that make script slower but let users to see more readable result in .txt.
#target bridge
gT = new Date().getTime()
reading(new BitmapData(File(fle = Folder
.desktop + '/BitmapData.jpg' ), true))
new Date().getTime() - gT
function reading(v) {
for(r = [], j = 0; j < v.height; j++) {
for(c = [], i = 0; i < v.width; i++) {
c.push(new Color(v.getPixel(i, j)))
}
r.push('\r\r' + (j + 1) + ': ' + c)
}
(txt = File(fle.slice(0, -3) + 'txt'))
.open('w'), txt.write(r), txt.close()
}
Another one is what you asked (with better performance, so with no special constraction in second push, but made a way it worked faster). Anyway create some small document 25*25 pixels (just to see result in no time as dialog drawing process in Photoshop is slow) and save on your desktop as BitmapData.jpg. Then run script from Photoshop. It is going to connect Br and send back array of pixel colour values that will be displayed in alert box. It's to show it can be stored by Ps in variable.
#target photoshop
function colors(v) {
function reading(v) {
for(r = [], j = 0; j < v.height; j++) {
for(c = [], i = 0; i < v.width; i++) {
c.push(new Color(v.getPixel(i, j)).toString())
}
r.push(c)
}
return src = r.toSource()
}
reading(new BitmapData(File(fle = Folder.desktop
+ '/BitmapData.jpg' ), true)); return src
}
(bt = new BridgeTalk()).target = 'bridge'
bt.body = 'colors = ' + colors.toSource() + '; colors()'
bt.onResult = function(v) {return res = v.body} bt.send(2)
alert(res)
Copy link to clipboard
Copied
Not bad 😉
Bridge must be opened in advance. Most time consuming is rendering of huge "alert" 😄
Otherwise I have 500ms for 200×200px image
Copy link to clipboard
Copied
Yes with this demonstrative example Bridge has to be opened in advance. I didn't make it more professional way, but it's not hard after all if needed to check is Bridge running and wait it is ready to wrok. It is all about goal this script can be used for...
Copy link to clipboard
Copied
Can
$.memCache
affect performance if you set bigger value?
Copy link to clipboard
Copied
I don't know this term, where is some documentation I can read more about? Is it undocumented Bridge / Photoshop thing?