• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to draw pixel data into a layer from Generator

Community Beginner ,
Mar 07, 2016 Mar 07, 2016

Copy link to clipboard

Copied

Hi,

How might one draw arbitrary RGBA data into a layer?

Are there any APIs that do this directly? If not, I'm guessing one could go through the target area, selecting each pixel and then doing a fill operation with the required color - or maybe draw each pixel with the pencil tool, etc. Is there some standard way of doing such things? I'm guessing people must have needed to do this, but I couldn't find any discussion or code samples.

If the use case isn't clear, I'm calling generator.getPixmap on a layer, then I modify the data and want to draw the results into a different layer. This is via generator, so either generator code or JSX would work (though generator APIs would be a lot easier to work with).

Thanks!

TOPICS
Actions and scripting

Views

1.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Mar 10, 2016 Mar 10, 2016

Hi, it's weird it didn't worked, maybe it's because of the progress bar, I know that sometimes it crashes Photoshop when you have a palette window... I've tested the script with the latest CC version on Windows and it worked fine... Anyway you can do that effect you want directly in Photoshop and with interactivity as well. I've created a screen on how I've done it:

forAndyHall.jpg

This way when you change the smart object it will automatically update the threshold margins. All you need to be careful is to not h

...

Votes

Translate

Translate
Adobe
Contributor ,
Mar 07, 2016 Mar 07, 2016

Copy link to clipboard

Copied

I don't think there is a way do do that directly... but you can just save the pixmap as png then just open that file in photoshop.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 07, 2016 Mar 07, 2016

Copy link to clipboard

Copied

I know data can be saved into files. I'm looking for a way to draw into a layer.


Thanks for any further ideas!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 09, 2016 Mar 09, 2016

Copy link to clipboard

Copied

Ok I see but you have to know that this will take a long time, probably more then just saving it as png and opening. I've created a .jsx script that make's a new layer from a pixmap sent from generator.

http://www.mediafire.com/download/yf765a70k75vcec/makeNewLayerFromPixmap.jsx

and in generator you just need to use:

_generator.evaluateJSXFile("pathToTheScript/makeNewLayerFromPixmap.jsx", pixmap);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 09, 2016 Mar 09, 2016

Copy link to clipboard

Copied

Hey, thanks for writing out a full script. Unfortunately when I try calling it, PS hangs until I force-quit, even for a tiny 10x10 pixel image. This is on OSX, newest PS. Not sure what might be going wrong.

With that said, from how slow you say it will be, maybe what I'm trying to do is impossible. I am basically trying to achieve the effect described in this thread:

Apply a threshold-style effect to a layer's transparency

My thinking was, if it can't be done with built-in PS features, I could write a generator extension that gets a pixmap of a source layer, runs through the RGBA data applying a threshold to the alpha values, and then writes the result into a target layer. The goal is to be able to see the results of the threshold as you work.

Anyway I'm getting the idea that "drawing into layers" basically isn't a supported thing to do with generator. If you have any other ideas please let me know though!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

Hi, it's weird it didn't worked, maybe it's because of the progress bar, I know that sometimes it crashes Photoshop when you have a palette window... I've tested the script with the latest CC version on Windows and it worked fine... Anyway you can do that effect you want directly in Photoshop and with interactivity as well. I've created a screen on how I've done it:

forAndyHall.jpg

This way when you change the smart object it will automatically update the threshold margins. All you need to be careful is to not have a black with the brightness of 0 in your color. You can have it with a value of 1 instead.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

Wow, thanks so much! That's basically what I needed to do, and gets me out of having to mess with Generator.

One small detail - maybe I'm missing a setting, but in your example the edges of the bottom smart layer blend a little with the "Color Fill 4" layer, right? (It will be more obvious with a lower threshold.)  In order to avoid this I found that I needed to make 3-5 copies of the lower smart object layer, to make the edges opaque. Or am I missing a setting?

Still though, this really solves my problem, so glad you took the time! Thanks a ton!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

Oh and by the way, if you can paste your image into that other thread I linked, I'll go mark it as the correct answer there. It might help someone in the future.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 10, 2016 Mar 10, 2016

Copy link to clipboard

Copied

I'm glad I could help, I will put the image in the other thread...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 22, 2017 Aug 22, 2017

Copy link to clipboard

Copied

LATEST

In case somebody is still interested in a "native" solution, well there's no setPixmap function (yet), but I've formally logged a feature request for it to the Photoshop/Generator team – I'll keep this post updated if/when I've news.

As a side note, a proper setPixmap would open the doors to JS image processing – e.g. a context where an HTML Panel can deal with a stream of bits (that is to say, the V8 engine of CEF and not the ExtendScript virtual machine, for I suspect ExtendScript wouldn't be as good as V8). It won't be incredibly fast in terms of performances compared to a native C++ plugin, but to bypass the steep learning curve of actual C++ plugins is a very missed option.

Davide

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines