jj2000.j2k.image.output
Class ImgWriterPPM

java.lang.Object
  |
  +--jj2000.j2k.image.output.ImgWriter
        |
        +--jj2000.j2k.image.output.ImgWriterPPM

public class ImgWriterPPM
extends ImgWriter

This class writes 3 components from an image in 8 bit unsigned data to a binary PPM file.

The size of the image that is written is the size of the source image. No component subsampling is allowed in any of the components that are written to the file.

Before writing, all coefficients are inversly level-shifted and then "saturated" (they are limited * to the nominal dynamic range).
Ex: if the nominal range is 0-255, the following algorithm is applied:
if coeff<0, output=0
if coeff>255, output=255
else output=coeff
The write() methods of an object of this class may not be called concurrently from different threads.

NOTE: This class is not thread safe, for reasons of internal buffering.


Field Summary
private  byte[] buf
          The line buffer.
private  int[] cps
          The array of indexes of the components from where to get the data
private  DataBlkInt db
          A DataBlk, just used to avoid allocating a new one each time it is needed
private  int[] fb
          The array of the number of fractional bits in the components of the source data
private  int[] levShift
          Value used to inverse level shift.
private  int offset
          The offset of the raw pixel data in the PPM file
private  java.io.RandomAccessFile out
          Where to write the data
 
Fields inherited from class jj2000.j2k.image.output.ImgWriter
DEF_STRIP_HEIGHT, h, src, w
 
Constructor Summary
ImgWriterPPM(java.io.File out, BlkImgDataSrc imgSrc, int n1, int n2, int n3)
          Creates a new writer to the specified File object, to write data from the specified component.
ImgWriterPPM(java.lang.String fname, BlkImgDataSrc imgSrc, int n1, int n2, int n3)
          Creates a new writer to the specified file, to write data from the specified component.
 
Method Summary
 void close()
          Closes the underlying file or netwrok connection to where the data is written.
 void flush()
          Writes all buffered data to the file or resource.
 java.lang.String toString()
          Returns a string of information about the object, more than 1 line long.
 void write()
          Writes the source's current tile to the output.
 void write(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.
private  void writeHeaderInfo()
          Writes the header info of the PPM file : P6
width height
255
 
Methods inherited from class jj2000.j2k.image.output.ImgWriter
finalize, writeAll
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

levShift

private int[] levShift
Value used to inverse level shift. One for each component


out

private java.io.RandomAccessFile out
Where to write the data


cps

private int[] cps
The array of indexes of the components from where to get the data


fb

private int[] fb
The array of the number of fractional bits in the components of the source data


db

private DataBlkInt db
A DataBlk, just used to avoid allocating a new one each time it is needed


offset

private int offset
The offset of the raw pixel data in the PPM file


buf

private byte[] buf
The line buffer.

Constructor Detail

ImgWriterPPM

public ImgWriterPPM(java.io.File out,
                    BlkImgDataSrc imgSrc,
                    int n1,
                    int n2,
                    int n3)
             throws java.io.IOException
Creates a new writer to the specified File object, to write data from the specified component.

The three components that will be written as R, G and B must be specified through the b1, b2 and b3 arguments.

Parameters:
out - The file where to write the data
imgSrc - The source from where to get the image data to write.
n1 - The index of the first component from where to get the data, that will be written as the red channel.
n2 - The index of the second component from where to get the data, that will be written as the green channel.
n3 - The index of the third component from where to get the data, that will be written as the green channel.
See Also:
DataBlk

ImgWriterPPM

public ImgWriterPPM(java.lang.String fname,
                    BlkImgDataSrc imgSrc,
                    int n1,
                    int n2,
                    int n3)
             throws java.io.IOException
Creates a new writer to the specified file, to write data from the specified component.

The three components that will be written as R, G and B must be specified through the b1, b2 and b3 arguments.

Parameters:
fname - The name of the file where to write the data
imgSrc - The source from where to get the image data to write.
n1 - The index of the first component from where to get the data, that will be written as the red channel.
n2 - The index of the second component from where to get the data, that will be written as the green channel.
n3 - The index of the third component from where to get the data, that will be written as the green channel.
See Also:
DataBlk
Method Detail

close

public void close()
           throws java.io.IOException
Closes 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:
close in class ImgWriter
Throws:
java.io.IOException - If an I/O error occurs.

flush

public void flush()
           throws java.io.IOException
Writes all buffered data to the file or resource.

Specified by:
flush in class 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.IOException
Writes 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.

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:
write in class 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.
Throws:
java.io.IOException - If an I/O error occurs.

write

public void write()
           throws java.io.IOException
Writes 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 any more.

Specified by:
write in class ImgWriter
Throws:
java.io.IOException - If an I/O error occurs.
See Also:
DataBlk

writeHeaderInfo

private void writeHeaderInfo()
                      throws java.io.IOException
Writes the header info of the PPM file : P6
width height
255

Throws:
java.io.IOException - If there is an I/O Error

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:
toString in class java.lang.Object
Returns:
A string of information about the object.