mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2026-04-30 00:00:01 -04:00
New code style. No functional changes.
This commit is contained in:
+5
-5
@@ -43,7 +43,7 @@ import java.io.InputStream;
|
||||
* @version $Id: ICCProfile.java,v 1.0 May 20, 2008 6:24:10 PM haraldk Exp$
|
||||
*/
|
||||
class ICCProfile extends PSDImageResource {
|
||||
private ICC_Profile mProfile;
|
||||
private ICC_Profile profile;
|
||||
|
||||
ICCProfile(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -51,9 +51,9 @@ class ICCProfile extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(ImageInputStream pInput) throws IOException {
|
||||
InputStream stream = IIOUtil.createStreamAdapter(pInput, mSize);
|
||||
InputStream stream = IIOUtil.createStreamAdapter(pInput, size);
|
||||
try {
|
||||
mProfile = ICC_Profile.getInstance(stream);
|
||||
profile = ICC_Profile.getInstance(stream);
|
||||
}
|
||||
finally {
|
||||
// Make sure stream has correct position after read
|
||||
@@ -62,14 +62,14 @@ class ICCProfile extends PSDImageResource {
|
||||
}
|
||||
|
||||
public ICC_Profile getProfile() {
|
||||
return mProfile;
|
||||
return profile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", profile: ").append(mProfile);
|
||||
builder.append(", profile: ").append(profile);
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
+5
-5
@@ -41,7 +41,7 @@ import java.util.List;
|
||||
* @version $Id: PSDAlphaChannelInfo.java,v 1.0 May 2, 2008 5:33:40 PM haraldk Exp$
|
||||
*/
|
||||
class PSDAlphaChannelInfo extends PSDImageResource {
|
||||
List<String> mNames;
|
||||
List<String> names;
|
||||
|
||||
public PSDAlphaChannelInfo(short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -49,12 +49,12 @@ class PSDAlphaChannelInfo extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mNames = new ArrayList<String>();
|
||||
names = new ArrayList<String>();
|
||||
|
||||
long left = mSize;
|
||||
long left = size;
|
||||
while (left > 0) {
|
||||
String name = PSDUtil.readPascalString(pInput);
|
||||
mNames.add(name);
|
||||
names.add(name);
|
||||
left -= name.length() + 1;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class PSDAlphaChannelInfo extends PSDImageResource {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
builder.append(", alpha channels: ").append(mNames).append("]");
|
||||
builder.append(", alpha channels: ").append(names).append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -36,8 +36,8 @@ package com.twelvemonkeys.imageio.plugins.psd;
|
||||
* @version $Id: PSDChannelInfo.java,v 1.0 May 6, 2008 2:46:23 PM haraldk Exp$
|
||||
*/
|
||||
class PSDChannelInfo {
|
||||
final short mChannelId;
|
||||
final long mLength;
|
||||
final short channelId;
|
||||
final long length;
|
||||
|
||||
// typedef struct _CLI
|
||||
// {
|
||||
@@ -45,16 +45,16 @@ class PSDChannelInfo {
|
||||
// LONG LengthOfChannelData; /* Channel Length Info field two */
|
||||
// } CLI;
|
||||
public PSDChannelInfo(short pChannelId, long pLength) {
|
||||
mChannelId = pChannelId;
|
||||
mLength = pLength;
|
||||
channelId = pChannelId;
|
||||
length = pLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[");
|
||||
builder.append("channelId: ").append(mChannelId);
|
||||
builder.append(", length: ").append(mLength);
|
||||
builder.append("channelId: ").append(channelId);
|
||||
builder.append(", length: ").append(length);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
+15
-15
@@ -39,29 +39,29 @@ import java.io.IOException;
|
||||
* @version $Id: PSDChannelSourceDestinationRange.java,v 1.0 May 6, 2008 5:14:13 PM haraldk Exp$
|
||||
*/
|
||||
class PSDChannelSourceDestinationRange {
|
||||
private String mChannel;
|
||||
private short mSourceBlack;
|
||||
private short mSourceWhite;
|
||||
private short mDestBlack;
|
||||
private short mDestWhite;
|
||||
private String channel;
|
||||
private short sourceBlack;
|
||||
private short sourceWhite;
|
||||
private short destBlack;
|
||||
private short destWhite;
|
||||
|
||||
public PSDChannelSourceDestinationRange(ImageInputStream pInput, String pChannel) throws IOException {
|
||||
mChannel = pChannel;
|
||||
mSourceBlack = pInput.readShort();
|
||||
mSourceWhite = pInput.readShort();
|
||||
mDestBlack = pInput.readShort();
|
||||
mDestWhite = pInput.readShort();
|
||||
channel = pChannel;
|
||||
sourceBlack = pInput.readShort();
|
||||
sourceWhite = pInput.readShort();
|
||||
destBlack = pInput.readShort();
|
||||
destWhite = pInput.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
|
||||
builder.append("[(").append(mChannel);
|
||||
builder.append("): sourceBlack: ").append(Integer.toHexString(mSourceBlack & 0xffff));
|
||||
builder.append(", sourceWhite: ").append(Integer.toHexString(mSourceWhite & 0xffff));
|
||||
builder.append(", destBlack: ").append(Integer.toHexString(mDestBlack & 0xffff));
|
||||
builder.append(", destWhite: ").append(Integer.toHexString(mDestWhite & 0xffff));
|
||||
builder.append("[(").append(channel);
|
||||
builder.append("): sourceBlack: ").append(Integer.toHexString(sourceBlack & 0xffff));
|
||||
builder.append(", sourceWhite: ").append(Integer.toHexString(sourceWhite & 0xffff));
|
||||
builder.append(", destBlack: ").append(Integer.toHexString(destBlack & 0xffff));
|
||||
builder.append(", destWhite: ").append(Integer.toHexString(destWhite & 0xffff));
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
+8
-8
@@ -44,8 +44,8 @@ import java.io.IOException;
|
||||
* @version $Id: PSDColorData.java,v 1.0 Apr 29, 2008 5:33:01 PM haraldk Exp$
|
||||
*/
|
||||
class PSDColorData {
|
||||
final byte[] mColors;
|
||||
private IndexColorModel mColorModel;
|
||||
final byte[] colors;
|
||||
private IndexColorModel colorModel;
|
||||
|
||||
PSDColorData(final ImageInputStream pInput) throws IOException {
|
||||
int length = pInput.readInt();
|
||||
@@ -57,19 +57,19 @@ class PSDColorData {
|
||||
}
|
||||
|
||||
// NOTE: Spec says length may only be 768 bytes (256 RGB triplets)
|
||||
mColors = new byte[length];
|
||||
pInput.readFully(mColors);
|
||||
colors = new byte[length];
|
||||
pInput.readFully(colors);
|
||||
|
||||
// NOTE: Could be a padding byte here, if not even..
|
||||
}
|
||||
|
||||
IndexColorModel getIndexColorModel() {
|
||||
if (mColorModel == null) {
|
||||
int[] rgb = toInterleavedRGB(mColors);
|
||||
mColorModel = new InverseColorMapIndexColorModel(8, rgb.length, rgb, 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
if (colorModel == null) {
|
||||
int[] rgb = toInterleavedRGB(colors);
|
||||
colorModel = new InverseColorMapIndexColorModel(8, rgb.length, rgb, 0, false, -1, DataBuffer.TYPE_BYTE);
|
||||
}
|
||||
|
||||
return mColorModel;
|
||||
return colorModel;
|
||||
}
|
||||
|
||||
private static int[] toInterleavedRGB(final byte[] pColors) {
|
||||
|
||||
+23
-23
@@ -65,10 +65,10 @@ class PSDDisplayInfo extends PSDImageResource {
|
||||
// BYTE Padding; /* Always zero */
|
||||
//} DISPLAYINFO;
|
||||
|
||||
int mColorSpace;
|
||||
short[] mColors;
|
||||
short mOpacity;
|
||||
byte mKind;
|
||||
int colorSpace;
|
||||
short[] colors;
|
||||
short opacity;
|
||||
byte kind;
|
||||
|
||||
PSDDisplayInfo(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -76,46 +76,46 @@ class PSDDisplayInfo extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(ImageInputStream pInput) throws IOException {
|
||||
if (mSize % 14 != 0) {
|
||||
throw new IIOException("Display info length expected to be mod 14: " + mSize);
|
||||
if (size % 14 != 0) {
|
||||
throw new IIOException("Display info length expected to be mod 14: " + size);
|
||||
}
|
||||
|
||||
// long left = mSize;
|
||||
// long left = size;
|
||||
// while (left > 0) {
|
||||
mColorSpace = pInput.readShort();
|
||||
colorSpace = pInput.readShort();
|
||||
|
||||
// Color[4]...?
|
||||
mColors = new short[4];
|
||||
mColors[0] = pInput.readShort();
|
||||
mColors[1] = pInput.readShort();
|
||||
mColors[2] = pInput.readShort();
|
||||
mColors[3] = pInput.readShort();
|
||||
colors = new short[4];
|
||||
colors[0] = pInput.readShort();
|
||||
colors[1] = pInput.readShort();
|
||||
colors[2] = pInput.readShort();
|
||||
colors[3] = pInput.readShort();
|
||||
|
||||
mOpacity = pInput.readShort();
|
||||
opacity = pInput.readShort();
|
||||
|
||||
mKind = pInput.readByte();
|
||||
kind = pInput.readByte();
|
||||
|
||||
pInput.readByte(); // Pad
|
||||
// left -= 14;
|
||||
// }
|
||||
pInput.skipBytes(mSize - 14);
|
||||
pInput.skipBytes(size - 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", ColorSpace: ").append(mColorSpace);
|
||||
builder.append(", ColorSpace: ").append(colorSpace);
|
||||
builder.append(", Colors: {");
|
||||
builder.append(mColors[0]);
|
||||
builder.append(colors[0]);
|
||||
builder.append(", ");
|
||||
builder.append(mColors[1]);
|
||||
builder.append(colors[1]);
|
||||
builder.append(", ");
|
||||
builder.append(mColors[2]);
|
||||
builder.append(colors[2]);
|
||||
builder.append(", ");
|
||||
builder.append(mColors[3]);
|
||||
builder.append("}, Opacity: ").append(mOpacity);
|
||||
builder.append(", Kind: ").append(kind(mKind));
|
||||
builder.append(colors[3]);
|
||||
builder.append("}, Opacity: ").append(opacity);
|
||||
builder.append(", Kind: ").append(kind(kind));
|
||||
|
||||
builder.append("]");
|
||||
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ import java.io.IOException;
|
||||
* @see <a href="http://partners.adobe.com/public/developer/tiff/index.html">Adobe TIFF developer resources</a>
|
||||
*/
|
||||
final class PSDEXIF1Data extends PSDImageResource {
|
||||
protected Directory mDirectory;
|
||||
protected Directory directory;
|
||||
|
||||
PSDEXIF1Data(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -28,13 +28,13 @@ final class PSDEXIF1Data extends PSDImageResource {
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
// This is in essence an embedded TIFF file.
|
||||
// TODO: Instead, read the byte data, store for later parsing (or better yet, store offset, and read on request)
|
||||
mDirectory = new EXIFReader().read(pInput);
|
||||
directory = new EXIFReader().read(pInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
builder.append(", ").append(mDirectory);
|
||||
builder.append(", ").append(directory);
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
+21
-21
@@ -39,25 +39,25 @@ import java.io.IOException;
|
||||
* @version $Id: PSDGlobalLayerMask.java,v 1.0 May 8, 2008 5:33:48 PM haraldk Exp$
|
||||
*/
|
||||
class PSDGlobalLayerMask {
|
||||
final int mColorSpace;
|
||||
final int mColor1;
|
||||
final int mColor2;
|
||||
final int mColor3;
|
||||
final int mColor4;
|
||||
final int mOpacity;
|
||||
final int mKind;
|
||||
final int colorSpace;
|
||||
final int color1;
|
||||
final int color2;
|
||||
final int color3;
|
||||
final int color4;
|
||||
final int opacity;
|
||||
final int kind;
|
||||
|
||||
PSDGlobalLayerMask(final ImageInputStream pInput) throws IOException {
|
||||
mColorSpace = pInput.readUnsignedShort(); // Undocumented
|
||||
colorSpace = pInput.readUnsignedShort(); // Undocumented
|
||||
|
||||
mColor1 = pInput.readUnsignedShort();
|
||||
mColor2 = pInput.readUnsignedShort();
|
||||
mColor3 = pInput.readUnsignedShort();
|
||||
mColor4 = pInput.readUnsignedShort();
|
||||
color1 = pInput.readUnsignedShort();
|
||||
color2 = pInput.readUnsignedShort();
|
||||
color3 = pInput.readUnsignedShort();
|
||||
color4 = pInput.readUnsignedShort();
|
||||
|
||||
mOpacity = pInput.readUnsignedShort(); // 0-100
|
||||
opacity = pInput.readUnsignedShort(); // 0-100
|
||||
|
||||
mKind = pInput.readUnsignedByte(); // 0: Selected (ie inverted), 1: Color protected, 128: Use value stored per layer
|
||||
kind = pInput.readUnsignedByte(); // 0: Selected (ie inverted), 1: Color protected, 128: Use value stored per layer
|
||||
|
||||
// TODO: Variable: Filler zeros
|
||||
|
||||
@@ -68,13 +68,13 @@ class PSDGlobalLayerMask {
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[");
|
||||
builder.append("color space: 0x").append(Integer.toHexString(mColorSpace));
|
||||
builder.append(", colors: [0x").append(Integer.toHexString(mColor1));
|
||||
builder.append(", 0x").append(Integer.toHexString(mColor2));
|
||||
builder.append(", 0x").append(Integer.toHexString(mColor3));
|
||||
builder.append(", 0x").append(Integer.toHexString(mColor4));
|
||||
builder.append("], opacity: ").append(mOpacity);
|
||||
builder.append(", kind: ").append(mKind);
|
||||
builder.append("color space: 0x").append(Integer.toHexString(colorSpace));
|
||||
builder.append(", colors: [0x").append(Integer.toHexString(color1));
|
||||
builder.append(", 0x").append(Integer.toHexString(color2));
|
||||
builder.append(", 0x").append(Integer.toHexString(color3));
|
||||
builder.append(", 0x").append(Integer.toHexString(color4));
|
||||
builder.append("], opacity: ").append(opacity);
|
||||
builder.append(", kind: ").append(kind);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
+15
-15
@@ -25,12 +25,12 @@ final class PSDGridAndGuideInfo extends PSDImageResource {
|
||||
// gchar fDirection; /* Guide orientation */
|
||||
//} GuideResource;
|
||||
|
||||
int mVersion;
|
||||
int mGridCycleVertical;
|
||||
int mGridCycleHorizontal;
|
||||
int mGuideCount;
|
||||
int version;
|
||||
int gridCycleVertical;
|
||||
int gridCycleHorizontal;
|
||||
int guideCount;
|
||||
|
||||
GuideResource[] mGuides;
|
||||
GuideResource[] guides;
|
||||
|
||||
PSDGridAndGuideInfo(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -38,21 +38,21 @@ final class PSDGridAndGuideInfo extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mVersion = pInput.readInt();
|
||||
mGridCycleVertical = pInput.readInt();
|
||||
mGridCycleHorizontal = pInput.readInt();
|
||||
mGuideCount = pInput.readInt();
|
||||
version = pInput.readInt();
|
||||
gridCycleVertical = pInput.readInt();
|
||||
gridCycleHorizontal = pInput.readInt();
|
||||
guideCount = pInput.readInt();
|
||||
|
||||
mGuides = new GuideResource[mGuideCount];
|
||||
guides = new GuideResource[guideCount];
|
||||
|
||||
for (GuideResource guide : mGuides) {
|
||||
guide.mLocation = pInput.readInt();
|
||||
guide.mDirection = pInput.readByte();
|
||||
for (GuideResource guide : guides) {
|
||||
guide.location = pInput.readInt();
|
||||
guide.direction = pInput.readByte();
|
||||
}
|
||||
}
|
||||
|
||||
static class GuideResource {
|
||||
int mLocation;
|
||||
byte mDirection; // 0: vertical, 1: horizontal
|
||||
int location;
|
||||
byte direction; // 0: vertical, 1: horizontal
|
||||
}
|
||||
}
|
||||
|
||||
+16
-19
@@ -28,9 +28,6 @@
|
||||
|
||||
package com.twelvemonkeys.imageio.plugins.psd;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import javax.imageio.metadata.IIOMetadataNode;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.IIOException;
|
||||
import java.io.IOException;
|
||||
@@ -58,11 +55,11 @@ class PSDHeader {
|
||||
// WORD Mode; /* Color mode */
|
||||
// } PSD_HEADER;
|
||||
|
||||
final short mChannels;
|
||||
final int mWidth;
|
||||
final int mHeight;
|
||||
final short mBits;
|
||||
final short mMode;
|
||||
final short channels;
|
||||
final int width;
|
||||
final int height;
|
||||
final short bits;
|
||||
final short mode;
|
||||
|
||||
PSDHeader(final ImageInputStream pInput) throws IOException {
|
||||
int signature = pInput.readInt();
|
||||
@@ -84,27 +81,27 @@ class PSDHeader {
|
||||
byte[] reserved = new byte[6];
|
||||
pInput.readFully(reserved);
|
||||
|
||||
mChannels = pInput.readShort();
|
||||
mHeight = pInput.readInt(); // Rows
|
||||
mWidth = pInput.readInt(); // Columns
|
||||
mBits = pInput.readShort();
|
||||
mMode = pInput.readShort();
|
||||
channels = pInput.readShort();
|
||||
height = pInput.readInt(); // Rows
|
||||
width = pInput.readInt(); // Columns
|
||||
bits = pInput.readShort();
|
||||
mode = pInput.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[Channels: ");
|
||||
builder.append(mChannels);
|
||||
builder.append(channels);
|
||||
builder.append(", width: ");
|
||||
builder.append(mWidth);
|
||||
builder.append(width);
|
||||
builder.append(", height: ");
|
||||
builder.append(mHeight);
|
||||
builder.append(height);
|
||||
builder.append(", depth: ");
|
||||
builder.append(mBits);
|
||||
builder.append(bits);
|
||||
builder.append(", mode: ");
|
||||
builder.append(mMode);
|
||||
switch (mMode) {
|
||||
builder.append(mode);
|
||||
switch (mode) {
|
||||
case PSD.COLOR_MODE_MONOCHROME:
|
||||
builder.append(" (Monochrome)");
|
||||
break;
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
* @version $Id: PSDIPTCData.java,v 1.0 Nov 7, 2009 9:52:14 PM haraldk Exp$
|
||||
*/
|
||||
final class PSDIPTCData extends PSDImageResource {
|
||||
Directory mDirectory;
|
||||
Directory directory;
|
||||
|
||||
PSDIPTCData(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -23,13 +23,13 @@ final class PSDIPTCData extends PSDImageResource {
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
// Read IPTC directory
|
||||
mDirectory = new IPTCReader().read(pInput);
|
||||
directory = new IPTCReader().read(pInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
builder.append(", ").append(mDirectory);
|
||||
builder.append(", ").append(directory);
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
+91
-97
@@ -72,36 +72,30 @@ import java.util.List;
|
||||
// See http://www.codeproject.com/KB/graphics/PSDParser.aspx
|
||||
// See http://www.adobeforums.com/webx?14@@.3bc381dc/0
|
||||
public class PSDImageReader extends ImageReaderBase {
|
||||
private PSDHeader mHeader;
|
||||
// private PSDColorData mColorData;
|
||||
// private List<PSDImageResource> mImageResources;
|
||||
// private PSDGlobalLayerMask mGlobalLayerMask;
|
||||
// private List<PSDLayerInfo> mLayerInfo;
|
||||
private ICC_ColorSpace mColorSpace;
|
||||
protected PSDMetadata mMetadata;
|
||||
private PSDHeader header;
|
||||
private ICC_ColorSpace colorSpace;
|
||||
protected PSDMetadata metadata;
|
||||
|
||||
protected PSDImageReader(final ImageReaderSpi pOriginatingProvider) {
|
||||
super(pOriginatingProvider);
|
||||
}
|
||||
|
||||
protected void resetMembers() {
|
||||
mHeader = null;
|
||||
// mColorData = null;
|
||||
// mImageResources = null;
|
||||
mMetadata = null;
|
||||
mColorSpace = null;
|
||||
header = null;
|
||||
metadata = null;
|
||||
colorSpace = null;
|
||||
}
|
||||
|
||||
public int getWidth(final int pIndex) throws IOException {
|
||||
checkBounds(pIndex);
|
||||
readHeader();
|
||||
return mHeader.mWidth;
|
||||
return header.width;
|
||||
}
|
||||
|
||||
public int getHeight(final int pIndex) throws IOException {
|
||||
checkBounds(pIndex);
|
||||
readHeader();
|
||||
return mHeader.mHeight;
|
||||
return header.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,39 +109,39 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
|
||||
ColorSpace cs;
|
||||
|
||||
switch (mHeader.mMode) {
|
||||
switch (header.mode) {
|
||||
case PSD.COLOR_MODE_MONOCHROME:
|
||||
if (mHeader.mChannels == 1 && mHeader.mBits == 1) {
|
||||
if (header.channels == 1 && header.bits == 1) {
|
||||
return ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_BINARY);
|
||||
}
|
||||
|
||||
throw new IIOException(
|
||||
String.format("Unsupported channel count/bit depth for Monochrome PSD: %d channels/%d bits", mHeader.mChannels, mHeader.mBits)
|
||||
String.format("Unsupported channel count/bit depth for Monochrome PSD: %d channels/%d bits", header.channels, header.bits)
|
||||
);
|
||||
|
||||
case PSD.COLOR_MODE_INDEXED:
|
||||
// TODO: 16 bit indexed?! Does it exist?
|
||||
if (mHeader.mChannels == 1 && mHeader.mBits == 8) {
|
||||
return IndexedImageTypeSpecifier.createFromIndexColorModel(mMetadata.mColorData.getIndexColorModel());
|
||||
if (header.channels == 1 && header.bits == 8) {
|
||||
return IndexedImageTypeSpecifier.createFromIndexColorModel(metadata.colorData.getIndexColorModel());
|
||||
}
|
||||
|
||||
throw new IIOException(
|
||||
String.format("Unsupported channel count/bit depth for Indexed Color PSD: %d channels/%d bits", mHeader.mChannels, mHeader.mBits)
|
||||
String.format("Unsupported channel count/bit depth for Indexed Color PSD: %d channels/%d bits", header.channels, header.bits)
|
||||
);
|
||||
|
||||
case PSD.COLOR_MODE_DUOTONE:
|
||||
// NOTE: Duotone (whatever that is) should be treated as gray scale
|
||||
// Fall-through
|
||||
case PSD.COLOR_MODE_GRAYSCALE:
|
||||
if (mHeader.mChannels == 1 && mHeader.mBits == 8) {
|
||||
if (header.channels == 1 && header.bits == 8) {
|
||||
return ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY);
|
||||
}
|
||||
else if (mHeader.mChannels == 1 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 1 && header.bits == 16) {
|
||||
return ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_USHORT_GRAY);
|
||||
}
|
||||
|
||||
throw new IIOException(
|
||||
String.format("Unsupported channel count/bit depth for Gray Scale PSD: %d channels/%d bits", mHeader.mChannels, mHeader.mBits)
|
||||
String.format("Unsupported channel count/bit depth for Gray Scale PSD: %d channels/%d bits", header.channels, header.bits)
|
||||
);
|
||||
|
||||
case PSD.COLOR_MODE_RGB:
|
||||
@@ -157,21 +151,21 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
}
|
||||
|
||||
if (mHeader.mChannels == 3 && mHeader.mBits == 8) {
|
||||
if (header.channels == 3 && header.bits == 8) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_BYTE, false, false);
|
||||
}
|
||||
else if (mHeader.mChannels >= 4 && mHeader.mBits == 8) {
|
||||
else if (header.channels >= 4 && header.bits == 8) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_BYTE, true, false);
|
||||
}
|
||||
else if (mHeader.mChannels == 3 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 3 && header.bits == 16) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_USHORT, false, false);
|
||||
}
|
||||
else if (mHeader.mChannels >= 4 && mHeader.mBits == 16) {
|
||||
else if (header.channels >= 4 && header.bits == 16) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_USHORT, true, false);
|
||||
}
|
||||
|
||||
throw new IIOException(
|
||||
String.format("Unsupported channel count/bit depth for RGB PSD: %d channels/%d bits", mHeader.mChannels, mHeader.mBits)
|
||||
String.format("Unsupported channel count/bit depth for RGB PSD: %d channels/%d bits", header.channels, header.bits)
|
||||
);
|
||||
|
||||
case PSD.COLOR_MODE_CMYK:
|
||||
@@ -180,21 +174,21 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
cs = ColorSpaces.getColorSpace(ColorSpaces.CS_GENERIC_CMYK);
|
||||
}
|
||||
|
||||
if (mHeader.mChannels == 4 && mHeader.mBits == 8) {
|
||||
if (header.channels == 4 && header.bits == 8) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_BYTE, false, false);
|
||||
}
|
||||
else if (mHeader.mChannels == 5 && mHeader.mBits == 8) {
|
||||
else if (header.channels == 5 && header.bits == 8) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2, 3, 4}, new int[] {0, 0, 0, 0, 0}, DataBuffer.TYPE_BYTE, true, false);
|
||||
}
|
||||
else if (mHeader.mChannels == 4 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 4 && header.bits == 16) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_USHORT, false, false);
|
||||
}
|
||||
else if (mHeader.mChannels == 5 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 5 && header.bits == 16) {
|
||||
return ImageTypeSpecifier.createBanded(cs, new int[] {0, 1, 2, 3, 4}, new int[] {0, 0, 0, 0, 0}, DataBuffer.TYPE_USHORT, true, false);
|
||||
}
|
||||
|
||||
throw new IIOException(
|
||||
String.format("Unsupported channel count/bit depth for CMYK PSD: %d channels/%d bits", mHeader.mChannels, mHeader.mBits)
|
||||
String.format("Unsupported channel count/bit depth for CMYK PSD: %d channels/%d bits", header.channels, header.bits)
|
||||
);
|
||||
|
||||
case PSD.COLOR_MODE_MULTICHANNEL:
|
||||
@@ -204,7 +198,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
// TODO: If there's a color profile embedded, it should be easy, otherwise we're out of luck...
|
||||
default:
|
||||
throw new IIOException(
|
||||
String.format("Unsupported PSD MODE: %s (%d channels/%d bits)", mHeader.mMode, mHeader.mChannels, mHeader.mBits)
|
||||
String.format("Unsupported PSD MODE: %s (%d channels/%d bits)", header.mode, header.channels, header.bits)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -219,10 +213,10 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
ColorSpace cs = rawType.getColorModel().getColorSpace();
|
||||
List<ImageTypeSpecifier> types = new ArrayList<ImageTypeSpecifier>();
|
||||
|
||||
switch (mHeader.mMode) {
|
||||
switch (header.mode) {
|
||||
case PSD.COLOR_MODE_RGB:
|
||||
// Prefer interleaved versions as they are much faster to display
|
||||
if (mHeader.mChannels == 3 && mHeader.mBits == 8) {
|
||||
if (header.channels == 3 && header.bits == 8) {
|
||||
// TODO: ColorConvertOp to CS_sRGB
|
||||
// TODO: Integer raster
|
||||
// types.add(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.INT_RGB));
|
||||
@@ -233,7 +227,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {2, 1, 0}, DataBuffer.TYPE_BYTE, false, false));
|
||||
}
|
||||
}
|
||||
else if (mHeader.mChannels >= 4 && mHeader.mBits == 8) {
|
||||
else if (header.channels >= 4 && header.bits == 8) {
|
||||
// TODO: ColorConvertOp to CS_sRGB
|
||||
// TODO: Integer raster
|
||||
// types.add(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.INT_ARGB));
|
||||
@@ -244,10 +238,10 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, true, false));
|
||||
}
|
||||
}
|
||||
else if (mHeader.mChannels == 3 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 3 && header.bits == 16) {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {2, 1, 0}, DataBuffer.TYPE_USHORT, false, false));
|
||||
}
|
||||
else if (mHeader.mChannels >= 4 && mHeader.mBits == 16) {
|
||||
else if (header.channels >= 4 && header.bits == 16) {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {3, 2, 1, 0}, DataBuffer.TYPE_USHORT, true, false));
|
||||
}
|
||||
break;
|
||||
@@ -258,16 +252,16 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
// as Java2D is extremely slow displaying custom images.
|
||||
// Converting to RGB is also correct behaviour, according to the docs.
|
||||
// Doing this, will require rewriting the image reading, as the raw image data is channelled, not interleaved :-/
|
||||
if (mHeader.mChannels == 4 && mHeader.mBits == 8) {
|
||||
if (header.channels == 4 && header.bits == 8) {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {3, 2, 1, 0}, DataBuffer.TYPE_BYTE, false, false));
|
||||
}
|
||||
else if (mHeader.mChannels == 5 && mHeader.mBits == 8) {
|
||||
else if (header.channels == 5 && header.bits == 8) {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {4, 3, 2, 1, 0}, DataBuffer.TYPE_BYTE, true, false));
|
||||
}
|
||||
else if (mHeader.mChannels == 4 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 4 && header.bits == 16) {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[]{3, 2, 1, 0}, DataBuffer.TYPE_USHORT, false, false));
|
||||
}
|
||||
else if (mHeader.mChannels == 5 && mHeader.mBits == 16) {
|
||||
else if (header.channels == 5 && header.bits == 16) {
|
||||
types.add(ImageTypeSpecifier.createInterleaved(cs, new int[] {4, 3, 2, 1, 0}, DataBuffer.TYPE_USHORT, true, false));
|
||||
}
|
||||
break;
|
||||
@@ -286,19 +280,19 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
// TODO: Skip this, requires storing some stream offsets
|
||||
readLayerAndMaskInfo(false);
|
||||
|
||||
if (mColorSpace == null) {
|
||||
if (colorSpace == null) {
|
||||
ICC_Profile profile = null;
|
||||
for (PSDImageResource resource : mMetadata.mImageResources) {
|
||||
for (PSDImageResource resource : metadata.imageResources) {
|
||||
if (resource instanceof ICCProfile) {
|
||||
profile = ((ICCProfile) resource).getProfile();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mColorSpace = profile == null ? null : ColorSpaces.createColorSpace(profile);
|
||||
colorSpace = profile == null ? null : ColorSpaces.createColorSpace(profile);
|
||||
}
|
||||
|
||||
return mColorSpace;
|
||||
return colorSpace;
|
||||
}
|
||||
|
||||
public BufferedImage read(final int pIndex, final ImageReadParam pParam) throws IOException {
|
||||
@@ -309,13 +303,13 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
readImageResources(false);
|
||||
readLayerAndMaskInfo(false);
|
||||
|
||||
BufferedImage image = getDestination(pParam, getImageTypes(pIndex), mHeader.mWidth, mHeader.mHeight);
|
||||
BufferedImage image = getDestination(pParam, getImageTypes(pIndex), header.width, header.height);
|
||||
ImageTypeSpecifier rawType = getRawImageType(pIndex);
|
||||
checkReadParamBandSettings(pParam, rawType.getNumBands(), image.getSampleModel().getNumBands());
|
||||
|
||||
final Rectangle source = new Rectangle();
|
||||
final Rectangle dest = new Rectangle();
|
||||
computeRegions(pParam, mHeader.mWidth, mHeader.mHeight, image, source, dest);
|
||||
computeRegions(pParam, header.width, header.height, image, source, dest);
|
||||
|
||||
/*
|
||||
NOTE: It seems safe to just leave this out for now. The only thing we need is to support sub sampling.
|
||||
@@ -360,14 +354,14 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
int[] byteCounts = null;
|
||||
int compression = imageInput.readShort();
|
||||
// TODO: Need to make sure compression is set in metadata, even without reading the image data!
|
||||
mMetadata.mCompression = compression;
|
||||
metadata.compression = compression;
|
||||
|
||||
switch (compression) {
|
||||
case PSD.COMPRESSION_NONE:
|
||||
break;
|
||||
case PSD.COMPRESSION_RLE:
|
||||
// NOTE: Byte counts will allow us to easily skip rows before AOI
|
||||
byteCounts = new int[mHeader.mChannels * mHeader.mHeight];
|
||||
byteCounts = new int[header.channels * header.height];
|
||||
for (int i = 0; i < byteCounts.length; i++) {
|
||||
byteCounts[i] = imageInput.readUnsignedShort();
|
||||
}
|
||||
@@ -410,7 +404,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
final ColorModel destCM = pImage.getColorModel();
|
||||
|
||||
// TODO: This raster is 3-5 times longer than needed, depending on number of channels...
|
||||
final WritableRaster rowRaster = pSourceCM.createCompatibleWritableRaster(mHeader.mWidth, 1);
|
||||
final WritableRaster rowRaster = pSourceCM.createCompatibleWritableRaster(header.width, 1);
|
||||
|
||||
final int channels = rowRaster.getNumBands();
|
||||
final boolean banded = raster.getDataBuffer().getNumBanks() > 1;
|
||||
@@ -419,21 +413,21 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
for (int c = 0; c < channels; c++) {
|
||||
int bandOffset = banded ? 0 : interleavedBands - 1 - c;
|
||||
|
||||
switch (mHeader.mBits) {
|
||||
switch (header.bits) {
|
||||
case 1:
|
||||
byte[] row1 = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
|
||||
read1bitChannel(c, mHeader.mChannels, raster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row1, pSource, pDest, pXSub, pYSub, mHeader.mWidth, mHeader.mHeight, pByteCounts, pCompression == PSD.COMPRESSION_RLE);
|
||||
read1bitChannel(c, header.channels, raster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row1, pSource, pDest, pXSub, pYSub, header.width, header.height, pByteCounts, pCompression == PSD.COMPRESSION_RLE);
|
||||
break;
|
||||
case 8:
|
||||
byte[] row8 = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
|
||||
read8bitChannel(c, mHeader.mChannels, raster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row8, pSource, pDest, pXSub, pYSub, mHeader.mWidth, mHeader.mHeight, pByteCounts, c * mHeader.mHeight, pCompression == PSD.COMPRESSION_RLE);
|
||||
read8bitChannel(c, header.channels, raster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row8, pSource, pDest, pXSub, pYSub, header.width, header.height, pByteCounts, c * header.height, pCompression == PSD.COMPRESSION_RLE);
|
||||
break;
|
||||
case 16:
|
||||
short[] row16 = ((DataBufferUShort) rowRaster.getDataBuffer()).getData();
|
||||
read16bitChannel(c, mHeader.mChannels, raster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row16, pSource, pDest, pXSub, pYSub, mHeader.mWidth, mHeader.mHeight, pByteCounts, c * mHeader.mHeight, pCompression == PSD.COMPRESSION_RLE);
|
||||
read16bitChannel(c, header.channels, raster.getDataBuffer(), interleavedBands, bandOffset, pSourceCM, row16, pSource, pDest, pXSub, pYSub, header.width, header.height, pByteCounts, c * header.height, pCompression == PSD.COMPRESSION_RLE);
|
||||
break;
|
||||
default:
|
||||
throw new IIOException(String.format("Unknown PSD bit depth: %s", mHeader.mBits));
|
||||
throw new IIOException(String.format("Unknown PSD bit depth: %s", header.bits));
|
||||
}
|
||||
|
||||
if (abortRequested()) {
|
||||
@@ -441,7 +435,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
}
|
||||
}
|
||||
|
||||
if (mHeader.mBits == 8) {
|
||||
if (header.bits == 8) {
|
||||
// Compose out the background of the semi-transparent pixels, as PS somehow has the background composed in
|
||||
decomposeAlpha(destCM, raster.getDataBuffer(), pDest.width, pDest.height, raster.getNumBands());
|
||||
}
|
||||
@@ -713,11 +707,11 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
|
||||
private void readHeader() throws IOException {
|
||||
assertInput();
|
||||
if (mHeader == null) {
|
||||
mHeader = new PSDHeader(imageInput);
|
||||
if (header == null) {
|
||||
header = new PSDHeader(imageInput);
|
||||
|
||||
mMetadata = new PSDMetadata();
|
||||
mMetadata.mHeader = mHeader;
|
||||
metadata = new PSDMetadata();
|
||||
metadata.header = header;
|
||||
|
||||
/*
|
||||
Contains the required data to define the color mode.
|
||||
@@ -730,8 +724,8 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
the duotone image as a grayscale image, and keep the duotone specification
|
||||
around as a black box for use when saving the file.
|
||||
*/
|
||||
if (mHeader.mMode == PSD.COLOR_MODE_INDEXED) {
|
||||
mMetadata.mColorData = new PSDColorData(imageInput);
|
||||
if (header.mode == PSD.COLOR_MODE_INDEXED) {
|
||||
metadata.colorData = new PSDColorData(imageInput);
|
||||
}
|
||||
else {
|
||||
// TODO: We need to store the duotone spec if we decide to create a writer...
|
||||
@@ -755,14 +749,14 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
long length = imageInput.readUnsignedInt();
|
||||
|
||||
if (pParseData && length > 0) {
|
||||
if (mMetadata.mImageResources == null) {
|
||||
mMetadata.mImageResources = new ArrayList<PSDImageResource>();
|
||||
if (metadata.imageResources == null) {
|
||||
metadata.imageResources = new ArrayList<PSDImageResource>();
|
||||
long expectedEnd = imageInput.getStreamPosition() + length;
|
||||
|
||||
while (imageInput.getStreamPosition() < expectedEnd) {
|
||||
// TODO: Have PSDImageResources defer actual parsing? (Just store stream offsets)
|
||||
PSDImageResource resource = PSDImageResource.read(imageInput);
|
||||
mMetadata.mImageResources.add(resource);
|
||||
metadata.imageResources.add(resource);
|
||||
}
|
||||
|
||||
if (imageInput.getStreamPosition() != expectedEnd) {
|
||||
@@ -796,7 +790,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
for (int i = 0; i < layerInfos.length; i++) {
|
||||
layerInfos[i] = new PSDLayerInfo(imageInput);
|
||||
}
|
||||
mMetadata.mLayerInfo = Arrays.asList(layerInfos);
|
||||
metadata.layerInfo = Arrays.asList(layerInfos);
|
||||
|
||||
// TODO: Clean-up
|
||||
imageInput.mark();
|
||||
@@ -810,7 +804,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
|
||||
// TODO: Don't show! Store in meta data somehow...
|
||||
// if (layer != null) {
|
||||
// showIt(layer, layerInfo.mLayerName + " " + layerInfo.mBlendMode.toString());
|
||||
// showIt(layer, layerInfo.layerName + " " + layerInfo.blendMode.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -825,8 +819,8 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
long layerMaskInfoLength = imageInput.readUnsignedInt();
|
||||
// System.out.println("GlobalLayerMaskInfo length: " + layerMaskInfoLength);
|
||||
if (layerMaskInfoLength > 0) {
|
||||
mMetadata.mGlobalLayerMask = new PSDGlobalLayerMask(imageInput);
|
||||
// System.out.println("mGlobalLayerMask: " + mGlobalLayerMask);
|
||||
metadata.globalLayerMask = new PSDGlobalLayerMask(imageInput);
|
||||
// System.out.println("globalLayerMask: " + globalLayerMask);
|
||||
}
|
||||
|
||||
read = imageInput.getStreamPosition() - pos;
|
||||
@@ -842,8 +836,8 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
private BufferedImage readLayerData(final PSDLayerInfo pLayerInfo, final ImageTypeSpecifier pRawType, final ImageTypeSpecifier pImageType) throws IOException {
|
||||
final int width = pLayerInfo.mRight - pLayerInfo.mLeft;
|
||||
final int height = pLayerInfo.mBottom - pLayerInfo.mTop;
|
||||
final int width = pLayerInfo.right - pLayerInfo.left;
|
||||
final int height = pLayerInfo.bottom - pLayerInfo.top;
|
||||
|
||||
// Even if raw/imageType has no alpha, the layers may still have alpha...
|
||||
ImageTypeSpecifier imageType = getImageTypeForLayer(pImageType, pLayerInfo);
|
||||
@@ -869,19 +863,19 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
final boolean banded = raster.getDataBuffer().getNumBanks() > 1;
|
||||
final int interleavedBands = banded ? 1 : raster.getNumBands();
|
||||
|
||||
for (PSDChannelInfo channelInfo : pLayerInfo.mChannelInfo) {
|
||||
for (PSDChannelInfo channelInfo : pLayerInfo.channelInfo) {
|
||||
int compression = imageInput.readUnsignedShort();
|
||||
|
||||
// Skip layer if we can't read it
|
||||
// channelId == -2 means "user supplied layer mask", whatever that is...
|
||||
if (width <= 0 || height <= 0 || channelInfo.mChannelId == -2 ||
|
||||
if (width <= 0 || height <= 0 || channelInfo.channelId == -2 ||
|
||||
(compression != PSD.COMPRESSION_NONE && compression != PSD.COMPRESSION_RLE)) {
|
||||
imageInput.skipBytes(channelInfo.mLength - 2);
|
||||
imageInput.skipBytes(channelInfo.length - 2);
|
||||
}
|
||||
else {
|
||||
// 0 = red, 1 = green, etc
|
||||
// -1 = transparency mask; -2 = user supplied layer mask
|
||||
int c = channelInfo.mChannelId == -1 ? pLayerInfo.mChannelInfo.length - 1 : channelInfo.mChannelId;
|
||||
int c = channelInfo.channelId == -1 ? pLayerInfo.channelInfo.length - 1 : channelInfo.channelId;
|
||||
|
||||
// NOTE: For layers, byte counts are written per channel, while for the composite data
|
||||
// byte counts are written for all channels before the image data.
|
||||
@@ -896,7 +890,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
// If RLE, the the image data starts with the byte counts
|
||||
// for all the scan lines in the channel (LayerBottom-LayerTop), with
|
||||
// each count stored as a two*byte value.
|
||||
byteCounts = new int[pLayerInfo.mBottom - pLayerInfo.mTop];
|
||||
byteCounts = new int[pLayerInfo.bottom - pLayerInfo.top];
|
||||
for (int i = 0; i < byteCounts.length; i++) {
|
||||
byteCounts[i] = imageInput.readUnsignedShort();
|
||||
}
|
||||
@@ -911,7 +905,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
|
||||
int bandOffset = banded ? 0 : interleavedBands - 1 - c;
|
||||
|
||||
switch (mHeader.mBits) {
|
||||
switch (header.bits) {
|
||||
case 1:
|
||||
byte[] row1 = ((DataBufferByte) rowRaster.getDataBuffer()).getData();
|
||||
// DataBufferByte buffer1 = (DataBufferByte) raster.getDataBuffer();
|
||||
@@ -935,7 +929,7 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
read16bitChannel(c, imageType.getNumBands(), raster.getDataBuffer(), interleavedBands, bandOffset, sourceCM, row16, area, area, xsub, ysub, width, height, byteCounts, 0, compression == PSD.COMPRESSION_RLE);
|
||||
break;
|
||||
default:
|
||||
throw new IIOException(String.format("Unknown PSD bit depth: %s", mHeader.mBits));
|
||||
throw new IIOException(String.format("Unknown PSD bit depth: %s", header.bits));
|
||||
}
|
||||
|
||||
if (abortRequested()) {
|
||||
@@ -949,17 +943,17 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
|
||||
private ImageTypeSpecifier getImageTypeForLayer(final ImageTypeSpecifier pOriginal, final PSDLayerInfo pLayerInfo) {
|
||||
// If layer has more channels than composite data, it's normally extra alpha...
|
||||
if (pLayerInfo.mChannelInfo.length > pOriginal.getNumBands()) {
|
||||
if (pLayerInfo.channelInfo.length > pOriginal.getNumBands()) {
|
||||
// ...but, it could also be just the user mask...
|
||||
boolean userMask = false;
|
||||
for (PSDChannelInfo channelInfo : pLayerInfo.mChannelInfo) {
|
||||
if (channelInfo.mChannelId == -2) {
|
||||
for (PSDChannelInfo channelInfo : pLayerInfo.channelInfo) {
|
||||
if (channelInfo.channelId == -2) {
|
||||
userMask = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int newBandNum = pLayerInfo.mChannelInfo.length - (userMask ? 1 : 0);
|
||||
int newBandNum = pLayerInfo.channelInfo.length - (userMask ? 1 : 0);
|
||||
|
||||
// If there really is more channels, then create new imageTypeSpec
|
||||
if (newBandNum > pOriginal.getNumBands()) {
|
||||
@@ -1004,22 +998,22 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIOMetadata getImageMetadata(final int pImageIndex) throws IOException {
|
||||
public IIOMetadata getImageMetadata(final int imageIndex) throws IOException {
|
||||
// TODO: Implement
|
||||
checkBounds(pImageIndex);
|
||||
checkBounds(imageIndex);
|
||||
|
||||
readHeader();
|
||||
readImageResources(true);
|
||||
readLayerAndMaskInfo(true);
|
||||
|
||||
// TODO: Need to make sure compression is set in metadata, even without reading the image data!
|
||||
mMetadata.mCompression = imageInput.readShort();
|
||||
metadata.compression = imageInput.readShort();
|
||||
|
||||
// mMetadata.mHeader = mHeader;
|
||||
// mMetadata.mColorData = mColorData;
|
||||
// mMetadata.mImageResources = mImageResources;
|
||||
// metadata.header = header;
|
||||
// metadata.colorData = colorData;
|
||||
// metadata.imageResources = imageResources;
|
||||
|
||||
return mMetadata; // TODO: clone if we change to mutable metadata
|
||||
return metadata; // TODO: clone if we change to mutable metadata
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1041,14 +1035,14 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
|
||||
List<PSDThumbnail> thumbnails = null;
|
||||
|
||||
if (mMetadata.mImageResources == null) {
|
||||
if (metadata.imageResources == null) {
|
||||
// TODO: Need flag here, to specify what resources to read...
|
||||
readImageResources(true);
|
||||
// TODO: Skip this, requires storing some stream offsets
|
||||
readLayerAndMaskInfo(false);
|
||||
}
|
||||
|
||||
for (PSDImageResource resource : mMetadata.mImageResources) {
|
||||
for (PSDImageResource resource : metadata.imageResources) {
|
||||
if (resource instanceof PSDThumbnail) {
|
||||
if (thumbnails == null) {
|
||||
thumbnails = new ArrayList<PSDThumbnail>();
|
||||
@@ -1147,15 +1141,15 @@ public class PSDImageReader extends ImageReaderBase {
|
||||
imageReader.setInput(stream);
|
||||
|
||||
imageReader.readHeader();
|
||||
// System.out.println("imageReader.mHeader: " + imageReader.mHeader);
|
||||
// System.out.println("imageReader.header: " + imageReader.header);
|
||||
|
||||
imageReader.readImageResources(true);
|
||||
System.out.println("imageReader.mImageResources: " + imageReader.mMetadata.mImageResources);
|
||||
System.out.println("imageReader.imageResources: " + imageReader.metadata.imageResources);
|
||||
System.out.println();
|
||||
|
||||
imageReader.readLayerAndMaskInfo(true);
|
||||
System.out.println("imageReader.mLayerInfo: " + imageReader.mMetadata.mLayerInfo);
|
||||
// System.out.println("imageReader.mGlobalLayerMask: " + imageReader.mGlobalLayerMask);
|
||||
System.out.println("imageReader.layerInfo: " + imageReader.metadata.layerInfo);
|
||||
// System.out.println("imageReader.globalLayerMask: " + imageReader.globalLayerMask);
|
||||
System.out.println();
|
||||
|
||||
IIOMetadata metadata = imageReader.getImageMetadata(0);
|
||||
|
||||
+17
-17
@@ -47,33 +47,33 @@ public class PSDImageResource {
|
||||
// TODO: Refactor image resources to separate package
|
||||
// TODO: Change constructor to store stream offset and length only (+ possibly the name), defer reading
|
||||
|
||||
final short mId;
|
||||
final String mName;
|
||||
final long mSize;
|
||||
final short id;
|
||||
final String name;
|
||||
final long size;
|
||||
|
||||
PSDImageResource(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
mId = pId;
|
||||
id = pId;
|
||||
|
||||
mName = PSDUtil.readPascalString(pInput);
|
||||
name = PSDUtil.readPascalString(pInput);
|
||||
|
||||
// Skip pad
|
||||
int nameSize = mName.length() + 1;
|
||||
int nameSize = name.length() + 1;
|
||||
if (nameSize % 2 != 0) {
|
||||
pInput.readByte();
|
||||
}
|
||||
|
||||
mSize = pInput.readUnsignedInt();
|
||||
size = pInput.readUnsignedInt();
|
||||
long startPos = pInput.getStreamPosition();
|
||||
|
||||
readData(new SubImageInputStream(pInput, mSize));
|
||||
readData(new SubImageInputStream(pInput, size));
|
||||
|
||||
// NOTE: This should never happen, however it's safer to keep it here to
|
||||
if (pInput.getStreamPosition() != startPos + mSize) {
|
||||
pInput.seek(startPos + mSize);
|
||||
if (pInput.getStreamPosition() != startPos + size) {
|
||||
pInput.seek(startPos + size);
|
||||
}
|
||||
|
||||
// Data is even-padded (word aligned)
|
||||
if (mSize % 2 != 0) {
|
||||
if (size % 2 != 0) {
|
||||
pInput.read();
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class PSDImageResource {
|
||||
*/
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
// TODO: This design is ugly, as subclasses readData is invoked BEFORE their respective constructor...
|
||||
pInput.skipBytes(mSize);
|
||||
pInput.skipBytes(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,7 +94,7 @@ public class PSDImageResource {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", data length: ");
|
||||
builder.append(mSize);
|
||||
builder.append(size);
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
@@ -103,16 +103,16 @@ public class PSDImageResource {
|
||||
protected StringBuilder toStringBuilder() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
|
||||
String fakeType = resourceTypeForId(mId);
|
||||
String fakeType = resourceTypeForId(id);
|
||||
if (fakeType != null) {
|
||||
builder.append("(").append(fakeType).append(")");
|
||||
}
|
||||
|
||||
builder.append("[ID: 0x");
|
||||
builder.append(Integer.toHexString(mId));
|
||||
if (mName != null && mName.trim().length() != 0) {
|
||||
builder.append(Integer.toHexString(id));
|
||||
if (name != null && name.trim().length() != 0) {
|
||||
builder.append(", name: \"");
|
||||
builder.append(mName);
|
||||
builder.append(name);
|
||||
builder.append("\"");
|
||||
}
|
||||
|
||||
|
||||
+22
-22
@@ -40,10 +40,10 @@ import java.io.IOException;
|
||||
* @version $Id: PSDLayerBlendMode.java,v 1.0 May 8, 2008 4:34:35 PM haraldk Exp$
|
||||
*/
|
||||
class PSDLayerBlendMode {
|
||||
final int mBlendMode;
|
||||
final int mOpacity; // 0-255
|
||||
final int mClipping; // 0: base, 1: non-base
|
||||
final int mFlags;
|
||||
final int blendMode;
|
||||
final int opacity; // 0-255
|
||||
final int clipping; // 0: base, 1: non-base
|
||||
final int flags;
|
||||
|
||||
public PSDLayerBlendMode(final ImageInputStream pInput) throws IOException {
|
||||
int blendModeSig = pInput.readInt();
|
||||
@@ -51,11 +51,11 @@ class PSDLayerBlendMode {
|
||||
throw new IIOException("Illegal PSD Blend Mode signature, expected 8BIM: " + PSDUtil.intToStr(blendModeSig));
|
||||
}
|
||||
|
||||
mBlendMode = pInput.readInt();
|
||||
blendMode = pInput.readInt();
|
||||
|
||||
mOpacity = pInput.readUnsignedByte();
|
||||
mClipping = pInput.readUnsignedByte();
|
||||
mFlags = pInput.readUnsignedByte();
|
||||
opacity = pInput.readUnsignedByte();
|
||||
clipping = pInput.readUnsignedByte();
|
||||
flags = pInput.readUnsignedByte();
|
||||
|
||||
pInput.readByte(); // Pad
|
||||
}
|
||||
@@ -65,10 +65,10 @@ class PSDLayerBlendMode {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
|
||||
builder.append("[");
|
||||
builder.append("mode: \"").append(PSDUtil.intToStr(mBlendMode));
|
||||
builder.append("\", opacity: ").append(mOpacity);
|
||||
builder.append(", clipping: ").append(mClipping);
|
||||
switch (mClipping) {
|
||||
builder.append("mode: \"").append(PSDUtil.intToStr(blendMode));
|
||||
builder.append("\", opacity: ").append(opacity);
|
||||
builder.append(", clipping: ").append(clipping);
|
||||
switch (clipping) {
|
||||
case 0:
|
||||
builder.append(" (base)");
|
||||
break;
|
||||
@@ -79,40 +79,40 @@ class PSDLayerBlendMode {
|
||||
builder.append(" (unknown)");
|
||||
break;
|
||||
}
|
||||
builder.append(", flags: ").append(byteToBinary(mFlags));
|
||||
builder.append(", flags: ").append(byteToBinary(flags));
|
||||
/*
|
||||
bit 0 = transparency protected; bit 1 = visible; bit 2 = obsolete;
|
||||
bit 3 = 1 for Photoshop 5.0 and later, tells if bit 4 has useful information;
|
||||
bit 4 = pixel data irrelevant to appearance of document
|
||||
*/
|
||||
builder.append(" (");
|
||||
if ((mFlags & 0x01) != 0) {
|
||||
if ((flags & 0x01) != 0) {
|
||||
builder.append("Transp. protected, ");
|
||||
}
|
||||
if ((mFlags & 0x02) != 0) {
|
||||
if ((flags & 0x02) != 0) {
|
||||
builder.append("Hidden, ");
|
||||
}
|
||||
if ((mFlags & 0x04) != 0) {
|
||||
if ((flags & 0x04) != 0) {
|
||||
builder.append("Obsolete bit, ");
|
||||
}
|
||||
if ((mFlags & 0x08) != 0) {
|
||||
if ((flags & 0x08) != 0) {
|
||||
builder.append("PS 5.0 data present, "); // "tells if next bit has useful information"...
|
||||
}
|
||||
if ((mFlags & 0x10) != 0) {
|
||||
if ((flags & 0x10) != 0) {
|
||||
builder.append("Pixel data irrelevant, ");
|
||||
}
|
||||
if ((mFlags & 0x20) != 0) {
|
||||
if ((flags & 0x20) != 0) {
|
||||
builder.append("Unknown bit 5, ");
|
||||
}
|
||||
if ((mFlags & 0x40) != 0) {
|
||||
if ((flags & 0x40) != 0) {
|
||||
builder.append("Unknown bit 6, ");
|
||||
}
|
||||
if ((mFlags & 0x80) != 0) {
|
||||
if ((flags & 0x80) != 0) {
|
||||
builder.append("Unknown bit 7, ");
|
||||
}
|
||||
|
||||
// Stupidity...
|
||||
if (mFlags != 0) {
|
||||
if (flags != 0) {
|
||||
builder.delete(builder.length() - 2, builder.length());
|
||||
}
|
||||
|
||||
|
||||
+33
-33
@@ -41,34 +41,34 @@ import java.util.Arrays;
|
||||
* @version $Id: PSDLayerInfo.java,v 1.0 Apr 29, 2008 6:01:12 PM haraldk Exp$
|
||||
*/
|
||||
class PSDLayerInfo {
|
||||
final int mTop;
|
||||
final int mLeft;
|
||||
final int mBottom;
|
||||
final int mRight;
|
||||
final int top;
|
||||
final int left;
|
||||
final int bottom;
|
||||
final int right;
|
||||
|
||||
final PSDChannelInfo[] mChannelInfo;
|
||||
final PSDLayerBlendMode mBlendMode;
|
||||
final PSDLayerMaskData mLayerMaskData;
|
||||
final PSDChannelSourceDestinationRange[] mRanges;
|
||||
final String mLayerName;
|
||||
final PSDChannelInfo[] channelInfo;
|
||||
final PSDLayerBlendMode blendMode;
|
||||
final PSDLayerMaskData layerMaskData;
|
||||
final PSDChannelSourceDestinationRange[] ranges;
|
||||
final String layerName;
|
||||
|
||||
PSDLayerInfo(ImageInputStream pInput) throws IOException {
|
||||
mTop = pInput.readInt();
|
||||
mLeft = pInput.readInt();
|
||||
mBottom = pInput.readInt();
|
||||
mRight = pInput.readInt();
|
||||
top = pInput.readInt();
|
||||
left = pInput.readInt();
|
||||
bottom = pInput.readInt();
|
||||
right = pInput.readInt();
|
||||
|
||||
int channels = pInput.readUnsignedShort();
|
||||
|
||||
mChannelInfo = new PSDChannelInfo[channels];
|
||||
channelInfo = new PSDChannelInfo[channels];
|
||||
for (int i = 0; i < channels; i++) {
|
||||
short channelId = pInput.readShort();
|
||||
long length = pInput.readUnsignedInt();
|
||||
|
||||
mChannelInfo[i] = new PSDChannelInfo(channelId, length);
|
||||
channelInfo[i] = new PSDChannelInfo(channelId, length);
|
||||
}
|
||||
|
||||
mBlendMode = new PSDLayerBlendMode(pInput);
|
||||
blendMode = new PSDLayerBlendMode(pInput);
|
||||
|
||||
// Lenght of layer mask data
|
||||
long extraDataSize = pInput.readUnsignedInt();
|
||||
@@ -78,10 +78,10 @@ class PSDLayerInfo {
|
||||
// Layer mask/adjustment layer data
|
||||
int layerMaskDataSize = pInput.readInt(); // May be 0, 20 or 36 bytes...
|
||||
if (layerMaskDataSize != 0) {
|
||||
mLayerMaskData = new PSDLayerMaskData(pInput, layerMaskDataSize);
|
||||
layerMaskData = new PSDLayerMaskData(pInput, layerMaskDataSize);
|
||||
}
|
||||
else {
|
||||
mLayerMaskData = null;
|
||||
layerMaskData = null;
|
||||
}
|
||||
|
||||
int layerBlendingDataSize = pInput.readInt();
|
||||
@@ -89,15 +89,15 @@ class PSDLayerInfo {
|
||||
throw new IIOException("Illegal PSD Layer Blending Data size: " + layerBlendingDataSize + ", expected multiple of 8");
|
||||
}
|
||||
|
||||
mRanges = new PSDChannelSourceDestinationRange[layerBlendingDataSize / 8];
|
||||
for (int i = 0; i < mRanges.length; i++) {
|
||||
mRanges[i] = new PSDChannelSourceDestinationRange(pInput, (i == 0 ? "Gray" : "Channel " + (i - 1)));
|
||||
ranges = new PSDChannelSourceDestinationRange[layerBlendingDataSize / 8];
|
||||
for (int i = 0; i < ranges.length; i++) {
|
||||
ranges[i] = new PSDChannelSourceDestinationRange(pInput, (i == 0 ? "Gray" : "Channel " + (i - 1)));
|
||||
}
|
||||
|
||||
|
||||
mLayerName = PSDUtil.readPascalString(pInput);
|
||||
layerName = PSDUtil.readPascalString(pInput);
|
||||
|
||||
int layerNameSize = mLayerName.length() + 1;
|
||||
int layerNameSize = layerName.length() + 1;
|
||||
|
||||
// Skip pad bytes for long word alignment
|
||||
if (layerNameSize % 4 != 0) {
|
||||
@@ -115,18 +115,18 @@ class PSDLayerInfo {
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[");
|
||||
builder.append("top: ").append(mTop);
|
||||
builder.append(", left: ").append(mLeft);
|
||||
builder.append(", bottom: ").append(mBottom);
|
||||
builder.append(", right: ").append(mRight);
|
||||
builder.append("top: ").append(top);
|
||||
builder.append(", left: ").append(left);
|
||||
builder.append(", bottom: ").append(bottom);
|
||||
builder.append(", right: ").append(right);
|
||||
|
||||
builder.append(", channels: ").append(Arrays.toString(mChannelInfo));
|
||||
builder.append(", blend mode: ").append(mBlendMode);
|
||||
if (mLayerMaskData != null) {
|
||||
builder.append(", layer mask data: ").append(mLayerMaskData);
|
||||
builder.append(", channels: ").append(Arrays.toString(channelInfo));
|
||||
builder.append(", blend mode: ").append(blendMode);
|
||||
if (layerMaskData != null) {
|
||||
builder.append(", layer mask data: ").append(layerMaskData);
|
||||
}
|
||||
builder.append(", ranges: ").append(Arrays.toString(mRanges));
|
||||
builder.append(", layer name: \"").append(mLayerName).append("\"");
|
||||
builder.append(", ranges: ").append(Arrays.toString(ranges));
|
||||
builder.append(", layer name: \"").append(layerName).append("\"");
|
||||
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
|
||||
+40
-40
@@ -40,48 +40,48 @@ import java.io.IOException;
|
||||
* @version $Id: PSDLayerMaskData.java,v 1.0 May 6, 2008 5:15:05 PM haraldk Exp$
|
||||
*/
|
||||
class PSDLayerMaskData {
|
||||
private int mTop;
|
||||
private int mLeft;
|
||||
private int mBottom;
|
||||
private int mRight;
|
||||
private int mDefaultColor;
|
||||
private int mFlags;
|
||||
private int top;
|
||||
private int left;
|
||||
private int bottom;
|
||||
private int right;
|
||||
private int defaultColor;
|
||||
private int flags;
|
||||
|
||||
private boolean mLarge;
|
||||
private int mRealFlags;
|
||||
private int mRealUserBackground;
|
||||
private int mRealTop;
|
||||
private int mRealLeft;
|
||||
private int mRealBottom;
|
||||
private int mRealRight;
|
||||
private boolean large;
|
||||
private int realFlags;
|
||||
private int realUserBackground;
|
||||
private int realTop;
|
||||
private int realLeft;
|
||||
private int realBottom;
|
||||
private int realRight;
|
||||
|
||||
PSDLayerMaskData(ImageInputStream pInput, int pSize) throws IOException {
|
||||
if (pSize != 20 && pSize != 36) {
|
||||
throw new IIOException("Illegal PSD Layer Mask data size: " + pSize + " (expeced 20 or 36)");
|
||||
}
|
||||
mTop = pInput.readInt();
|
||||
mLeft = pInput.readInt();
|
||||
mBottom = pInput.readInt();
|
||||
mRight = pInput.readInt();
|
||||
top = pInput.readInt();
|
||||
left = pInput.readInt();
|
||||
bottom = pInput.readInt();
|
||||
right = pInput.readInt();
|
||||
|
||||
mDefaultColor = pInput.readUnsignedByte();
|
||||
defaultColor = pInput.readUnsignedByte();
|
||||
|
||||
mFlags = pInput.readUnsignedByte();
|
||||
flags = pInput.readUnsignedByte();
|
||||
|
||||
if (pSize == 20) {
|
||||
pInput.readShort(); // Pad
|
||||
}
|
||||
else {
|
||||
// TODO: What to make out of this?
|
||||
mLarge = true;
|
||||
large = true;
|
||||
|
||||
mRealFlags = pInput.readUnsignedByte();
|
||||
mRealUserBackground = pInput.readUnsignedByte();
|
||||
realFlags = pInput.readUnsignedByte();
|
||||
realUserBackground = pInput.readUnsignedByte();
|
||||
|
||||
mRealTop = pInput.readInt();
|
||||
mRealLeft = pInput.readInt();
|
||||
mRealBottom = pInput.readInt();
|
||||
mRealRight = pInput.readInt();
|
||||
realTop = pInput.readInt();
|
||||
realLeft = pInput.readInt();
|
||||
realBottom = pInput.readInt();
|
||||
realRight = pInput.readInt();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,43 +89,43 @@ class PSDLayerMaskData {
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getSimpleName());
|
||||
builder.append("[");
|
||||
builder.append("top: ").append(mTop);
|
||||
builder.append(", left: ").append(mLeft);
|
||||
builder.append(", bottom: ").append(mBottom);
|
||||
builder.append(", right: ").append(mRight);
|
||||
builder.append(", default color: ").append(mDefaultColor);
|
||||
builder.append(", flags: ").append(Integer.toBinaryString(mFlags));
|
||||
builder.append("top: ").append(top);
|
||||
builder.append(", left: ").append(left);
|
||||
builder.append(", bottom: ").append(bottom);
|
||||
builder.append(", right: ").append(right);
|
||||
builder.append(", default color: ").append(defaultColor);
|
||||
builder.append(", flags: ").append(Integer.toBinaryString(flags));
|
||||
|
||||
// TODO: Maybe the flag bits have oposite order?
|
||||
builder.append(" (");
|
||||
if ((mFlags & 0x01) != 0) {
|
||||
if ((flags & 0x01) != 0) {
|
||||
builder.append("Pos. rel. to layer");
|
||||
}
|
||||
else {
|
||||
builder.append("Pos. abs.");
|
||||
}
|
||||
if ((mFlags & 0x02) != 0) {
|
||||
if ((flags & 0x02) != 0) {
|
||||
builder.append(", Mask disabled");
|
||||
}
|
||||
else {
|
||||
builder.append(", Mask enabled");
|
||||
}
|
||||
if ((mFlags & 0x04) != 0) {
|
||||
if ((flags & 0x04) != 0) {
|
||||
builder.append(", Invert mask");
|
||||
}
|
||||
if ((mFlags & 0x08) != 0) {
|
||||
if ((flags & 0x08) != 0) {
|
||||
builder.append(", Unknown bit 3");
|
||||
}
|
||||
if ((mFlags & 0x10) != 0) {
|
||||
if ((flags & 0x10) != 0) {
|
||||
builder.append(", Unknown bit 4");
|
||||
}
|
||||
if ((mFlags & 0x20) != 0) {
|
||||
if ((flags & 0x20) != 0) {
|
||||
builder.append(", Unknown bit 5");
|
||||
}
|
||||
if ((mFlags & 0x40) != 0) {
|
||||
if ((flags & 0x40) != 0) {
|
||||
builder.append(", Unknown bit 6");
|
||||
}
|
||||
if ((mFlags & 0x80) != 0) {
|
||||
if ((flags & 0x80) != 0) {
|
||||
builder.append(", Unknown bit 7");
|
||||
}
|
||||
builder.append(")");
|
||||
|
||||
+85
-85
@@ -27,12 +27,12 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
static final String NATIVE_METADATA_FORMAT_NAME = "com_twelvemonkeys_imageio_psd_image_1.0";
|
||||
static final String NATIVE_METADATA_FORMAT_CLASS_NAME = "com.twelvemonkeys.imageio.plugins.psd.PSDMetadataFormat";
|
||||
|
||||
PSDHeader mHeader;
|
||||
PSDColorData mColorData;
|
||||
int mCompression = -1;
|
||||
List<PSDImageResource> mImageResources;
|
||||
PSDGlobalLayerMask mGlobalLayerMask;
|
||||
List<PSDLayerInfo> mLayerInfo;
|
||||
PSDHeader header;
|
||||
PSDColorData colorData;
|
||||
int compression = -1;
|
||||
List<PSDImageResource> imageResources;
|
||||
PSDGlobalLayerMask globalLayerMask;
|
||||
List<PSDLayerInfo> layerInfo;
|
||||
|
||||
static final String[] COLOR_MODES = {
|
||||
"MONOCHROME", "GRAYSCALE", "INDEXED", "RGB", "CMYK", null, null, "MULTICHANNEL", "DUOTONE", "LAB"
|
||||
@@ -70,11 +70,11 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
root.appendChild(createHeaderNode());
|
||||
|
||||
if (mHeader.mMode == PSD.COLOR_MODE_INDEXED) {
|
||||
if (header.mode == PSD.COLOR_MODE_INDEXED) {
|
||||
root.appendChild(createPaletteNode());
|
||||
}
|
||||
|
||||
if (mImageResources != null && !mImageResources.isEmpty()) {
|
||||
if (imageResources != null && !imageResources.isEmpty()) {
|
||||
root.appendChild(createImageResourcesNode());
|
||||
}
|
||||
|
||||
@@ -86,11 +86,11 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
header.setAttribute("type", "PSD");
|
||||
header.setAttribute("version", "1");
|
||||
header.setAttribute("channels", Integer.toString(mHeader.mChannels));
|
||||
header.setAttribute("height", Integer.toString(mHeader.mHeight));
|
||||
header.setAttribute("width", Integer.toString(mHeader.mWidth));
|
||||
header.setAttribute("bits", Integer.toString(mHeader.mBits));
|
||||
header.setAttribute("mode", COLOR_MODES[mHeader.mMode]);
|
||||
header.setAttribute("channels", Integer.toString(this.header.channels));
|
||||
header.setAttribute("height", Integer.toString(this.header.height));
|
||||
header.setAttribute("width", Integer.toString(this.header.width));
|
||||
header.setAttribute("bits", Integer.toString(this.header.bits));
|
||||
header.setAttribute("mode", COLOR_MODES[this.header.mode]);
|
||||
|
||||
return header;
|
||||
}
|
||||
@@ -99,7 +99,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
IIOMetadataNode resource = new IIOMetadataNode("ImageResources");
|
||||
IIOMetadataNode node;
|
||||
|
||||
for (PSDImageResource imageResource : mImageResources) {
|
||||
for (PSDImageResource imageResource : imageResources) {
|
||||
// TODO: Always add name (if set) and id (as resourceId) to all nodes?
|
||||
// Resource Id is useful for people with access to the PSD spec..
|
||||
|
||||
@@ -128,7 +128,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
node = new IIOMetadataNode("AlphaChannelInfo");
|
||||
|
||||
for (String name : alphaChannelInfo.mNames) {
|
||||
for (String name : alphaChannelInfo.names) {
|
||||
IIOMetadataNode nameNode = new IIOMetadataNode("Name");
|
||||
nameNode.setAttribute("value", name);
|
||||
node.appendChild(nameNode);
|
||||
@@ -138,11 +138,11 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
PSDDisplayInfo displayInfo = (PSDDisplayInfo) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("DisplayInfo");
|
||||
node.setAttribute("colorSpace", DISPLAY_INFO_CS[displayInfo.mColorSpace]);
|
||||
node.setAttribute("colorSpace", DISPLAY_INFO_CS[displayInfo.colorSpace]);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (short color : displayInfo.mColors) {
|
||||
for (short color : displayInfo.colors) {
|
||||
if (builder.length() > 0) {
|
||||
builder.append(" ");
|
||||
}
|
||||
@@ -151,79 +151,79 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
}
|
||||
|
||||
node.setAttribute("colors", builder.toString());
|
||||
node.setAttribute("opacity", Integer.toString(displayInfo.mOpacity));
|
||||
node.setAttribute("kind", DISPLAY_INFO_KINDS[displayInfo.mKind]);
|
||||
node.setAttribute("opacity", Integer.toString(displayInfo.opacity));
|
||||
node.setAttribute("kind", DISPLAY_INFO_KINDS[displayInfo.kind]);
|
||||
}
|
||||
else if (imageResource instanceof PSDGridAndGuideInfo) {
|
||||
PSDGridAndGuideInfo info = (PSDGridAndGuideInfo) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("GridAndGuideInfo");
|
||||
node.setAttribute("version", String.valueOf(info.mVersion));
|
||||
node.setAttribute("verticalGridCycle", String.valueOf(info.mGridCycleVertical));
|
||||
node.setAttribute("horizontalGridCycle", String.valueOf(info.mGridCycleHorizontal));
|
||||
node.setAttribute("version", String.valueOf(info.version));
|
||||
node.setAttribute("verticalGridCycle", String.valueOf(info.gridCycleVertical));
|
||||
node.setAttribute("horizontalGridCycle", String.valueOf(info.gridCycleHorizontal));
|
||||
|
||||
for (PSDGridAndGuideInfo.GuideResource guide : info.mGuides) {
|
||||
for (PSDGridAndGuideInfo.GuideResource guide : info.guides) {
|
||||
IIOMetadataNode guideNode = new IIOMetadataNode("Guide");
|
||||
guideNode.setAttribute("location", Integer.toString(guide.mLocation));
|
||||
guideNode.setAttribute("orientation", GUIDE_ORIENTATIONS[guide.mDirection]);
|
||||
guideNode.setAttribute("location", Integer.toString(guide.location));
|
||||
guideNode.setAttribute("orientation", GUIDE_ORIENTATIONS[guide.direction]);
|
||||
}
|
||||
}
|
||||
else if (imageResource instanceof PSDPixelAspectRatio) {
|
||||
PSDPixelAspectRatio aspectRatio = (PSDPixelAspectRatio) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("PixelAspectRatio");
|
||||
node.setAttribute("version", String.valueOf(aspectRatio.mVersion));
|
||||
node.setAttribute("aspectRatio", String.valueOf(aspectRatio.mAspect));
|
||||
node.setAttribute("version", String.valueOf(aspectRatio.version));
|
||||
node.setAttribute("aspectRatio", String.valueOf(aspectRatio.aspect));
|
||||
}
|
||||
else if (imageResource instanceof PSDPrintFlags) {
|
||||
PSDPrintFlags flags = (PSDPrintFlags) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("PrintFlags");
|
||||
node.setAttribute("labels", String.valueOf(flags.mLabels));
|
||||
node.setAttribute("cropMarks", String.valueOf(flags.mCropMasks));
|
||||
node.setAttribute("colorBars", String.valueOf(flags.mColorBars));
|
||||
node.setAttribute("registrationMarks", String.valueOf(flags.mRegistrationMarks));
|
||||
node.setAttribute("negative", String.valueOf(flags.mNegative));
|
||||
node.setAttribute("flip", String.valueOf(flags.mFlip));
|
||||
node.setAttribute("interpolate", String.valueOf(flags.mInterpolate));
|
||||
node.setAttribute("caption", String.valueOf(flags.mCaption));
|
||||
node.setAttribute("labels", String.valueOf(flags.labels));
|
||||
node.setAttribute("cropMarks", String.valueOf(flags.cropMasks));
|
||||
node.setAttribute("colorBars", String.valueOf(flags.colorBars));
|
||||
node.setAttribute("registrationMarks", String.valueOf(flags.registrationMarks));
|
||||
node.setAttribute("negative", String.valueOf(flags.negative));
|
||||
node.setAttribute("flip", String.valueOf(flags.flip));
|
||||
node.setAttribute("interpolate", String.valueOf(flags.interpolate));
|
||||
node.setAttribute("caption", String.valueOf(flags.caption));
|
||||
}
|
||||
else if (imageResource instanceof PSDPrintFlagsInformation) {
|
||||
PSDPrintFlagsInformation information = (PSDPrintFlagsInformation) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("PrintFlagsInformation");
|
||||
node.setAttribute("version", String.valueOf(information.mVersion));
|
||||
node.setAttribute("cropMarks", String.valueOf(information.mCropMasks));
|
||||
node.setAttribute("field", String.valueOf(information.mField));
|
||||
node.setAttribute("bleedWidth", String.valueOf(information.mBleedWidth));
|
||||
node.setAttribute("bleedScale", String.valueOf(information.mBleedScale));
|
||||
node.setAttribute("version", String.valueOf(information.version));
|
||||
node.setAttribute("cropMarks", String.valueOf(information.cropMasks));
|
||||
node.setAttribute("field", String.valueOf(information.field));
|
||||
node.setAttribute("bleedWidth", String.valueOf(information.bleedWidth));
|
||||
node.setAttribute("bleedScale", String.valueOf(information.bleedScale));
|
||||
}
|
||||
else if (imageResource instanceof PSDPrintScale) {
|
||||
PSDPrintScale printScale = (PSDPrintScale) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("PrintScale");
|
||||
node.setAttribute("style", PRINT_SCALE_STYLES[printScale.mStyle]);
|
||||
node.setAttribute("xLocation", String.valueOf(printScale.mXLocation));
|
||||
node.setAttribute("yLocation", String.valueOf(printScale.mYlocation));
|
||||
node.setAttribute("scale", String.valueOf(printScale.mScale));
|
||||
node.setAttribute("style", PRINT_SCALE_STYLES[printScale.style]);
|
||||
node.setAttribute("xLocation", String.valueOf(printScale.xLocation));
|
||||
node.setAttribute("yLocation", String.valueOf(printScale.ylocation));
|
||||
node.setAttribute("scale", String.valueOf(printScale.scale));
|
||||
}
|
||||
else if (imageResource instanceof PSDResolutionInfo) {
|
||||
PSDResolutionInfo information = (PSDResolutionInfo) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("ResolutionInfo");
|
||||
node.setAttribute("horizontalResolution", String.valueOf(information.mHRes));
|
||||
node.setAttribute("horizontalResolutionUnit", RESOLUTION_UNITS[information.mHResUnit]);
|
||||
node.setAttribute("widthUnit", DIMENSION_UNITS[information.mWidthUnit]);
|
||||
node.setAttribute("verticalResolution", String.valueOf(information.mVRes));
|
||||
node.setAttribute("verticalResolutionUnit", RESOLUTION_UNITS[information.mVResUnit]);
|
||||
node.setAttribute("heightUnit", DIMENSION_UNITS[information.mHeightUnit]);
|
||||
node.setAttribute("horizontalResolution", String.valueOf(information.hRes));
|
||||
node.setAttribute("horizontalResolutionUnit", RESOLUTION_UNITS[information.hResUnit]);
|
||||
node.setAttribute("widthUnit", DIMENSION_UNITS[information.widthUnit]);
|
||||
node.setAttribute("verticalResolution", String.valueOf(information.vRes));
|
||||
node.setAttribute("verticalResolutionUnit", RESOLUTION_UNITS[information.vResUnit]);
|
||||
node.setAttribute("heightUnit", DIMENSION_UNITS[information.heightUnit]);
|
||||
}
|
||||
else if (imageResource instanceof PSDUnicodeAlphaNames) {
|
||||
PSDUnicodeAlphaNames alphaNames = (PSDUnicodeAlphaNames) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("UnicodeAlphaNames");
|
||||
|
||||
for (String name : alphaNames.mNames) {
|
||||
for (String name : alphaNames.names) {
|
||||
IIOMetadataNode nameNode = new IIOMetadataNode("Name");
|
||||
nameNode.setAttribute("value", name);
|
||||
node.appendChild(nameNode);
|
||||
@@ -233,11 +233,11 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
PSDVersionInfo information = (PSDVersionInfo) imageResource;
|
||||
|
||||
node = new IIOMetadataNode("VersionInfo");
|
||||
node.setAttribute("version", String.valueOf(information.mVersion));
|
||||
node.setAttribute("hasRealMergedData", String.valueOf(information.mHasRealMergedData));
|
||||
node.setAttribute("writer", information.mWriter);
|
||||
node.setAttribute("reader", information.mReader);
|
||||
node.setAttribute("fileVersion", String.valueOf(information.mFileVersion));
|
||||
node.setAttribute("version", String.valueOf(information.version));
|
||||
node.setAttribute("hasRealMergedData", String.valueOf(information.hasRealMergedData));
|
||||
node.setAttribute("writer", information.writer);
|
||||
node.setAttribute("reader", information.reader);
|
||||
node.setAttribute("fileVersion", String.valueOf(information.fileVersion));
|
||||
}
|
||||
else if (imageResource instanceof PSDThumbnail) {
|
||||
// TODO: Revise/rethink this...
|
||||
@@ -253,9 +253,9 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
node = new IIOMetadataNode("DirectoryResource");
|
||||
node.setAttribute("type", "IPTC");
|
||||
node.setUserObject(iptc.mDirectory);
|
||||
node.setUserObject(iptc.directory);
|
||||
|
||||
appendEntries(node, "IPTC", iptc.mDirectory);
|
||||
appendEntries(node, "IPTC", iptc.directory);
|
||||
}
|
||||
else if (imageResource instanceof PSDEXIF1Data) {
|
||||
// TODO: Revise/rethink this...
|
||||
@@ -264,9 +264,9 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
node = new IIOMetadataNode("DirectoryResource");
|
||||
node.setAttribute("type", "EXIF");
|
||||
// TODO: Set byte[] data instead
|
||||
node.setUserObject(exif.mDirectory);
|
||||
node.setUserObject(exif.directory);
|
||||
|
||||
appendEntries(node, "EXIF", exif.mDirectory);
|
||||
appendEntries(node, "EXIF", exif.directory);
|
||||
}
|
||||
else if (imageResource instanceof PSDXMPData) {
|
||||
// TODO: Revise/rethink this... Would it be possible to parse XMP as IIOMetadataNodes? Or is that just stupid...
|
||||
@@ -275,25 +275,25 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
node = new IIOMetadataNode("DirectoryResource");
|
||||
node.setAttribute("type", "XMP");
|
||||
appendEntries(node, "XMP", xmp.mDirectory);
|
||||
appendEntries(node, "XMP", xmp.directory);
|
||||
|
||||
// Set the entire XMP document as user data
|
||||
node.setUserObject(xmp.mData);
|
||||
node.setUserObject(xmp.data);
|
||||
}
|
||||
else {
|
||||
// Generic resource..
|
||||
node = new IIOMetadataNode("ImageResource");
|
||||
String value = PSDImageResource.resourceTypeForId(imageResource.mId);
|
||||
String value = PSDImageResource.resourceTypeForId(imageResource.id);
|
||||
if (!"UnknownResource".equals(value)) {
|
||||
node.setAttribute("name", value);
|
||||
}
|
||||
node.setAttribute("length", String.valueOf(imageResource.mSize));
|
||||
node.setAttribute("length", String.valueOf(imageResource.size));
|
||||
// TODO: Set user object: byte array
|
||||
}
|
||||
|
||||
// TODO: More resources
|
||||
|
||||
node.setAttribute("resourceId", String.format("0x%04x", imageResource.mId));
|
||||
node.setAttribute("resourceId", String.format("0x%04x", imageResource.id));
|
||||
resource.appendChild(node);
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
node = new IIOMetadataNode("ColorSpaceType");
|
||||
String cs;
|
||||
switch (mHeader.mMode) {
|
||||
switch (header.mode) {
|
||||
case PSD.COLOR_MODE_MONOCHROME:
|
||||
case PSD.COLOR_MODE_GRAYSCALE:
|
||||
case PSD.COLOR_MODE_DUOTONE: // Rationale: Spec says treat as gray...
|
||||
@@ -357,7 +357,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
cs = "CMYK";
|
||||
break;
|
||||
case PSD.COLOR_MODE_MULTICHANNEL:
|
||||
cs = getMultiChannelCS(mHeader.mChannels);
|
||||
cs = getMultiChannelCS(header.channels);
|
||||
break;
|
||||
case PSD.COLOR_MODE_LAB:
|
||||
cs = "Lab";
|
||||
@@ -370,7 +370,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
// TODO: Channels might be 5 for RGB + A + Mask... Probably not correct
|
||||
node = new IIOMetadataNode("NumChannels");
|
||||
node.setAttribute("value", Integer.toString(mHeader.mChannels));
|
||||
node.setAttribute("value", Integer.toString(header.channels));
|
||||
chroma_node.appendChild(node);
|
||||
|
||||
// TODO: Check if this is correct with bitmap (monchrome)
|
||||
@@ -378,7 +378,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
node.setAttribute("value", "true");
|
||||
chroma_node.appendChild(node);
|
||||
|
||||
if (mHeader.mMode == PSD.COLOR_MODE_INDEXED) {
|
||||
if (header.mode == PSD.COLOR_MODE_INDEXED) {
|
||||
node = createPaletteNode();
|
||||
chroma_node.appendChild(node);
|
||||
}
|
||||
@@ -411,7 +411,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
|
||||
private IIOMetadataNode createPaletteNode() {
|
||||
IIOMetadataNode node = new IIOMetadataNode("Palette");
|
||||
IndexColorModel cm = mColorData.getIndexColorModel();
|
||||
IndexColorModel cm = colorData.getIndexColorModel();
|
||||
|
||||
for (int i = 0; i < cm.getMapSize(); i++) {
|
||||
IIOMetadataNode entry = new IIOMetadataNode("PaletteEntry");
|
||||
@@ -442,7 +442,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
node = new IIOMetadataNode("CompressionTypeName");
|
||||
String compression;
|
||||
|
||||
switch (mCompression) {
|
||||
switch (this.compression) {
|
||||
case PSD.COMPRESSION_NONE:
|
||||
compression = "none";
|
||||
break;
|
||||
@@ -478,13 +478,13 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
dataNode.appendChild(node);
|
||||
|
||||
node = new IIOMetadataNode("SampleFormat");
|
||||
node.setAttribute("value", mHeader.mMode == PSD.COLOR_MODE_INDEXED ? "Index" : "UnsignedIntegral");
|
||||
node.setAttribute("value", header.mode == PSD.COLOR_MODE_INDEXED ? "Index" : "UnsignedIntegral");
|
||||
dataNode.appendChild(node);
|
||||
|
||||
String bitDepth = Integer.toString(mHeader.mBits); // bits per plane
|
||||
String bitDepth = Integer.toString(header.bits); // bits per plane
|
||||
|
||||
// TODO: Channels might be 5 for RGB + A + Mask...
|
||||
String[] bps = new String[mHeader.mChannels];
|
||||
String[] bps = new String[header.channels];
|
||||
Arrays.fill(bps, bitDepth);
|
||||
|
||||
node = new IIOMetadataNode("BitsPerSample");
|
||||
@@ -509,7 +509,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
Iterator<PSDPixelAspectRatio> ratios = getResources(PSDPixelAspectRatio.class);
|
||||
if (ratios.hasNext()) {
|
||||
PSDPixelAspectRatio ratio = ratios.next();
|
||||
aspect = (float) ratio.mAspect;
|
||||
aspect = (float) ratio.aspect;
|
||||
}
|
||||
|
||||
node.setAttribute("value", Float.toString(aspect));
|
||||
@@ -525,11 +525,11 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
PSDResolutionInfo resolutionInfo = resolutionInfos.next();
|
||||
|
||||
node = new IIOMetadataNode("HorizontalPixelSize");
|
||||
node.setAttribute("value", Float.toString(asMM(resolutionInfo.mHResUnit, resolutionInfo.mHRes)));
|
||||
node.setAttribute("value", Float.toString(asMM(resolutionInfo.hResUnit, resolutionInfo.hRes)));
|
||||
dimensionNode.appendChild(node);
|
||||
|
||||
node = new IIOMetadataNode("VerticalPixelSize");
|
||||
node.setAttribute("value", Float.toString(asMM(resolutionInfo.mVResUnit, resolutionInfo.mVRes)));
|
||||
node.setAttribute("value", Float.toString(asMM(resolutionInfo.vResUnit, resolutionInfo.vRes)));
|
||||
dimensionNode.appendChild(node);
|
||||
}
|
||||
|
||||
@@ -583,7 +583,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
PSDEXIF1Data data = exif.next();
|
||||
|
||||
// Get the EXIF DateTime (aka ModifyDate) tag if present
|
||||
Entry dateTime = data.mDirectory.getEntryById(TIFF.TAG_DATE_TIME);
|
||||
Entry dateTime = data.directory.getEntryById(TIFF.TAG_DATE_TIME);
|
||||
if (dateTime != null) {
|
||||
node = new IIOMetadataNode("ImageCreationTime"); // As TIFF, but could just as well be ImageModificationTime
|
||||
// Format: "YYYY:MM:DD hh:mm:ss"
|
||||
@@ -629,7 +629,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
if (textResource instanceof PSDIPTCData) {
|
||||
PSDIPTCData iptc = (PSDIPTCData) textResource;
|
||||
|
||||
appendTextEntriesFlat(text, iptc.mDirectory, new FilterIterator.Filter<Entry>() {
|
||||
appendTextEntriesFlat(text, iptc.directory, new FilterIterator.Filter<Entry>() {
|
||||
public boolean accept(final Entry pEntry) {
|
||||
Integer tagId = (Integer) pEntry.getIdentifier();
|
||||
|
||||
@@ -645,7 +645,7 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
else if (textResource instanceof PSDEXIF1Data) {
|
||||
PSDEXIF1Data exif = (PSDEXIF1Data) textResource;
|
||||
|
||||
appendTextEntriesFlat(text, exif.mDirectory, new FilterIterator.Filter<Entry>() {
|
||||
appendTextEntriesFlat(text, exif.directory, new FilterIterator.Filter<Entry>() {
|
||||
public boolean accept(final Entry pEntry) {
|
||||
Integer tagId = (Integer) pEntry.getIdentifier();
|
||||
|
||||
@@ -714,14 +714,14 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
}
|
||||
|
||||
private boolean hasAlpha() {
|
||||
return mHeader.mMode == PSD.COLOR_MODE_RGB && mHeader.mChannels >= 4 ||
|
||||
mHeader.mMode == PSD.COLOR_MODE_CMYK & mHeader.mChannels >= 5;
|
||||
return header.mode == PSD.COLOR_MODE_RGB && header.channels >= 4 ||
|
||||
header.mode == PSD.COLOR_MODE_CMYK & header.channels >= 5;
|
||||
}
|
||||
|
||||
<T extends PSDImageResource> Iterator<T> getResources(final Class<T> pResourceType) {
|
||||
// NOTE: The cast here is wrong, strictly speaking, but it does not matter...
|
||||
@SuppressWarnings({"unchecked"})
|
||||
Iterator<T> iterator = (Iterator<T>) mImageResources.iterator();
|
||||
Iterator<T> iterator = (Iterator<T>) imageResources.iterator();
|
||||
|
||||
return new FilterIterator<T>(iterator, new FilterIterator.Filter<T>() {
|
||||
public boolean accept(final T pElement) {
|
||||
@@ -731,12 +731,12 @@ public final class PSDMetadata extends AbstractMetadata {
|
||||
}
|
||||
|
||||
Iterator<PSDImageResource> getResources(final int... pResourceTypes) {
|
||||
Iterator<PSDImageResource> iterator = mImageResources.iterator();
|
||||
Iterator<PSDImageResource> iterator = imageResources.iterator();
|
||||
|
||||
return new FilterIterator<PSDImageResource>(iterator, new FilterIterator.Filter<PSDImageResource>() {
|
||||
public boolean accept(final PSDImageResource pResource) {
|
||||
for (int type : pResourceTypes) {
|
||||
if (type == pResource.mId) {
|
||||
if (type == pResource.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -12,8 +12,8 @@ import java.io.IOException;
|
||||
*/
|
||||
final class PSDPixelAspectRatio extends PSDImageResource {
|
||||
// 4 bytes (version = 1), 8 bytes double, x / y of a pixel
|
||||
int mVersion;
|
||||
double mAspect;
|
||||
int version;
|
||||
double aspect;
|
||||
|
||||
PSDPixelAspectRatio(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -21,7 +21,7 @@ final class PSDPixelAspectRatio extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mVersion = pInput.readInt();
|
||||
mAspect = pInput.readDouble();
|
||||
version = pInput.readInt();
|
||||
aspect = pInput.readDouble();
|
||||
}
|
||||
}
|
||||
|
||||
+25
-25
@@ -11,14 +11,14 @@ import java.io.IOException;
|
||||
* @version $Id: PSDPrintFlagsInfo.java,v 1.0 Jul 28, 2009 5:16:27 PM haraldk Exp$
|
||||
*/
|
||||
final class PSDPrintFlags extends PSDImageResource {
|
||||
boolean mLabels;
|
||||
boolean mCropMasks;
|
||||
boolean mColorBars;
|
||||
boolean mRegistrationMarks;
|
||||
boolean mNegative;
|
||||
boolean mFlip;
|
||||
boolean mInterpolate;
|
||||
boolean mCaption;
|
||||
boolean labels;
|
||||
boolean cropMasks;
|
||||
boolean colorBars;
|
||||
boolean registrationMarks;
|
||||
boolean negative;
|
||||
boolean flip;
|
||||
boolean interpolate;
|
||||
boolean caption;
|
||||
|
||||
PSDPrintFlags(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -26,30 +26,30 @@ final class PSDPrintFlags extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mLabels = pInput.readBoolean();
|
||||
mCropMasks = pInput.readBoolean();
|
||||
mColorBars = pInput.readBoolean();
|
||||
mRegistrationMarks = pInput.readBoolean();
|
||||
mNegative = pInput.readBoolean();
|
||||
mFlip = pInput.readBoolean();
|
||||
mInterpolate = pInput.readBoolean();
|
||||
mCaption = pInput.readBoolean();
|
||||
labels = pInput.readBoolean();
|
||||
cropMasks = pInput.readBoolean();
|
||||
colorBars = pInput.readBoolean();
|
||||
registrationMarks = pInput.readBoolean();
|
||||
negative = pInput.readBoolean();
|
||||
flip = pInput.readBoolean();
|
||||
interpolate = pInput.readBoolean();
|
||||
caption = pInput.readBoolean();
|
||||
|
||||
pInput.skipBytes(mSize - 8);
|
||||
pInput.skipBytes(size - 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", labels: ").append(mLabels);
|
||||
builder.append(", crop masks: ").append(mCropMasks);
|
||||
builder.append(", color bars: ").append(mColorBars);
|
||||
builder.append(", registration marks: ").append(mRegistrationMarks);
|
||||
builder.append(", negative: ").append(mNegative);
|
||||
builder.append(", flip: ").append(mFlip);
|
||||
builder.append(", interpolate: ").append(mInterpolate);
|
||||
builder.append(", caption: ").append(mCaption);
|
||||
builder.append(", labels: ").append(labels);
|
||||
builder.append(", crop masks: ").append(cropMasks);
|
||||
builder.append(", color bars: ").append(colorBars);
|
||||
builder.append(", registration marks: ").append(registrationMarks);
|
||||
builder.append(", negative: ").append(negative);
|
||||
builder.append(", flip: ").append(flip);
|
||||
builder.append(", interpolate: ").append(interpolate);
|
||||
builder.append(", caption: ").append(caption);
|
||||
|
||||
builder.append("]");
|
||||
|
||||
|
||||
+16
-16
@@ -11,11 +11,11 @@ import java.io.IOException;
|
||||
* @version $Id: PSDPrintFlagsInfo.java,v 1.0 Jul 28, 2009 5:16:27 PM haraldk Exp$
|
||||
*/
|
||||
final class PSDPrintFlagsInformation extends PSDImageResource {
|
||||
int mVersion;
|
||||
boolean mCropMasks;
|
||||
int mField;
|
||||
long mBleedWidth;
|
||||
int mBleedScale;
|
||||
int version;
|
||||
boolean cropMasks;
|
||||
int field;
|
||||
long bleedWidth;
|
||||
int bleedScale;
|
||||
|
||||
PSDPrintFlagsInformation(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -23,24 +23,24 @@ final class PSDPrintFlagsInformation extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mVersion = pInput.readUnsignedShort();
|
||||
mCropMasks = pInput.readBoolean();
|
||||
mField = pInput.readUnsignedByte(); // TODO: Is this really pad?
|
||||
mBleedWidth = pInput.readUnsignedInt();
|
||||
mBleedScale = pInput.readUnsignedShort();
|
||||
version = pInput.readUnsignedShort();
|
||||
cropMasks = pInput.readBoolean();
|
||||
field = pInput.readUnsignedByte(); // TODO: Is this really pad?
|
||||
bleedWidth = pInput.readUnsignedInt();
|
||||
bleedScale = pInput.readUnsignedShort();
|
||||
|
||||
pInput.skipBytes(mSize - 10);
|
||||
pInput.skipBytes(size - 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", version: ").append(mVersion);
|
||||
builder.append(", crop masks: ").append(mCropMasks);
|
||||
builder.append(", field: ").append(mField);
|
||||
builder.append(", bleed width: ").append(mBleedWidth);
|
||||
builder.append(", bleed scale: ").append(mBleedScale);
|
||||
builder.append(", version: ").append(version);
|
||||
builder.append(", crop masks: ").append(cropMasks);
|
||||
builder.append(", field: ").append(field);
|
||||
builder.append(", bleed width: ").append(bleedWidth);
|
||||
builder.append(", bleed scale: ").append(bleedScale);
|
||||
|
||||
builder.append("]");
|
||||
|
||||
|
||||
+8
-8
@@ -16,10 +16,10 @@ final class PSDPrintScale extends PSDImageResource {
|
||||
// 4 bytes y location (floating point).
|
||||
// 4 bytes scale (floating point)
|
||||
|
||||
short mStyle;
|
||||
float mXLocation;
|
||||
float mYlocation;
|
||||
float mScale;
|
||||
short style;
|
||||
float xLocation;
|
||||
float ylocation;
|
||||
float scale;
|
||||
|
||||
PSDPrintScale(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -27,9 +27,9 @@ final class PSDPrintScale extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mStyle = pInput.readShort();
|
||||
mXLocation = pInput.readFloat();
|
||||
mYlocation = pInput.readFloat();
|
||||
mScale = pInput.readFloat();
|
||||
style = pInput.readShort();
|
||||
xLocation = pInput.readFloat();
|
||||
ylocation = pInput.readFloat();
|
||||
scale = pInput.readFloat();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-20
@@ -50,12 +50,12 @@ class PSDResolutionInfo extends PSDImageResource {
|
||||
// WORD HeightUnit; /* 1=in, 2=cm, 3=pt, 4=picas, 5=columns */
|
||||
// } RESOLUTIONINFO;
|
||||
|
||||
float mHRes;
|
||||
short mHResUnit;
|
||||
short mWidthUnit;
|
||||
float mVRes;
|
||||
short mVResUnit;
|
||||
short mHeightUnit;
|
||||
float hRes;
|
||||
short hResUnit;
|
||||
short widthUnit;
|
||||
float vRes;
|
||||
short vResUnit;
|
||||
short heightUnit;
|
||||
|
||||
PSDResolutionInfo(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -63,32 +63,32 @@ class PSDResolutionInfo extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(ImageInputStream pInput) throws IOException {
|
||||
if (mSize != 16) {
|
||||
throw new IIOException("Resolution info length expected to be 16: " + mSize);
|
||||
if (size != 16) {
|
||||
throw new IIOException("Resolution info length expected to be 16: " + size);
|
||||
}
|
||||
|
||||
mHRes = PSDUtil.fixedPointToFloat(pInput.readInt());
|
||||
mHResUnit = pInput.readShort();
|
||||
mWidthUnit = pInput.readShort();
|
||||
mVRes = PSDUtil.fixedPointToFloat(pInput.readInt());
|
||||
mVResUnit = pInput.readShort();
|
||||
mHeightUnit = pInput.readShort();
|
||||
hRes = PSDUtil.fixedPointToFloat(pInput.readInt());
|
||||
hResUnit = pInput.readShort();
|
||||
widthUnit = pInput.readShort();
|
||||
vRes = PSDUtil.fixedPointToFloat(pInput.readInt());
|
||||
vResUnit = pInput.readShort();
|
||||
heightUnit = pInput.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", hRes: ").append(mHRes);
|
||||
builder.append(", hRes: ").append(hRes);
|
||||
builder.append(" ");
|
||||
builder.append(resUnit(mHResUnit));
|
||||
builder.append(resUnit(hResUnit));
|
||||
builder.append(", width unit: ");
|
||||
builder.append(dimUnit(mWidthUnit));
|
||||
builder.append(", vRes: ").append(mVRes);
|
||||
builder.append(dimUnit(widthUnit));
|
||||
builder.append(", vRes: ").append(vRes);
|
||||
builder.append(" ");
|
||||
builder.append(resUnit(mVResUnit));
|
||||
builder.append(resUnit(vResUnit));
|
||||
builder.append(", height unit: ");
|
||||
builder.append(dimUnit(mHeightUnit));
|
||||
builder.append(dimUnit(heightUnit));
|
||||
|
||||
builder.append("]");
|
||||
|
||||
|
||||
+11
-11
@@ -16,9 +16,9 @@ import java.io.IOException;
|
||||
* @version $Id: PSDThumbnail.java,v 1.0 Jul 29, 2009 4:41:06 PM haraldk Exp$
|
||||
*/
|
||||
class PSDThumbnail extends PSDImageResource {
|
||||
private BufferedImage mThumbnail;
|
||||
private int mWidth;
|
||||
private int mHeight;
|
||||
private BufferedImage thumbnail;
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public PSDThumbnail(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -50,8 +50,8 @@ class PSDThumbnail extends PSDImageResource {
|
||||
throw new IIOException(String.format("Unsupported thumbnail format (%s) in PSD document", format));
|
||||
}
|
||||
|
||||
mWidth = pInput.readInt();
|
||||
mHeight = pInput.readInt();
|
||||
width = pInput.readInt();
|
||||
height = pInput.readInt();
|
||||
|
||||
// This data isn't really useful, unless we're dealing with raw bytes
|
||||
int widthBytes = pInput.readInt();
|
||||
@@ -59,7 +59,7 @@ class PSDThumbnail extends PSDImageResource {
|
||||
|
||||
// Consistency check
|
||||
int sizeCompressed = pInput.readInt();
|
||||
if (sizeCompressed != (mSize - 28)) {
|
||||
if (sizeCompressed != (size - 28)) {
|
||||
throw new IIOException("Corrupt thumbnail in PSD document");
|
||||
}
|
||||
|
||||
@@ -72,26 +72,26 @@ class PSDThumbnail extends PSDImageResource {
|
||||
|
||||
// TODO: Defer decoding until getThumbnail?
|
||||
// TODO: Support BGR if id == RES_THUMBNAIL_PS4? Or is that already supported in the JPEG?
|
||||
mThumbnail = ImageIO.read(IIOUtil.createStreamAdapter(pInput, sizeCompressed));
|
||||
thumbnail = ImageIO.read(IIOUtil.createStreamAdapter(pInput, sizeCompressed));
|
||||
}
|
||||
|
||||
public final int getWidth() {
|
||||
return mWidth;
|
||||
return width;
|
||||
}
|
||||
|
||||
public final int getHeight() {
|
||||
return mHeight;
|
||||
return height;
|
||||
}
|
||||
|
||||
public final BufferedImage getThumbnail() {
|
||||
return mThumbnail;
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", ").append(mThumbnail);
|
||||
builder.append(", ").append(thumbnail);
|
||||
|
||||
builder.append("]");
|
||||
|
||||
|
||||
+4
-4
@@ -13,7 +13,7 @@ import java.util.List;
|
||||
* @version $Id: PSDUnicodeAlphaNames.java,v 1.0 Nov 7, 2009 9:16:56 PM haraldk Exp$
|
||||
*/
|
||||
final class PSDUnicodeAlphaNames extends PSDImageResource {
|
||||
List<String> mNames;
|
||||
List<String> names;
|
||||
|
||||
PSDUnicodeAlphaNames(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -21,12 +21,12 @@ final class PSDUnicodeAlphaNames extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mNames = new ArrayList<String>();
|
||||
names = new ArrayList<String>();
|
||||
|
||||
long left = mSize;
|
||||
long left = size;
|
||||
while (left > 0) {
|
||||
String name = PSDUtil.readUnicodeString(pInput);
|
||||
mNames.add(name);
|
||||
names.add(name);
|
||||
left -= name.length() * 2 + 4;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -12,11 +12,11 @@ import java.io.IOException;
|
||||
*/
|
||||
final class PSDVersionInfo extends PSDImageResource {
|
||||
|
||||
int mVersion;
|
||||
boolean mHasRealMergedData;
|
||||
String mWriter;
|
||||
String mReader;
|
||||
int mFileVersion;
|
||||
int version;
|
||||
boolean hasRealMergedData;
|
||||
String writer;
|
||||
String reader;
|
||||
int fileVersion;
|
||||
|
||||
PSDVersionInfo(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -32,24 +32,24 @@ final class PSDVersionInfo extends PSDImageResource {
|
||||
4 bytes file version.
|
||||
*/
|
||||
|
||||
mVersion = pInput.readInt();
|
||||
mHasRealMergedData = pInput.readBoolean();
|
||||
version = pInput.readInt();
|
||||
hasRealMergedData = pInput.readBoolean();
|
||||
|
||||
mWriter = PSDUtil.readUnicodeString(pInput);
|
||||
mReader = PSDUtil.readUnicodeString(pInput);
|
||||
writer = PSDUtil.readUnicodeString(pInput);
|
||||
reader = PSDUtil.readUnicodeString(pInput);
|
||||
|
||||
mFileVersion = pInput.readInt();
|
||||
fileVersion = pInput.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
builder.append(", version: ").append(mVersion);
|
||||
builder.append(", hasRealMergedData: ").append(mHasRealMergedData);
|
||||
builder.append(", writer: ").append(mWriter);
|
||||
builder.append(", reader: ").append(mReader);
|
||||
builder.append(", file version: ").append(mFileVersion);
|
||||
builder.append(", version: ").append(version);
|
||||
builder.append(", hasRealMergedData: ").append(hasRealMergedData);
|
||||
builder.append(", writer: ").append(writer);
|
||||
builder.append(", reader: ").append(reader);
|
||||
builder.append(", file version: ").append(fileVersion);
|
||||
builder.append("]");
|
||||
|
||||
return builder.toString();
|
||||
|
||||
+9
-9
@@ -22,8 +22,8 @@ import java.nio.charset.Charset;
|
||||
* @see <a href="http://www.adobe.com/devnet/xmp/">Adobe XMP Developer Center</a>
|
||||
*/
|
||||
final class PSDXMPData extends PSDImageResource {
|
||||
protected byte[] mData;
|
||||
Directory mDirectory;
|
||||
protected byte[] data;
|
||||
Directory directory;
|
||||
|
||||
PSDXMPData(final short pId, final ImageInputStream pInput) throws IOException {
|
||||
super(pId, pInput);
|
||||
@@ -31,21 +31,21 @@ final class PSDXMPData extends PSDImageResource {
|
||||
|
||||
@Override
|
||||
protected void readData(final ImageInputStream pInput) throws IOException {
|
||||
mData = new byte[(int) mSize]; // TODO: Fix potential overflow, or document why that can't happen (read spec)
|
||||
//pInput.readFully(mData);
|
||||
data = new byte[(int) size]; // TODO: Fix potential overflow, or document why that can't happen (read spec)
|
||||
//pInput.readFully(data);
|
||||
|
||||
mDirectory = new XMPReader().read(pInput);
|
||||
directory = new XMPReader().read(pInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = toStringBuilder();
|
||||
|
||||
int length = Math.min(256, mData.length);
|
||||
String data = StringUtil.decode(mData, 0, length, "UTF-8").replace('\n', ' ').replaceAll("\\s+", " ");
|
||||
int length = Math.min(256, data.length);
|
||||
String data = StringUtil.decode(this.data, 0, length, "UTF-8").replace('\n', ' ').replaceAll("\\s+", " ");
|
||||
builder.append(", data: \"").append(data);
|
||||
|
||||
if (length < mData.length) {
|
||||
if (length < this.data.length) {
|
||||
builder.append("...");
|
||||
}
|
||||
|
||||
@@ -60,6 +60,6 @@ final class PSDXMPData extends PSDImageResource {
|
||||
* @return the XMP metadata.
|
||||
*/
|
||||
public Reader getData() {
|
||||
return new InputStreamReader(new ByteArrayInputStream(mData), Charset.forName("UTF-8"));
|
||||
return new InputStreamReader(new ByteArrayInputStream(data), Charset.forName("UTF-8"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user