Moving the rest

This commit is contained in:
Erlend Hamnaberg
2010-01-29 19:40:12 +01:00
parent 40e6486154
commit ee99550a65
30 changed files with 0 additions and 0 deletions
@@ -0,0 +1,104 @@
package com.twelvemonkeys.imageio.plugins.psd;
import org.w3c.dom.Node;
import javax.imageio.metadata.IIOInvalidTreeException;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.metadata.IIOMetadataFormatImpl;
import java.util.Arrays;
/**
* AbstractMetadata
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: AbstractMetadata.java,v 1.0 Nov 13, 2009 1:02:12 AM haraldk Exp$
*/
abstract class AbstractMetadata extends IIOMetadata implements Cloneable {
// TODO: Move to core...
protected AbstractMetadata(final boolean pStandardFormatSupported,
final String pNativeFormatName, final String pNativeFormatClassName,
final String[] pExtraFormatNames, final String[] pExtraFormatClassNames) {
super(pStandardFormatSupported, pNativeFormatName, pNativeFormatClassName, pExtraFormatNames, pExtraFormatClassNames);
}
/**
* Default implementation returns {@code true}.
* Mutable subclasses should override this method.
*
* @return {@code true}.
*/
@Override
public boolean isReadOnly() {
return true;
}
@Override
public Node getAsTree(final String pFormatName) {
validateFormatName(pFormatName);
if (pFormatName.equals(nativeMetadataFormatName)) {
return getNativeTree();
}
else if (pFormatName.equals(IIOMetadataFormatImpl.standardMetadataFormatName)) {
return getStandardTree();
}
// TODO: What about extra formats??
throw new AssertionError("Unreachable");
}
@Override
public void mergeTree(final String pFormatName, final Node pRoot) throws IIOInvalidTreeException {
assertMutable();
validateFormatName(pFormatName);
if (!pRoot.getNodeName().equals(nativeMetadataFormatName)) {
throw new IIOInvalidTreeException("Root must be " + nativeMetadataFormatName, pRoot);
}
Node node = pRoot.getFirstChild();
while (node != null) {
// TODO: Merge values from node into this
// Move to the next sibling
node = node.getNextSibling();
}
}
@Override
public void reset() {
assertMutable();
}
/**
* Asserts that this meta data is mutable.
*
* @throws IllegalStateException if {@link #isReadOnly()} returns {@code true}.
*/
protected final void assertMutable() {
if (isReadOnly()) {
throw new IllegalStateException("Metadata is read-only");
}
}
protected abstract Node getNativeTree();
protected final void validateFormatName(final String pFormatName) {
String[] metadataFormatNames = getMetadataFormatNames();
if (metadataFormatNames != null) {
for (String metadataFormatName : metadataFormatNames) {
if (metadataFormatName.equals(pFormatName)) {
return; // Found, we're ok!
}
}
}
throw new IllegalArgumentException(
String.format("Bad format name: \"%s\". Expected one of %s", pFormatName, Arrays.toString(metadataFormatNames))
);
}
}
@@ -0,0 +1,58 @@
package com.twelvemonkeys.imageio.plugins.psd;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
/**
* PSDGridAndGuideInfo
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: PSDGridAndGuideInfo.java,v 1.0 Nov 7, 2009 8:46:13 PM haraldk Exp$
*/
final class PSDGridAndGuideInfo extends PSDImageResource {
/* Grid & guide header */
//typedef struct {
// guint32 fVersion; /* Version - always 1 for PS */
// guint32 fGridCycleV; /* Vertical grid size */
// guint32 fGridCycleH; /* Horizontal grid size */
// guint32 fGuideCount; /* Number of guides */
//} GuideHeader;
/* Guide resource block */
//typedef struct {
// guint32 fLocation; /* Guide position in Pixels * 100 */
// gchar fDirection; /* Guide orientation */
//} GuideResource;
int mVersion;
int mGridCycleVertical;
int mGridCycleHorizontal;
int mGuideCount;
GuideResource[] mGuides;
PSDGridAndGuideInfo(final short pId, final ImageInputStream pInput) throws IOException {
super(pId, pInput);
}
@Override
protected void readData(final ImageInputStream pInput) throws IOException {
mVersion = pInput.readInt();
mGridCycleVertical = pInput.readInt();
mGridCycleHorizontal = pInput.readInt();
mGuideCount = pInput.readInt();
mGuides = new GuideResource[mGuideCount];
for (GuideResource guide : mGuides) {
guide.mLocation = pInput.readInt();
guide.mDirection = pInput.readByte();
}
}
static class GuideResource {
int mLocation;
byte mDirection; // 0: vertical, 1: horizontal
}
}
@@ -0,0 +1,37 @@
package com.twelvemonkeys.imageio.plugins.psd;
import com.twelvemonkeys.imageio.metadata.Directory;
import com.twelvemonkeys.imageio.metadata.iptc.IPTCReader;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
/**
* PSDIPTCData
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: PSDIPTCData.java,v 1.0 Nov 7, 2009 9:52:14 PM haraldk Exp$
*/
final class PSDIPTCData extends PSDImageResource {
Directory mDirectory;
PSDIPTCData(final short pId, final ImageInputStream pInput) throws IOException {
super(pId, pInput);
}
@Override
protected void readData(final ImageInputStream pInput) throws IOException {
// Read IPTC directory
mDirectory = new IPTCReader().read(pInput);
}
@Override
public String toString() {
StringBuilder builder = toStringBuilder();
builder.append(", ").append(mDirectory);
builder.append("]");
return builder.toString();
}
}
@@ -0,0 +1,27 @@
package com.twelvemonkeys.imageio.plugins.psd;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
/**
* PSDPixelAspectRatio
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: PSDPixelAspectRatio.java,v 1.0 Nov 7, 2009 8:23:09 PM haraldk Exp$
*/
final class PSDPixelAspectRatio extends PSDImageResource {
// 4 bytes (version = 1), 8 bytes double, x / y of a pixel
int mVersion;
double mAspect;
PSDPixelAspectRatio(final short pId, final ImageInputStream pInput) throws IOException {
super(pId, pInput);
}
@Override
protected void readData(final ImageInputStream pInput) throws IOException {
mVersion = pInput.readInt();
mAspect = pInput.readDouble();
}
}
@@ -0,0 +1,35 @@
package com.twelvemonkeys.imageio.plugins.psd;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
/**
* PSDPrintScale
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: PSDPrintScale.java,v 1.0 Nov 7, 2009 9:41:17 PM haraldk Exp$
*/
final class PSDPrintScale extends PSDImageResource {
// 2 bytes style (0 = centered, 1 = size to fit, 2 = user defined).
// 4 bytes x location (floating point).
// 4 bytes y location (floating point).
// 4 bytes scale (floating point)
short mStyle;
float mXLocation;
float mYlocation;
float mScale;
PSDPrintScale(final short pId, final ImageInputStream pInput) throws IOException {
super(pId, pInput);
}
@Override
protected void readData(final ImageInputStream pInput) throws IOException {
mStyle = pInput.readShort();
mXLocation = pInput.readFloat();
mYlocation = pInput.readFloat();
mScale = pInput.readFloat();
}
}
@@ -0,0 +1,33 @@
package com.twelvemonkeys.imageio.plugins.psd;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* PSDUnicodeAlphaNames
*
* @author <a href="mailto:harald.kuhr@gmail.com">Harald Kuhr</a>
* @author last modified by $Author: haraldk$
* @version $Id: PSDUnicodeAlphaNames.java,v 1.0 Nov 7, 2009 9:16:56 PM haraldk Exp$
*/
final class PSDUnicodeAlphaNames extends PSDImageResource {
List<String> mNames;
PSDUnicodeAlphaNames(final short pId, final ImageInputStream pInput) throws IOException {
super(pId, pInput);
}
@Override
protected void readData(final ImageInputStream pInput) throws IOException {
mNames = new ArrayList<String>();
long left = mSize;
while (left > 0) {
String name = PSDUtil.readUnicodeString(pInput);
mNames.add(name);
left -= name.length() * 2 + 4;
}
}
}