Skip to content

Implemented saving pixmap with 1 or 3 channels#268

Open
marekhrabe wants to merge 1 commit intoadobe-photoshop:masterfrom
marekhrabe:one-channel-pixmap
Open

Implemented saving pixmap with 1 or 3 channels#268
marekhrabe wants to merge 1 commit intoadobe-photoshop:masterfrom
marekhrabe:one-channel-pixmap

Conversation

@marekhrabe
Copy link
Copy Markdown
Contributor

Only place that needed change was the convert implementation, other things look ready. I tested with "synthetic" pixmaps like this one:

var pixels = new Buffer(400);
pixels.fill(0xcc);

var pixmap = { format: 2,
  width: 20,
  height: 20,
  rowBytes: 20,
  colorMode: 1,
  channelCount: 1,
  bitsPerChannel: 8,
  pixels: pixels,
  bytesPerPixel: 1,
  bounds: { top: 0, left: 0, bottom: 20, right: 20 }
};

generator.savePixmap(pixmap, 'pixmap.png', { format: 'gif', ppi: 72 });

This should make it easier to implement mask support as discussed in #161 (comment)

I tested output to png, gif and jpg and all seems working perfectly.

@joelrbrandt
Copy link
Copy Markdown
Contributor

@marekhrabe Thanks for this. The bad news is that I think what @timothynoel is proposing is building the low-level pipeline to send single-channel images over the connection between PS and Node. That'll require a decent amount of modification to both the native side and lib/photoshop.js.

Nonetheless, this PR will be useful for writing single channel images to disk. So, I'm going to keep this open until we're ready on the native side. Once again, we appreciate your help!

@marekhrabe
Copy link
Copy Markdown
Contributor Author

@joelrbrandt I've inspected lib/photoshop.js, but I haven't found a thing that will not support single channel image. Is there any?

All lib/photoshop.js does is that it emits raw pixmap that it got (without any logic or checks I think) and Generator.prototype.getPixmap passes it into xpm.Pixmap (which can already handle 1, 3 or 4-channel pixmaps). I do not understand all the architectual decisions, but for me it seems like when generator receives valid 1-channel pixmap (mainly channelCount and bitsPerChannel), it can handle it just fine.

@joelrbrandt
Copy link
Copy Markdown
Contributor

@marekhrabe Admittedly, I was a bit cavalier when I was trying to rush through all my replies yesterday. 😄

I'd love it if it "just works" from the PS communication perspective -- I hope you're right. However, my fear is that there'll be some mismatch between PS's 1-channel format and the 1-channel format that the xpm code expects. (e.g. the 1-channel code from PS might not have the same header structure -- it might just be a raw stream of pixels) But, maybe not!

Independent of that, though, is the fact that rewriting the pixmap pipeline to be streaming is very high on our backlog. That means we'll throw out the xpm code we have and write new code to transcribe the stream from PS into a stream that convert can accept. We'll need different paths for 3-channel and 1-channel in that case.

Anyway, thanks again for your input! And, certainly, the code in this PR will be useful when @timothynoel wires up 1-channel pixmaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants