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
Add integrated support for writing PhotoShop layered PSD files #240
Comments
@lamdalili FYI |
…ts.PSD.* TPsdBuilder and TCustomPsdLayer is now TPhotoshopDocument and TCustomPhotoshopLayer. PSD read/write functionality has been decoupled from PSD model classes. Refs #240
First: Thank you for all your hard work on this. I recently looked into the new saving/loading mechanism and it is amazing. I struggle using streams instead of files though. So, with regards to the examples already in the repo and with creating these examples that you are creating for PSD. Is it possible with the new mechanism, to receive "any" stream and load it as a TBitmap32 with Graphics32 without knowing what format it is? Further, if I have a Bitmap32, it would be awesome if the examples would contain something how to write in a certain format to a stream - again, without using files. I always had to look for alternatives to TPicture, for example, as its mechanism is based on file extension which fails with streams and you need to know the concrete file format. Especially, in web times when people can "upload" multiple formats, it would be great if Graphics32 offered a solution. Back in the early 2000s, I used GraphicEx as that determined file formats using the header of a file or stream. I would be great if the new examples answered these questions as I am sure I am not the only one having these issues. I would gladly participate to create these, but right now, I simply do not know how. Thank you and I hope you don't mind that I chime in here. But it seemed the right place to comment as you are working on a new format and it could be included at some point in this process. |
Yes;
I think that might be too specialized for the examples, but it's really easy though. If you look in I have considered extending the image format registration system to also support registration against mime type. It just doesn't "feel" right to have to use file types when no files are involved.
Not at all. I guess I could enable the repo discussion section. I've never used it. |
Thank you for your reply. I have actually tried finding my way into this and maybe a description why I was not able to proceed can help others. My difficulty was to get a list of all registered writers, readers and their associated file extensions. I was able to iterate all the writers and readers. You have an excellent architecture there. However, the reference to the interface then did not allow me to "print" the file extension. I guess, I am missing the base interface type of all the writers or readers that feature these attributes. With Delphi 11 code navigation in the state it is in right now, I was not able to find my way to the correct type. |
Once you have a reader or a writer you can query it for the
Originally I had |
An other task to add to the todo list :
The example shows how to export a |
The initial code was written based on abstract TStream to work on any stream, but then I saw the operation is very slow when using TFileStream so I had to force the use of TMemoryStream. |
Yes, I noticed that some of the alignment values didn't quite match the specs. This is probably the reason some of the readers complain about the file format but still manage to load the files.
It should be possible to handle that within the current framework. It's just not built in out-of-the-box and I think it's a reasonable limitation. Very little code would be required to implement it but since it is impossible to cover all cases I don't think we should even try (with the standard functionality I mean).
Holger is talking about the Image Format Adapter framework in general.
Yes, and I removed that and made it work with the generic TStream API. That way you can use any stream type you like. Not just TMemoryStream. |
…ough. Added PSD Image Format Adapter. TPhotoshopDocument is now assignment compatible with TCustomBitmap32. Refs #240
…er (the TBitmapLayer base class) Refs #240
I'm not sure I understand your code but are you sure changing channels order is supported by all readers ? I think
|
The purpose of that constant is to handle the difference in source channel order on different platforms. For example, on Windows, the channel order inside a
Yes, as far as I can tell from the specs, the background (i.e. the Image Data), isn't optional but I think it's nice that one doesn't have to supply a background source layer. Since it's mandatory how can
I had that thought too but as far as I can tell, the background must have the size of the image so it cannot be a thumbnail.
Sure. I'm not sure what you're arguing here. |
Fixed. I've completely rewritten the PackBits encoder. |
In PSD the IDs of the channels are placed in Layer Record their order fixes the storage order of the channels, in theory it's possible to mix them (ID) as you want this has no effect since each channel has its ID (-1, 0, 1, 2) . |
If you want more compatibilty you should put the final renedring in the image, a simple appli can skip easily to the last section and load the final image decompress it without have to repruduce all complex features. |
Yes, but the same isn't true for the Image Data (what you call the background):
If a background layer/bitmap is included in If you are arguing that the background should somehow be mandatory in the PSD object model layer ( |
I think we're just about "feature complete" with regard to PSD write support. The remaining tasks are nice-to-haves that can be implemented at a later stage. I will create a pull request for the PSD branch but I will leave this issue open until the remaining tasks have been implemented or rejected. I expect to merge the PR in a few days unless there are objections. |
Photoshop app uses that name , if you think it's wrong to call it so, you're free to correct it.
I've done some tests with this new code, and compared with previous: I removed the jpg image from the test since compressed to avoid confusion |
No, it's fine. I do think it's pretty misleading but I don't really have a better term to use. FWIW, it's called the Image Data in the specs.
That's strange. Theoretically, it should compress better. I did a lot of tests and never once saw the size increase. |
Potentiel bug in graphics32/Source/GR32.ImageFormats.PSD.pas Line 461 in 89b9c21
As I know transparency tiles are painted to mark presence of alpha channel, and reseved for purly internal use and shouldn't be painted in the external Bitmap32 : I think it's important to disable |
Moved to #247 |
…n alpha-transparent background. Refs #240
I'll merge the PR to master tomorrow evening (Tuesday, CET) unless there are objections. |
The current |
Yes, that makes sense. |
Fixed. |
The problem is that PhotoShop ignores alpha channel in the background and displays it as solid image , the scan need also detect presence of any blending value (alpha <> 255) if so the Bitmap should be exported as PSD layer regardless of the Image32 is layred or not. |
Yes. That's how I've implemented it now. It turned out that Photopea ignored the background even if the image didn't contain layers; An image with a background but no layers just displays as an empty, black bitmap. |
That works great! I also check if the file format that I enumerate supports it because not all do.
Compiler optimization because I do not use any of the classes?! Because JPEG is also missing. |
Yes. It got merged a few days ago.
Only the ones you listed are included by default (see the To include more formats just add their units to a |
Just thinking out loud here... could we create a unit that contains uses for all available file formats? Kinda what happens when you drop a certain component on the form with FireDAC that just adds units into the binary. So, we could add that unit and all file formats would be included. Obviously, I could create that myself for my project as well, but this way it would be part of GR32. |
Yeah, well, I'm not too thrilled about that idea. I'm also not seeing a good use case for this. Personally, I would prefer to have fewer file formats included by default than is the case now. For example how often do you need to load a TIFF file nowadays? And what about wmf, emf, ico, rle and dib? Unless you're writing an image editor I don't really think there's much need for these or that the typical end-user even knows what they are. Finally, the VCL |
I was just seeing the consumer side too much. I agree it is fine if somebody wants to "use all", they can just add all the units. No argument here. I stand corrected. |
Based on the PSD Export example from #239 standard functionality should be added for writing PSD files.
The PSD files should be layered when created from
TCustomImage32
(with layers) and non-layered when created fromTBitmap32
.Tasks
TCustomImage32
with layers.TCustomImage32
without layers.TBitmap32
.IImageFormatLayeredWriter
, for use byTCustomImage32
.The prediction algorithm is the same as the one described in Adobe Photoshop TIFF Technical Note 3. Basically, delta-encode each channel and then zip that.
Se also:
Some of these tasks are already covered by the existing PSD Export example. The functionality simply needs to be refactored into the existing framework.
The text was updated successfully, but these errors were encountered: