forked from LupusNobilis/java-org.hwo
71 lines
1.2 KiB
Java
71 lines
1.2 KiB
Java
package org.hwo.image.tiff;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import org.hwo.compressor.LZW;
|
|
import org.hwo.image.UnsupportedFormatException;
|
|
|
|
class Strip
|
|
{
|
|
/**
|
|
*
|
|
*/
|
|
private final IFD ifd;
|
|
int offset,
|
|
length,
|
|
rowcount;
|
|
|
|
public Strip(IFD ifd, int offset,int length,int rowcount)
|
|
{
|
|
this.ifd = ifd;
|
|
this.offset = offset;
|
|
this.length = length;
|
|
this.rowcount = rowcount;
|
|
}
|
|
|
|
public int getOffset()
|
|
{
|
|
return offset;
|
|
}
|
|
public int getLength()
|
|
{
|
|
return length;
|
|
}
|
|
public int getRowCount()
|
|
{
|
|
return rowcount;
|
|
}
|
|
|
|
public ByteBuffer getBuffer()
|
|
{
|
|
ByteBuffer result;
|
|
|
|
switch (this.ifd.getCompression())
|
|
{
|
|
case 1:
|
|
this.ifd.tiffFile.sourceBuffer.position(offset);
|
|
result = this.ifd.tiffFile.sourceBuffer.slice();
|
|
break;
|
|
case 5:
|
|
byte[] source = new byte[ length ];
|
|
this.ifd.tiffFile.sourceBuffer.position(offset);
|
|
this.ifd.tiffFile.sourceBuffer.get(source);
|
|
|
|
LZW lzw = new LZW();
|
|
lzw.setCompressedData(source);
|
|
|
|
if (this.ifd.getFillOrder()==2)
|
|
lzw.setByteOrder(true);
|
|
|
|
lzw.decompress();
|
|
|
|
result = ByteBuffer.wrap(lzw.getUncompressedData());
|
|
break;
|
|
default:
|
|
throw new UnsupportedFormatException("Unsupported compression scheme");
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
} |