Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing down PSD files #1

Open
kvark opened this issue Feb 28, 2019 · 5 comments
Open

Writing down PSD files #1

kvark opened this issue Feb 28, 2019 · 5 comments

Comments

@kvark
Copy link

kvark commented Feb 28, 2019

In https://github.com/kvark/vange-rs project, we faced an unexpected problem. We wanted to export the level data for modders to play with, and then import back. The data of the level is somewhat strange:

  • it has 3 byte channels and 2 half-byte (4-bit) channels
  • resolutions are like 16K by 2K

Apparently, there is no existing open format to support that. We tried TIFF and faced the lack of proper support on both GIMP and Photoshop sides. It would be very convenient if we could export/import a PSD (without losing the data) for this - at least Photoshop would be guaranteed to work.

@chinedufn
Copy link
Owner

Thanks for opening this issue!

So, I'm assuming that you want to export to an image format so that modders can use a regular old image editor to mod levels?


So, there are 4 bytes of data per tile if I'm understanding correctly. Would it be alright to store them in RGBA in a single layer (with the alpha channel holding the two half-byte channels)?

Or would it be better to have 5 layers, one layer per channel? This is more of a UX question as I'm not sure how people intend to mod levels and what would make the most sense visually.

(5 layers would be bigger since there would be extra channels for each layer, but they'd be compressed so would need to think about / investigate how much of a difference this would make size-of-file wise)


Thanks for clarifying!

@kvark
Copy link
Author

kvark commented Mar 1, 2019

So, I'm assuming that you want to export to an image format so that modders can use a regular old image editor to mod levels?

As I mentioned, there isn't many image editors supporting multiple layers. If the users are able to use Photoshop, that's already a win for us.

Would it be alright to store them in RGBA in a single layer (with the alpha channel holding the two half-byte channels)?

No, we already have that in other formats. It's very inconvenient for the users to than decode those 4-bit channels.

Or would it be better to have 5 layers, one layer per channel?

Yes. Preferably, in fixed order and/or named.

@chinedufn
Copy link
Owner

chinedufn commented Mar 2, 2019

Thanks!

Alright - to make sure that I fully understand the use case - would the following rough sketch meet your needs?

use psd::{Psd, PsdLayer};

fn main () {
  let mut psd = Psd::new(16000, 2000); // width, height
  
  let channel_1 = vec![0; 16000 * 2000];
  let channel_2 = vec![0; 16000 * 2000];
  // ... same for all 5 channels ...

 let mut layer_1 = PsdLayer::new("First Channel");
 layer_1.set_red(channel_1);
 let mut layer_2 = PsdLayer::new("Second Channel");
 layer_2.set_red(channel_2);
  // ... same for all 5 channels ...

 let mut psd_file: Vec<u8> = vec![];
 psd.write(&mut psd_file);
}

Then you'd end up with a PSD with 5 gray layers (layers with only one channel show up as gray in Photoshop).

Well in this specific example they'd be black ... but I mean in a real use case ..

EDIT - I did some experimenting and a PSD is grey when the color type of the psd is grayscale. A grayscale image can have 2 channels if it's 16bit.

@kvark
Copy link
Author

kvark commented Mar 2, 2019

Yeah, that would likely work for us 👍

@chinedufn
Copy link
Owner

Awesome!

I'll take some stabs here next time I'm working on psd (which will likely be whenever it breaks for me).

Thanks for explaining!

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

No branches or pull requests

2 participants