mirror of
https://github.com/haraldk/TwelveMonkeys.git
synced 2025-08-05 12:35:29 -04:00
Clean up of thumbnail support.
This commit is contained in:
parent
74cbb789a8
commit
ee8e1c47df
@ -765,7 +765,7 @@ public class PSDImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readImageResources(boolean pParseData) throws IOException {
|
private void readImageResources(final boolean pParseData) throws IOException {
|
||||||
// TODO: Avoid unnecessary stream repositioning
|
// TODO: Avoid unnecessary stream repositioning
|
||||||
long pos = mImageInput.getFlushedPosition();
|
long pos = mImageInput.getFlushedPosition();
|
||||||
mImageInput.seek(pos);
|
mImageInput.seek(pos);
|
||||||
@ -783,7 +783,7 @@ public class PSDImageReader extends ImageReaderBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mImageInput.getStreamPosition() != expectedEnd) {
|
if (mImageInput.getStreamPosition() != expectedEnd) {
|
||||||
throw new IIOException("Corrupt PSD document");
|
throw new IIOException("Corrupt PSD document"); // ..or maybe just a bug in the reader.. ;-)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -791,7 +791,7 @@ public class PSDImageReader extends ImageReaderBase {
|
|||||||
mImageInput.seek(pos + length + 4);
|
mImageInput.seek(pos + length + 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readLayerAndMaskInfo(boolean pParseData) throws IOException {
|
private void readLayerAndMaskInfo(final boolean pParseData) throws IOException {
|
||||||
// TODO: Make sure we are positioned correctly
|
// TODO: Make sure we are positioned correctly
|
||||||
long length = mImageInput.readUnsignedInt();
|
long length = mImageInput.readUnsignedInt();
|
||||||
if (pParseData && length > 0) {
|
if (pParseData && length > 0) {
|
||||||
@ -909,6 +909,7 @@ public class PSDImageReader extends ImageReaderBase {
|
|||||||
if (thumbnails == null) {
|
if (thumbnails == null) {
|
||||||
thumbnails = new ArrayList<PSDThumbnail>();
|
thumbnails = new ArrayList<PSDThumbnail>();
|
||||||
}
|
}
|
||||||
|
|
||||||
thumbnails.add((PSDThumbnail) resource);
|
thumbnails.add((PSDThumbnail) resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -921,39 +922,40 @@ public class PSDImageReader extends ImageReaderBase {
|
|||||||
public int getNumThumbnails(int pIndex) throws IOException {
|
public int getNumThumbnails(int pIndex) throws IOException {
|
||||||
List<PSDThumbnail> thumbnails = getThumbnailResources(pIndex);
|
List<PSDThumbnail> thumbnails = getThumbnailResources(pIndex);
|
||||||
|
|
||||||
|
return thumbnails == null ? 0 : thumbnails.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private PSDThumbnail getThumbnailResource(int pImageIndex, int pThumbnailIndex) throws IOException {
|
||||||
|
List<PSDThumbnail> thumbnails = getThumbnailResources(pImageIndex);
|
||||||
|
|
||||||
if (thumbnails == null) {
|
if (thumbnails == null) {
|
||||||
return 0;
|
throw new IndexOutOfBoundsException(String.format("thumbnail index %d > 0", pThumbnailIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
return thumbnails.size();
|
return thumbnails.get(pThumbnailIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getThumbnailWidth(int imageIndex, int thumbnailIndex) throws IOException {
|
public int getThumbnailWidth(int pImageIndex, int pThumbnailIndex) throws IOException {
|
||||||
// TODO: We could get this without decoding the thumbnail first
|
return getThumbnailResource(pImageIndex, pThumbnailIndex).getWidth();
|
||||||
return super.getThumbnailWidth(imageIndex, thumbnailIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getThumbnailHeight(int imageIndex, int thumbnailIndex) throws IOException {
|
public int getThumbnailHeight(int pImageIndex, int pThumbnailIndex) throws IOException {
|
||||||
// TODO: We could get this without decoding the thumbnail first
|
return getThumbnailResource(pImageIndex, pThumbnailIndex).getHeight();
|
||||||
return super.getThumbnailHeight(imageIndex, thumbnailIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BufferedImage readThumbnail(int pImageIndex, int pThumbnailIndex) throws IOException {
|
public BufferedImage readThumbnail(int pImageIndex, int pThumbnailIndex) throws IOException {
|
||||||
// TODO: Thumbnail listeners...
|
// TODO: Thumbnail listeners...
|
||||||
List<PSDThumbnail> thumbnails = getThumbnailResources(pImageIndex);
|
PSDThumbnail thumbnail = getThumbnailResource(pImageIndex, pThumbnailIndex);
|
||||||
if (thumbnails == null) {
|
|
||||||
throw new IndexOutOfBoundsException(String.format("%d > 0", pThumbnailIndex));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(pImageIndex, pThumbnailIndex);
|
||||||
processThumbnailComplete();
|
processThumbnailComplete();
|
||||||
|
|
||||||
return thumbnails.get(pThumbnailIndex).getThumbnail();
|
return thumbnail.getThumbnail();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Functional testing
|
/// Functional testing
|
||||||
|
@ -17,6 +17,8 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
class PSDThumbnail extends PSDImageResource {
|
class PSDThumbnail extends PSDImageResource {
|
||||||
private BufferedImage mThumbnail;
|
private BufferedImage mThumbnail;
|
||||||
|
private int mWidth;
|
||||||
|
private int mHeight;
|
||||||
|
|
||||||
public PSDThumbnail(final short pId, final ImageInputStream pInput) throws IOException {
|
public PSDThumbnail(final short pId, final ImageInputStream pInput) throws IOException {
|
||||||
super(pId, pInput);
|
super(pId, pInput);
|
||||||
@ -39,16 +41,19 @@ class PSDThumbnail extends PSDImageResource {
|
|||||||
int format = pInput.readInt();
|
int format = pInput.readInt();
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 0:
|
case 0:
|
||||||
|
// RAW RGB
|
||||||
throw new IIOException("RAW RGB format thumbnail not supported yet");
|
throw new IIOException("RAW RGB format thumbnail not supported yet");
|
||||||
case 1:
|
case 1:
|
||||||
|
// JPEG
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IIOException(String.format("Unsupported thumbnail format (%s) in PSD document", format));
|
throw new IIOException(String.format("Unsupported thumbnail format (%s) in PSD document", format));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mWidth = pInput.readInt();
|
||||||
|
mHeight = pInput.readInt();
|
||||||
|
|
||||||
// This data isn't really useful, unless we're dealing with raw bytes
|
// This data isn't really useful, unless we're dealing with raw bytes
|
||||||
int width = pInput.readInt();
|
|
||||||
int height = pInput.readInt();
|
|
||||||
int widthBytes = pInput.readInt();
|
int widthBytes = pInput.readInt();
|
||||||
int totalSize = pInput.readInt();
|
int totalSize = pInput.readInt();
|
||||||
|
|
||||||
@ -70,7 +75,15 @@ class PSDThumbnail extends PSDImageResource {
|
|||||||
mThumbnail = ImageIO.read(IIOUtil.createStreamAdapter(pInput, sizeCompressed));
|
mThumbnail = ImageIO.read(IIOUtil.createStreamAdapter(pInput, sizeCompressed));
|
||||||
}
|
}
|
||||||
|
|
||||||
public BufferedImage getThumbnail() {
|
public final int getWidth() {
|
||||||
|
return mWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int getHeight() {
|
||||||
|
return mHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final BufferedImage getThumbnail() {
|
||||||
return mThumbnail;
|
return mThumbnail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user