New code style. No functional changes.

This commit is contained in:
Harald Kuhr 2011-02-17 21:42:36 +01:00
parent dda46b0ab9
commit f1a4a79003
6 changed files with 74 additions and 74 deletions

View File

@ -76,8 +76,8 @@ public class PSDImageReader extends ImageReaderBase {
private ICC_ColorSpace colorSpace; private ICC_ColorSpace colorSpace;
protected PSDMetadata metadata; protected PSDMetadata metadata;
protected PSDImageReader(final ImageReaderSpi pOriginatingProvider) { protected PSDImageReader(final ImageReaderSpi originatingProvider) {
super(pOriginatingProvider); super(originatingProvider);
} }
protected void resetMembers() { protected void resetMembers() {
@ -86,25 +86,25 @@ public class PSDImageReader extends ImageReaderBase {
colorSpace = null; colorSpace = null;
} }
public int getWidth(final int pIndex) throws IOException { public int getWidth(final int imageIndex) throws IOException {
checkBounds(pIndex); checkBounds(imageIndex);
readHeader(); readHeader();
return header.width; return header.width;
} }
public int getHeight(final int pIndex) throws IOException { public int getHeight(final int imageIndex) throws IOException {
checkBounds(pIndex); checkBounds(imageIndex);
readHeader(); readHeader();
return header.height; return header.height;
} }
@Override @Override
public ImageTypeSpecifier getRawImageType(final int pIndex) throws IOException { public ImageTypeSpecifier getRawImageType(final int imageIndex) throws IOException {
return getRawImageTypeInternal(pIndex); return getRawImageTypeInternal(imageIndex);
} }
private ImageTypeSpecifier getRawImageTypeInternal(final int pIndex) throws IOException { private ImageTypeSpecifier getRawImageTypeInternal(final int imageIndex) throws IOException {
checkBounds(pIndex); checkBounds(imageIndex);
readHeader(); readHeader();
ColorSpace cs; ColorSpace cs;
@ -203,12 +203,12 @@ public class PSDImageReader extends ImageReaderBase {
} }
} }
public Iterator<ImageTypeSpecifier> getImageTypes(final int pIndex) throws IOException { public Iterator<ImageTypeSpecifier> getImageTypes(final int imageIndex) throws IOException {
// TODO: Check out the custom ImageTypeIterator and ImageTypeProducer used in the Sun provided JPEGImageReader // TODO: Check out the custom ImageTypeIterator and ImageTypeProducer used in the Sun provided JPEGImageReader
// Could use similar concept to create lazily-created ImageTypeSpecifiers (util candidate, based on FilterIterator?) // Could use similar concept to create lazily-created ImageTypeSpecifiers (util candidate, based on FilterIterator?)
// Get the raw type. Will fail for unsupported types // Get the raw type. Will fail for unsupported types
ImageTypeSpecifier rawType = getRawImageTypeInternal(pIndex); ImageTypeSpecifier rawType = getRawImageTypeInternal(imageIndex);
ColorSpace cs = rawType.getColorModel().getColorSpace(); ColorSpace cs = rawType.getColorModel().getColorSpace();
List<ImageTypeSpecifier> types = new ArrayList<ImageTypeSpecifier>(); List<ImageTypeSpecifier> types = new ArrayList<ImageTypeSpecifier>();
@ -295,21 +295,21 @@ public class PSDImageReader extends ImageReaderBase {
return colorSpace; return colorSpace;
} }
public BufferedImage read(final int pIndex, final ImageReadParam pParam) throws IOException { public BufferedImage read(final int imageIndex, final ImageReadParam param) throws IOException {
checkBounds(pIndex); checkBounds(imageIndex);
readHeader(); readHeader();
readImageResources(false); readImageResources(false);
readLayerAndMaskInfo(false); readLayerAndMaskInfo(false);
BufferedImage image = getDestination(pParam, getImageTypes(pIndex), header.width, header.height); BufferedImage image = getDestination(param, getImageTypes(imageIndex), header.width, header.height);
ImageTypeSpecifier rawType = getRawImageType(pIndex); ImageTypeSpecifier rawType = getRawImageType(imageIndex);
checkReadParamBandSettings(pParam, rawType.getNumBands(), image.getSampleModel().getNumBands()); checkReadParamBandSettings(param, rawType.getNumBands(), image.getSampleModel().getNumBands());
final Rectangle source = new Rectangle(); final Rectangle source = new Rectangle();
final Rectangle dest = new Rectangle(); final Rectangle dest = new Rectangle();
computeRegions(pParam, header.width, header.height, image, source, dest); computeRegions(param, 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. NOTE: It seems safe to just leave this out for now. The only thing we need is to support sub sampling.
@ -329,8 +329,8 @@ public class PSDImageReader extends ImageReaderBase {
// TODO: Banding... // TODO: Banding...
ImageTypeSpecifier spec = getRawImageType(pIndex); ImageTypeSpecifier spec = getRawImageType(imageIndex);
BufferedImage temp = spec.createBufferedImage(getWidth(pIndex), 1); BufferedImage temp = spec.createBufferedImage(getWidth(imageIndex), 1);
temp.getRaster(); temp.getRaster();
if (...) if (...)
@ -341,15 +341,15 @@ public class PSDImageReader extends ImageReaderBase {
final int xSub; final int xSub;
final int ySub; final int ySub;
if (pParam == null) { if (param == null) {
xSub = ySub = 1; xSub = ySub = 1;
} }
else { else {
xSub = pParam.getSourceXSubsampling(); xSub = param.getSourceXSubsampling();
ySub = pParam.getSourceYSubsampling(); ySub = param.getSourceYSubsampling();
} }
processImageStarted(pIndex); processImageStarted(imageIndex);
int[] byteCounts = null; int[] byteCounts = null;
int compression = imageInput.readShort(); int compression = imageInput.readShort();
@ -1028,8 +1028,8 @@ public class PSDImageReader extends ImageReaderBase {
return true; return true;
} }
private List<PSDThumbnail> getThumbnailResources(final int pIndex) throws IOException { private List<PSDThumbnail> getThumbnailResources(final int imageIndex) throws IOException {
checkBounds(pIndex); checkBounds(imageIndex);
readHeader(); readHeader();
@ -1056,40 +1056,40 @@ public class PSDImageReader extends ImageReaderBase {
} }
@Override @Override
public int getNumThumbnails(final int pIndex) throws IOException { public int getNumThumbnails(final int imageIndex) throws IOException {
List<PSDThumbnail> thumbnails = getThumbnailResources(pIndex); List<PSDThumbnail> thumbnails = getThumbnailResources(imageIndex);
return thumbnails == null ? 0 : thumbnails.size(); return thumbnails == null ? 0 : thumbnails.size();
} }
private PSDThumbnail getThumbnailResource(final int pImageIndex, final int pThumbnailIndex) throws IOException { private PSDThumbnail getThumbnailResource(final int imageIndex, final int thumbnailIndex) throws IOException {
List<PSDThumbnail> thumbnails = getThumbnailResources(pImageIndex); List<PSDThumbnail> thumbnails = getThumbnailResources(imageIndex);
if (thumbnails == null) { if (thumbnails == null) {
throw new IndexOutOfBoundsException(String.format("thumbnail index %d > 0", pThumbnailIndex)); throw new IndexOutOfBoundsException(String.format("thumbnail index %d > 0", thumbnailIndex));
} }
return thumbnails.get(pThumbnailIndex); return thumbnails.get(thumbnailIndex);
} }
@Override @Override
public int getThumbnailWidth(final int pImageIndex, final int pThumbnailIndex) throws IOException { public int getThumbnailWidth(final int imageIndex, final int thumbnailIndex) throws IOException {
return getThumbnailResource(pImageIndex, pThumbnailIndex).getWidth(); return getThumbnailResource(imageIndex, thumbnailIndex).getWidth();
} }
@Override @Override
public int getThumbnailHeight(final int pImageIndex, final int pThumbnailIndex) throws IOException { public int getThumbnailHeight(final int imageIndex, final int thumbnailIndex) throws IOException {
return getThumbnailResource(pImageIndex, pThumbnailIndex).getHeight(); return getThumbnailResource(imageIndex, thumbnailIndex).getHeight();
} }
@Override @Override
public BufferedImage readThumbnail(final int pImageIndex, final int pThumbnailIndex) throws IOException { public BufferedImage readThumbnail(final int imageIndex, final int thumbnailIndex) throws IOException {
// TODO: Thumbnail progress listeners... // TODO: Thumbnail progress listeners...
PSDThumbnail thumbnail = getThumbnailResource(pImageIndex, pThumbnailIndex); PSDThumbnail thumbnail = getThumbnailResource(imageIndex, thumbnailIndex);
// TODO: Defer decoding // TODO: Defer decoding
// TODO: It's possible to attach listeners to the ImageIO reader delegate... But do we really care? // TODO: It's possible to attach listeners to the ImageIO reader delegate... But do we really care?
processThumbnailStarted(pImageIndex, pThumbnailIndex); processThumbnailStarted(imageIndex, thumbnailIndex);
processThumbnailComplete(); processThumbnailComplete();
// TODO: Returning a cached mutable thumbnail is not really safe... // TODO: Returning a cached mutable thumbnail is not really safe...

View File

@ -53,10 +53,10 @@ public class PSDImageReaderSpi extends ImageReaderSpi {
this(IIOUtil.getProviderInfo(PSDImageReaderSpi.class)); this(IIOUtil.getProviderInfo(PSDImageReaderSpi.class));
} }
private PSDImageReaderSpi(final ProviderInfo pProviderInfo) { private PSDImageReaderSpi(final ProviderInfo providerInfo) {
super( super(
pProviderInfo.getVendorName(), providerInfo.getVendorName(),
pProviderInfo.getVersion(), providerInfo.getVersion(),
new String[]{"psd", "PSD"}, new String[]{"psd", "PSD"},
new String[]{"psd"}, new String[]{"psd"},
new String[]{ new String[]{

View File

@ -51,30 +51,30 @@ public class PSDImageResource {
final String name; final String name;
final long size; final long size;
PSDImageResource(final short pId, final ImageInputStream pInput) throws IOException { PSDImageResource(final short resourceId, final ImageInputStream input) throws IOException {
id = pId; id = resourceId;
name = PSDUtil.readPascalString(pInput); name = PSDUtil.readPascalString(input);
// Skip pad // Skip pad
int nameSize = name.length() + 1; int nameSize = name.length() + 1;
if (nameSize % 2 != 0) { if (nameSize % 2 != 0) {
pInput.readByte(); input.readByte();
} }
size = pInput.readUnsignedInt(); size = input.readUnsignedInt();
long startPos = pInput.getStreamPosition(); long startPos = input.getStreamPosition();
readData(new SubImageInputStream(pInput, size)); readData(new SubImageInputStream(input, size));
// NOTE: This should never happen, however it's safer to keep it here to // NOTE: This should never happen, however it's safer to keep it here to
if (pInput.getStreamPosition() != startPos + size) { if (input.getStreamPosition() != startPos + size) {
pInput.seek(startPos + size); input.seek(startPos + size);
} }
// Data is even-padded (word aligned) // Data is even-padded (word aligned)
if (size % 2 != 0) { if (size % 2 != 0) {
pInput.read(); input.read();
} }
} }

View File

@ -304,8 +304,8 @@ public final class PSDMetadata extends AbstractMetadata {
return resource; return resource;
} }
private void appendEntries(final IIOMetadataNode pNode, final String pType, final Directory pDirectory) { private void appendEntries(final IIOMetadataNode node, final String type, final Directory directory) {
for (Entry entry : pDirectory) { for (Entry entry : directory) {
Object tagId = entry.getIdentifier(); Object tagId = entry.getIdentifier();
IIOMetadataNode tag = new IIOMetadataNode("Entry"); IIOMetadataNode tag = new IIOMetadataNode("Entry");
@ -316,13 +316,13 @@ public final class PSDMetadata extends AbstractMetadata {
tag.setAttribute("field", String.format("%s", field)); tag.setAttribute("field", String.format("%s", field));
} }
else { else {
if ("IPTC".equals(pType)) { if ("IPTC".equals(type)) {
tag.setAttribute("field", String.format("%s:%s", (Integer) tagId >> 8, (Integer) tagId & 0xff)); tag.setAttribute("field", String.format("%s:%s", (Integer) tagId >> 8, (Integer) tagId & 0xff));
} }
} }
if (entry.getValue() instanceof Directory) { if (entry.getValue() instanceof Directory) {
appendEntries(tag, pType, (Directory) entry.getValue()); appendEntries(tag, type, (Directory) entry.getValue());
tag.setAttribute("type", "Directory"); tag.setAttribute("type", "Directory");
} }
else { else {
@ -330,7 +330,7 @@ public final class PSDMetadata extends AbstractMetadata {
tag.setAttribute("type", entry.getTypeName()); tag.setAttribute("type", entry.getTypeName());
} }
pNode.appendChild(tag); node.appendChild(tag);
} }
} }
@ -426,9 +426,9 @@ public final class PSDMetadata extends AbstractMetadata {
return node; return node;
} }
private String getMultiChannelCS(short pChannels) { private String getMultiChannelCS(short channels) {
if (pChannels < 16) { if (channels < 16) {
return String.format("%xCLR", pChannels); return String.format("%xCLR", channels);
} }
throw new UnsupportedOperationException("Standard meta data format does not support more than 15 channels"); throw new UnsupportedOperationException("Standard meta data format does not support more than 15 channels");
@ -563,9 +563,9 @@ public final class PSDMetadata extends AbstractMetadata {
return dimensionNode; return dimensionNode;
} }
private static float asMM(final short pUnit, final float pResolution) { private static float asMM(final short unit, final float resolution) {
// Unit: 1 -> pixels per inch, 2 -> pixels pr cm // Unit: 1 -> pixels per inch, 2 -> pixels pr cm
return (pUnit == 1 ? 25.4f : 10) / pResolution; return (unit == 1 ? 25.4f : 10) / resolution;
} }
@Override @Override
@ -670,13 +670,13 @@ public final class PSDMetadata extends AbstractMetadata {
return text; return text;
} }
private void appendTextEntriesFlat(final IIOMetadataNode pNode, final Directory pDirectory, final FilterIterator.Filter<Entry> pFilter) { private void appendTextEntriesFlat(final IIOMetadataNode node, final Directory directory, final FilterIterator.Filter<Entry> filter) {
FilterIterator<Entry> pEntries = new FilterIterator<Entry>(pDirectory.iterator(), pFilter); FilterIterator<Entry> pEntries = new FilterIterator<Entry>(directory.iterator(), filter);
while (pEntries.hasNext()) { while (pEntries.hasNext()) {
Entry entry = pEntries.next(); Entry entry = pEntries.next();
if (entry.getValue() instanceof Directory) { if (entry.getValue() instanceof Directory) {
appendTextEntriesFlat(pNode, (Directory) entry.getValue(), pFilter); appendTextEntriesFlat(node, (Directory) entry.getValue(), filter);
} }
else if (entry.getValue() instanceof String) { else if (entry.getValue() instanceof String) {
IIOMetadataNode tag = new IIOMetadataNode("TextEntry"); IIOMetadataNode tag = new IIOMetadataNode("TextEntry");
@ -691,7 +691,7 @@ public final class PSDMetadata extends AbstractMetadata {
} }
tag.setAttribute("value", entry.getValueAsString()); tag.setAttribute("value", entry.getValueAsString());
pNode.appendChild(tag); node.appendChild(tag);
} }
} }
} }
@ -718,24 +718,24 @@ public final class PSDMetadata extends AbstractMetadata {
header.mode == PSD.COLOR_MODE_CMYK & header.channels >= 5; header.mode == PSD.COLOR_MODE_CMYK & header.channels >= 5;
} }
<T extends PSDImageResource> Iterator<T> getResources(final Class<T> pResourceType) { <T extends PSDImageResource> Iterator<T> getResources(final Class<T> resourceType) {
// NOTE: The cast here is wrong, strictly speaking, but it does not matter... // NOTE: The cast here is wrong, strictly speaking, but it does not matter...
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
Iterator<T> iterator = (Iterator<T>) imageResources.iterator(); Iterator<T> iterator = (Iterator<T>) imageResources.iterator();
return new FilterIterator<T>(iterator, new FilterIterator.Filter<T>() { return new FilterIterator<T>(iterator, new FilterIterator.Filter<T>() {
public boolean accept(final T pElement) { public boolean accept(final T pElement) {
return pResourceType.isInstance(pElement); return resourceType.isInstance(pElement);
} }
}); });
} }
Iterator<PSDImageResource> getResources(final int... pResourceTypes) { Iterator<PSDImageResource> getResources(final int... resourceTypes) {
Iterator<PSDImageResource> iterator = imageResources.iterator(); Iterator<PSDImageResource> iterator = imageResources.iterator();
return new FilterIterator<PSDImageResource>(iterator, new FilterIterator.Filter<PSDImageResource>() { return new FilterIterator<PSDImageResource>(iterator, new FilterIterator.Filter<PSDImageResource>() {
public boolean accept(final PSDImageResource pResource) { public boolean accept(final PSDImageResource pResource) {
for (int type : pResourceTypes) { for (int type : resourceTypes) {
if (type == pResource.id) { if (type == pResource.id) {
return true; return true;
} }

View File

@ -195,7 +195,7 @@ public final class PSDMetadataFormat extends IIOMetadataFormatImpl {
@Override @Override
public boolean canNodeAppear(final String pElementName, final ImageTypeSpecifier pImageType) { public boolean canNodeAppear(final String elementName, final ImageTypeSpecifier imageType) {
// TODO: PSDColorData and PaletteEntry only for indexed color model // TODO: PSDColorData and PaletteEntry only for indexed color model
throw new UnsupportedOperationException("Method canNodeAppear not implemented"); // TODO: Implement throw new UnsupportedOperationException("Method canNodeAppear not implemented"); // TODO: Implement
} }

View File

@ -21,7 +21,7 @@ import java.io.IOException;
*/ */
public class PSDImageReaderTestCase extends ImageReaderAbstractTestCase<PSDImageReader> { public class PSDImageReaderTestCase extends ImageReaderAbstractTestCase<PSDImageReader> {
static ImageReaderSpi sProvider = new PSDImageReaderSpi(); static ImageReaderSpi provider = new PSDImageReaderSpi();
protected List<TestData> getTestData() { protected List<TestData> getTestData() {
return Arrays.asList( return Arrays.asList(
@ -49,12 +49,12 @@ public class PSDImageReaderTestCase extends ImageReaderAbstractTestCase<PSDImage
} }
protected ImageReaderSpi createProvider() { protected ImageReaderSpi createProvider() {
return sProvider; return provider;
} }
@Override @Override
protected PSDImageReader createReader() { protected PSDImageReader createReader() {
return new PSDImageReader(sProvider); return new PSDImageReader(provider);
} }
protected Class<PSDImageReader> getReaderClass() { protected Class<PSDImageReader> getReaderClass() {