Somehow they suggested making a psd file parser. It seems to be very simple. It is necessary to find out from which layers the document consists, to list the layers. If the layer is text, display text and formatting options. Those. font names, sizes, indents, etc.
Where to begin? May Google help us. A lot of information, a lot of details how to make plug-ins for photoshop. But this is all wrong. We need a console program that will receive psd files as input and output a textual description of its internals. Installing Photoshop was not originally planned.
This document turned out to be the most useful:
PhotoshopFileFormat is the actual specification of the structure of the photoshop file. A kind of single byte skeleton .psd file, just what the doctor ordered.
Next googled on the subject of, and did colleagues like that on java? Yes, it turns out that it is.
Parser-psd - a brief description + source code in the same place. Their program parses the file, and saves them in separate files (!) Plus information on slices is extracted. For my task, a little bit of something, but as an initial example, it even helped a lot.
')
The file is pushed into the usual
DataInputStream in = new DataInputStream(input)
stream and then we work with this stream byte-by-byte.
The file itself consists of five main sections:
1. File header
2. Color mode data
3. Image resources
4. Layer and mask information
5. Image data
The header has a fixed size, but the remaining blocks may have a different size. With this more closely. One byte by and the whole thing will be closed. The size is indicated in the first four bytes of the block, so blocks can be skipped if you don't need to
in.skipBytes(size)
everything
in.skipBytes(size)
.
Here the main attention and strict adherence to specifications. Attention! The format changes from version to version, these differences are indicated in the specification. However, the current specification, which I managed to find from 2010, and I had to use an even older description for the 2007th year. Therefore, when parsing the most recent versions of files you can miss.