Class ImgWriterRAW
- java.lang.Object
-
- jj2000.j2k.image.output.ImgWriter
-
- gov.nih.mipav.model.file.rawjp2.ImgWriterRAW
-
- Direct Known Subclasses:
ImgWriterRAWColor
public class ImgWriterRAW extends jj2000.j2k.image.output.ImgWriterThis class extends the ImgWriter abstract class for writing JP2 3D files. Each slice of the 3D image is written to the current offset in the ouput file. The class can take input data in ModelImage structure or BlkImgDataSrc (which is prefered in JJ2K context :-) Data: The image binary values appear one after the other (in raster order) immediately after the last header character ('\n') and are byte-aligned (they are packed into 1,2 or 4 bytes per sample, depending upon the bit-depth value).If the data is unsigned, level shifting is applied adding 2^(bit depth - 1)
NOTE: This class is not thread safe, for reasons of internal buffering.
- See Also:
ImgWriter,BlkImgDataSrc
-
-
Field Summary
Fields Modifier and Type Field Description protected intbitDepthThe bit-depth of the input file (must be between 1 and 31)private byte[]bufThe line buffer.protected intcThe index of the component from where to get the dataprotected jj2000.j2k.image.DataBlkIntdbA DataBlk, just used to avoid allocating a new one each time it is neededprivate intfbThe number of fractional bits in the source dataprotected intimgType(package private) booleanisSignedWhether the data must be signed when writing or not.(package private) intlevShiftUsed with level-shifting(package private) intmaxValUsed during saturation (2^bitdepth-1 if unsigned, 2^(bitdepth-1)-1 if signed)(package private) intminValUsed during saturation (0 if unsigned, -2^(bitdepth-1) if signed)protected ModelImagemodImgModel image pointerprotected intmodImgOffsetThe current offset of the raw pixel data in the RAW fileprotected intncThe number of layers/componentsprotected intoffsetThe current offset of the raw pixel data in the RAW fileprivate java.io.RandomAccessFileoutWhere to write the dataprotected intpackBytesThe pack length of one sample (in bytes, according to the output bit-depth
-
Constructor Summary
Constructors Constructor Description ImgWriterRAW(ModelImage mi, jj2000.j2k.image.BlkImgDataSrc imgSrc, boolean isSigned)ImgWriterRAW(java.io.File out, jj2000.j2k.image.BlkImgDataSrc imgSrc, int c, boolean isSigned)Creates a new writer to the specified File object, to write data from the specified component.ImgWriterRAW(java.lang.String fname, jj2000.j2k.image.BlkImgDataSrc imgSrc, int c, boolean isSigned)Creates a new writer to the specified file, to write data from the specified component.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the underlying file or netwrok connection to where the data is written.voidflush()Writes all buffered data to the file or resource.intgetImgType()intgetOffset()voidsetImgType(int imgType)voidsetOffset(int slcIdx)voidsetSrc(jj2000.j2k.image.BlkImgDataSrc slc)java.lang.StringtoString()Returns a string of information about the object, more than 1 line long.voidwrite()Writes the source's current tile to the output.voidwrite(int ulx, int uly, int w, int h)Writes the data of the specified area to the file, coordinates are relative to the current tile of the source.voidwriteModImg()voidwriteSlice()
-
-
-
Field Detail
-
maxVal
int maxVal
Used during saturation (2^bitdepth-1 if unsigned, 2^(bitdepth-1)-1 if signed)
-
minVal
int minVal
Used during saturation (0 if unsigned, -2^(bitdepth-1) if signed)
-
levShift
int levShift
Used with level-shifting
-
isSigned
boolean isSigned
Whether the data must be signed when writing or not. In the latter case inverse level shifting must be applied
-
bitDepth
protected int bitDepth
The bit-depth of the input file (must be between 1 and 31)
-
out
private java.io.RandomAccessFile out
Where to write the data
-
offset
protected int offset
The current offset of the raw pixel data in the RAW file
-
modImgOffset
protected int modImgOffset
The current offset of the raw pixel data in the RAW file
-
db
protected jj2000.j2k.image.DataBlkInt db
A DataBlk, just used to avoid allocating a new one each time it is needed
-
fb
private int fb
The number of fractional bits in the source data
-
c
protected int c
The index of the component from where to get the data
-
nc
protected int nc
The number of layers/components
-
packBytes
protected int packBytes
The pack length of one sample (in bytes, according to the output bit-depth
-
buf
private byte[] buf
The line buffer.
-
modImg
protected ModelImage modImg
Model image pointer
-
imgType
protected int imgType
-
-
Constructor Detail
-
ImgWriterRAW
public ImgWriterRAW(java.io.File out, jj2000.j2k.image.BlkImgDataSrc imgSrc, int c, boolean isSigned) throws java.io.IOExceptionCreates a new writer to the specified File object, to write data from the specified component.The size of the image that is written to the file is the size of the component from which to get the data, specified by b, not the size of the source image (they differ if there is some sub-sampling).
All the header informations are given by the BlkImgDataSrc source (component width, component height, bit-depth) and sign flag, which are provided to the constructor. The endianness is always big-endian (MSB first).
- Parameters:
out- The file where to write the dataimgSrc- The source from where to get the image data to write.c- The index of the component from where to get the data.isSigned- Whether the datas are signed or not (needed only when writing header).- Throws:
java.io.IOException- See Also:
DataBlk
-
ImgWriterRAW
public ImgWriterRAW(ModelImage mi, jj2000.j2k.image.BlkImgDataSrc imgSrc, boolean isSigned) throws java.io.IOException
- Throws:
java.io.IOException
-
ImgWriterRAW
public ImgWriterRAW(java.lang.String fname, jj2000.j2k.image.BlkImgDataSrc imgSrc, int c, boolean isSigned) throws java.io.IOExceptionCreates a new writer to the specified file, to write data from the specified component.The size of the image that is written to the file is the size of the component from which to get the data, specified by b, not the size of the source image (they differ if there is some sub-sampling).
All header information is given by the BlkImgDataSrc source (component width, component height, bit-depth) and sign flag, which are provided to the constructor. The endianness is always big-endian (MSB first).
- Parameters:
fname- The name of the file where to write the dataimgSrc- The source from where to get the image data to write.c- The index of the component from where to get the data.isSigned- Whether the datas are signed or not (needed only when writing header).- Throws:
java.io.IOException- See Also:
DataBlk
-
-
Method Detail
-
close
public void close() throws java.io.IOExceptionCloses the underlying file or netwrok connection to where the data is written. Any call to other methods of the class become illegal after a call to this one.- Specified by:
closein classjj2000.j2k.image.output.ImgWriter- Throws:
java.io.IOException- If an I/O error occurs.
-
flush
public void flush() throws java.io.IOExceptionWrites all buffered data to the file or resource.- Specified by:
flushin classjj2000.j2k.image.output.ImgWriter- Throws:
java.io.IOException- If an I/O error occurs.
-
write
public void write(int ulx, int uly, int w, int h) throws java.io.IOExceptionWrites the data of the specified area to the file, coordinates are relative to the current tile of the source. Before writing, the coefficients are limited to the nominal range and packed into 1,2 or 4 bytes (according to the bit-depth).If the data is unisigned, level shifting is applied adding 2^(bit depth - 1)
This method may not be called concurrently from different threads.
If the data returned from the BlkImgDataSrc source is progressive, then it is requested over and over until it is not progressive anymore.
- Specified by:
writein classjj2000.j2k.image.output.ImgWriter- Parameters:
ulx- The horizontal coordinate of the upper-left corner of the area to write, relative to the current tile.uly- The vertical coordinate of the upper-left corner of the area to write, relative to the current tile.width- The width of the area to write.height- The height of the area to write.- Throws:
java.io.IOException- If an I/O error occurs.
-
write
public void write() throws java.io.IOExceptionWrites the source's current tile to the output. The requests of data issued to the source BlkImgDataSrc object are done by strips, in order to reduce memory usage.If the data returned from the BlkImgDataSrc source is progressive, then it is requested over and over until it is not progressive anymore.
- Specified by:
writein classjj2000.j2k.image.output.ImgWriter- Throws:
java.io.IOException- If an I/O error occurs.- See Also:
DataBlk
-
writeModImg
public void writeModImg() throws java.io.IOException- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
Returns a string of information about the object, more than 1 line long. The information string includes information from the underlying RandomAccessFile (its toString() method is called in turn).- Overrides:
toStringin classjava.lang.Object- Returns:
- A string of information about the object.
-
getOffset
public int getOffset()
-
setOffset
public void setOffset(int slcIdx)
-
setSrc
public void setSrc(jj2000.j2k.image.BlkImgDataSrc slc)
-
writeSlice
public void writeSlice() throws java.io.IOException- Throws:
java.io.IOException
-
getImgType
public int getImgType()
-
setImgType
public void setImgType(int imgType)
-
-