
A simple host application for testing the API. Main window: Drag'n'drop a PSD file, select which layer to inspect (or Global for the merged image and global data).

XML inspector: For viewing all data in the document. Shows info about the selected layer or global info.
Introduction
This is a work in progress that aims to give .NET developers full control over Photoshop PSD files. All features aren't covered by the library, and there are, without doubt, some documents it will choke on, but with good feedback from users, this will hopefully be fixed over time.
The main usage of the API is for reading and writing PSD files from your own applications. It can also be used as a reference for writing parsers for non-.NET languages. Thanks to the XML serializing feature, it can easily be used for investigating unknown tags (or for implementing a zip-style file format; XML settings plus PNG files for channel data).
Examples of PSD sections it can handle:
- Individual layers, including extracting their bitmaps, transparencies and masks
- Global channels
- Slices, Grid/Guides, Thumbnails
- Vector Paths
- Layer effects (shadows, glows etc.)
- Adjustment layers (Brightness/Contrast, Curves, Levels etc.)
- Text layers (well, not really; there's an ocean of data for a simple text layer, and I don't know what half of it is for, but strictly speaking they're being parsed)
Note that it is not a PSD renderer; this library is for manipulating the files themselves. I will implement the most important rendering features in PaintLab, and possibly make it available as a DLL for immediate rendering (i.e. without opening the paint app itself).
Background
A few years back, I wanted to decode parts of the PSD format in order to speed up the production pipeline for a project. I looked at the available parsers, both commercial and open source, but none of them had the features I needed, nor a design I felt comfortable with, so I decided to write my own by using the SDK. But after finding out how closely Adobe guarded the secrets of their format, and that I wouldn't be able to sign their harsh SDK license agreement, I knew I would have to do it the hard way.
Reverse engineering is a tedious process (thus slow), and with the project where I needed the parser gone by, I didn't put much time on it.
Then I started working on the paint application PaintLab, and I realized that PSD support was probably one of the most important features - without it, there is no chance of Photoshop users even considering using the program. So, instead of working with the interesting features of PaintLab, I've had to put a fair amount of time into examining the PSD format, while cursing the fact that such a widely used format has no decent open source codec. I hope my work here can save other people's time, and help them being creative instead of dealing with the boring details of a file format.
With this project, I think I've managed to create a decent architecture, but there's still work to be done before it has a 100% compatibility with PSD files.
Using the code
As the code is part of the Endogine project, and uses several of the its classes, Endogine.dll has to be available for referencing. The host app also uses Endogine.Editors.dll for the XML editor.
The API is currently a pretty straightforward reflection of the PSD file structure:
using Endogine.Codecs.Photoshop;
using Endogine.Codecs.Photoshop.ImageResources;
using Endogine.Codecs.Photoshop.LayerResources;
Document psd = new Document("somefile.psd");
int documentHeight = psd.Header.Rows;
GridGuidesInfo guidesInfo =
(GridGuidesInfo)psd.GetResource(typeof(GridGuidesInfo));
Console.WriteLine("Guide location: " +
guidesInfo.Guides[0].LocationInPixels);
Bitmap bmp = psd.Layers[0].Bitmap;
Bitmap bmpChannel = psd.Layers[1].Channels[-1].Bitmap;
BrightnessContrast bc = (BrightnessContrast)
psd.Layers[2].GetResource(typeof(BrightnessContrast));
Console.WriteLine("Layer 2 (Adjustment layer) Brighness: " +
bc.Brightness);
psd.SaveXml("somefile.xml", true);
Points of Interest
The newer Photoshop SDKs, which include the file format specifications, are protected by a license agreement that compromises the usability of code produced by anyone who has signed it. That's why I've had to use reverse engineering for creating many parts of the code, and why it's taking so long to complete it.
If you want to contribute to the project, please understand that I won't accept code from anyone who has signed an Adobe SDK agreement. That could potentially mean trouble ahead, the day evil Adobe wants to shut down this subversive operation.
If the program fails to load a document, please add a note about it in the comments section below and keep the file around - if I have time, I'll ask you to send it to me for closer inspection. Note that I currently only have interest in documents created with Photoshop version 6 or later.
TODO
- Understand the properties of text layer tags (TySh and Txt2). They seem extremely bloated; help with these would be very welcome.
- Better access of data in Descriptor tags
- Implement write functionality in all classes
- Make sure it always writes correct PSD files
- Deserialize from XML / PNGs
- Implement ICC parser
- Investigate what the tags marked as Unknown are for
- Error handling
So far, I've only cared about RGB, 8-bit per channel images. Other formats are implicitly supported (channel data is treated the same way), but there's no specific functionality for them, like converting to RGB color space. Should you need color space conversion, there are classes for that in the Endogine.ColorEx namespace.
License
This project uses the BSD license. You are free to use the code or the binaries however you want, including commercially, as long as the copyright notice and license text are included as specified in LICENSE.txt (comes with the zip files).
History
- 2006-10-08 - First draft of the library.
| You must Sign In to use this message board. |
|
|
 |
|
 |
hey i need a lil help n dunno where to turn to. CS2 n CS3 .eps and .psd both have a photoshop:ColorMode for rgb n cmyk, but im havin difficulties wif CS1: *.eps have /deviceRGB or /deviceCMYK but i have abs no idea which tag where in the .psd tells anythin bout color space ? (i mean there is the photoshop:ColorMode tag but its value always says rgb even if its actually cmyk )
thx 
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
Hello,
I have 3 simple PSDs files made by photoshop CS 2. all of them raise exceptions in the demo application.
first one: "There was an error generating the XML document" second one: "Exception has been thrown by the target of an invocation" EDIT: third one is the same error, and same for 4 or 5 files that I have downloaded from the Net.
I don't know which parameter to set in the PSD, in order to be able to be parsed correctly.
|
| Sign In·View Thread·PermaLink | 1.60/5 |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hello, how can i get the version of PSD, e.g. Photoshop5.0 or 6.0 or CS2 etc...? I can't find the section to describe it, who can give me a hand.
thanks a lot.
Get and share.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hi,
Is it possible to add one more layer to the existing PSD file and change the existing layers text object.
|
| Sign In·View Thread·PermaLink | 1.67/5 |
|
|
|
 |
|
 |
Hi,
I am getting this error while opening the file using Document object. {"Unable to read beyond the end of the stream."}
Thanks Best Regards Jay
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In my program, I am using the Quicktime tools on the mac to import a psd file but they dont store the object offsets within the layer and I want to retain those on import. Any idea if I am even in the right area, its an offset of the object within the layer not an offset of the layer on the canvas right? Where do I get this info from the file? Any help would be greatly appreciated from anyone anthonyfg@gmail.com
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello everyone, i am parsing psd file for a project, but i cann't get enough infomation about psd file format, where do i find the specification of psd file format(ps6ffspecsv2.pdf) or the other document? thanks.
Pls refer to FIX: Assert in Appui1.cpp Line 215 in MFC SDI/MDI application
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
The output char buffer is too small to contain the decoded characters, encoding 'Unicode (UTF-8)' fallback 'System.Text.DecoderReplacementFallback'. Parameter name: chars
What should I do?
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I haven't looked into the CS3 format at all, and I have no idea when I'll have the time to continue working on the parser. Sorry!
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
When I save the psd document, an exception has thrown: My code: string filename = "c://output//psdOutput.psd"; _psd.Save(filename); The exception: "Exception has been thrown by the target of invocation"
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Thank you for your great topic I want to browse for a psd file instead of dragging it. I do that but there is a problem with the path. What can I do?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
This given demo project have 3 dll's
Endogine.Codecs.Photoshop.dll Endogine.dll Endogine.Editors.dll
I need a help file this 3 dll's. Then only i can use these dll in my project.
Note : And also i want to know these 3 dll's can use asp.net? or need different dll's for asp.net
Any one know about? Please help me!
John. J.P. .Net Sn. Programmer
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
If you want to use the parser on a web site, you'll have to create the GUI from scratch yourself - there's no way to automatically port WinForms forms/controls to WebForms. Endogine.Editors.dll is only used for the WinForms part, for the web version you'd only need Endogine.dll and Endogine.Codecs.Photoshop.dll. HTH, Jonas
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
This give demo project have 3 dll's. I try to do same project in asp.net, the following declaration is
Endogine.Editors.TreeEditForm psdtree;
This only for winform, i neet it in webform, Shell i use same dll for webform or i can use differnet dll for asp.net
John. J.P. .Net Sn. Programmer
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Hi...this is very great work. I have two questions : 1) how to support cs2 psd file format? 2) how to save psd files with this library? I will appreciate for your help.
regards Afaaz
Nothing is impossible
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello and thanks! I haven't had time to work on the project lately, and I haven't received much additions to the code from the community, so the CS2/3 format and save functionality is currently not available. And sorry, I can't really tell if/when I'll be giving it some more attention right now.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I am having difficulty saving a valid Photoshop file. I am wanting to take bitmaps and save them as layers in a .psd. I am probably leaving out a step. What are the steps to make a document that is valid?
Here's my code:
class PhotoshopExporter {
public PhotoshopExporter() { psdDoc = new Document(); }
public void AddLayer(Bitmap bitmapLayer, string layerName) { Layer myLayer = psdDoc.CreateLayer(layerName); myLayer.Bitmap = bitmapLayer; psdDoc.Layers.Add(myLayer);
}
public void SaveFile(string fileName) { psdDoc.GlobalImage.Bitmap = psdDoc.Layers[0].Bitmap; psdDoc.Save(fileName); } }
Any help is greatly appreciated!
Joseph
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
See My coding
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Endogine.Codecs.Photoshop; using System.Xml; using System.IO;
namespace PSD_Analysis { public partial class Form1 : Form { Document psddoc; XmlNode psdnode; Endogine.Editors.TreeEditForm psdtree; public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { this.Size = new Size(510, 720); this.Location = new Point(1, 1);
psdtree = new Endogine.Editors.TreeEditForm(); psdtree.Show(); psdtree.Visible = true; psdtree.Size = new Size(510, 720); psdtree.Location = new Point(510, 1); psdtree.TreeEdit.SplitterPosition = 200; }
private void PLoad_Click(object sender, EventArgs e) { psddoc = new Document(Application.StartupPath + "\\Sample.psd"); psddoc.SaveXml("Sample.xml", false);
XmlDocument xmldoc = new XmlDocument(); xmldoc.Load("Sample.xml");
psdnode =xmldoc.SelectSingleNode("PsdDocument"); LayerList.Items.Clear(); LayerList.Items.Add("Global"); foreach(Layer L in psddoc.Layers) LayerList.Items.Add(L.Name); LayerList.SelectedIndex = 0; }
private void LayerList_SelectedIndexChanged(object sender, EventArgs e) { if (LayerList.SelectedIndex == 0) { Pic.Image = psddoc.GlobalImage.Bitmap; psdtree.TreeEdit.LoadXml(null, true); foreach (XmlNode nod in psdnode.ChildNodes) if (nod.Name != "Layers") psdtree.TreeEdit.LoadXml(nod, false); } else { Layer L =psddoc.Layers[LayerList.SelectedIndex - 1]; Pic.Image = L.Bitmap; MemoryStream ms = new MemoryStream(); System.Xml.Serialization.XmlSerializer xmlser = new System.Xml.Serialization.XmlSerializer(L.GetType()); xmlser.Serialize(ms, L); foreach (XmlNode nod in psdnode.SelectSingleNode("Layers").ChildNodes) if (nod.Attributes["Name"].InnerText == L.Name) { psdtree.LoadXml(nod); break; }
} psdtree.TreeEdit.ExpandAll(); } } }
John. J.P. .Net Sn. Programmer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
if i must to save a psd to jpg with multi channel ? If i save it colors non true I lost colors to image multi channel
thank Matteo
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have been looking through your code and have been trying to find the class where layersets are stored or parsed.
Any help you could provide would greatly appreciated.
Marc
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|