fi.faidon.jis
Class JPEGImageSaver

java.lang.Object
  |
  +--fi.faidon.jis.ImageSaverInterface
        |
        +--fi.faidon.jis.JPEGImageSaver
All Implemented Interfaces:
java.awt.image.ImageConsumer, java.io.Serializable

public class JPEGImageSaver
extends ImageSaverInterface
implements java.io.Serializable, java.awt.image.ImageConsumer

Class for saving an image in the JPEG format.

See Also:
Serialized Form

Field Summary
protected  int Ah
           
protected  int Al
           
protected  boolean arithCode
           
protected static int BITS_IN_JSAMPLE
           
protected  int blocksInMCU
           
protected static int C_MAX_BLOCKS_IN_MCU
           
protected  boolean CCIR601sampling
           
protected  JPEGColor cconvert
           
protected  java.util.Vector compInfoVector
           
protected  int compsInScan
           
protected  java.util.Vector curCompInfo
           
protected  int dataPrecision
           
protected static int DCTSIZE
           
protected static int DCTSIZE2
           
protected  JPEGSample downsample
           
static java.lang.String FORMAT_CODE
           
static java.lang.String FORMAT_COMPLETE_NAME
           
static java.lang.String FORMAT_EXTENSION
           
protected  int height
           
protected  int inColorSpace
           
protected  int inputComponents
           
protected static int JBUF_CRANK_DEST
           
protected static int JBUF_PASS_THRU
          Operating modes for buffer controllers
protected static int JBUF_SAVE_AND_PASS
           
protected static int JBUF_SAVE_SOURCE
          Remaining modes require a full-image buffer to have been created
protected static int JPEG_MAX_DIMENSION
           
protected  int jpegColorSpace
           
protected  fi.faidon.jis.JPEGMainController main
           
protected  fi.faidon.jis.JPEGMaster master
           
protected static int MAX_COMPONENTS
           
protected static int MAX_COMPS_IN_SCAN
           
protected static int MAX_SAMP_FACTOR
           
protected  int maxHsampFactor
           
protected  int maxVsampFactor
           
protected  int[] MCUmembership
           
protected  int MCURowsInScan
           
protected  int MCUsPerRow
           
protected  int numComponents
           
protected  int numScans
           
protected  boolean optimizeCoding
           
protected  JPEGPrepController prep
           
protected  boolean progressiveMode
           
protected  boolean rawDataIn
           
protected  int restartInRows
           
protected  int restartInterval
           
protected  java.lang.Object scanInfo
           
protected  int Se
           
protected  int Ss
           
protected  int totaliMCURows
           
protected  int width
           
 
Fields inherited from class fi.faidon.jis.ImageSaverInterface
saveImage, savePath
 
Fields inherited from interface java.awt.image.ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
 
Constructor Summary
JPEGImageSaver()
           
 
Method Summary
 int checkSave()
          Return ImageObserver constants for indicating the state of the image saving.
 void emit2Bytes(int value)
          Emit a numeric value as two bytes.
 void emitByte(int value)
          Emit a numeric value as a byte.
 java.lang.String getFormatCode()
          ImageSaverInterface method implementations.
 java.lang.String getFormatExtension()
           
 java.lang.String getFormatString()
           
 void imageComplete(int status)
          Get imageComplete message so that we can close the output file.
static void jcopySampleRows(int[][] inputArray, int sourceRow, int[][] outputArray, int destRow, int numRows, int numCols)
          Copy some rows of samples from one place to another.
 boolean saveIt()
          Save the image.
 void setColorModel(java.awt.image.ColorModel model)
          If the default color model is an indexed color model and if it has a transparency pixel, then we put in an alpha channel.
 void setDimensions(int w, int h)
           
 void setHints(int hintflags)
           
 void setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, byte[] pixels, int off, int scansize)
          Write the pixels into the file as RGB data.
 void setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, int[] pixels, int off, int scansize)
           
 void setProperties(java.util.Hashtable props)
          ImageConsumer method implementations.
 void writeFrameHeader()
          Write frame header.
 void writeScanHeader()
          Write scan header.
 
Methods inherited from class fi.faidon.jis.ImageSaverInterface
getSaveImage, getSavePath, setSaveImage, setSavePath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORMAT_CODE

public static final java.lang.String FORMAT_CODE
See Also:
Constant Field Values

FORMAT_COMPLETE_NAME

public static final java.lang.String FORMAT_COMPLETE_NAME
See Also:
Constant Field Values

FORMAT_EXTENSION

public static final java.lang.String FORMAT_EXTENSION
See Also:
Constant Field Values

DCTSIZE

protected static final int DCTSIZE
See Also:
Constant Field Values

DCTSIZE2

protected static final int DCTSIZE2
See Also:
Constant Field Values

MAX_SAMP_FACTOR

protected static final int MAX_SAMP_FACTOR
See Also:
Constant Field Values

MAX_COMPONENTS

protected static final int MAX_COMPONENTS
See Also:
Constant Field Values

BITS_IN_JSAMPLE

protected static final int BITS_IN_JSAMPLE
See Also:
Constant Field Values

JPEG_MAX_DIMENSION

protected static final int JPEG_MAX_DIMENSION
See Also:
Constant Field Values

MAX_COMPS_IN_SCAN

protected static final int MAX_COMPS_IN_SCAN
See Also:
Constant Field Values

C_MAX_BLOCKS_IN_MCU

protected static final int C_MAX_BLOCKS_IN_MCU
See Also:
Constant Field Values

JBUF_PASS_THRU

protected static final int JBUF_PASS_THRU
Operating modes for buffer controllers

See Also:
Constant Field Values

JBUF_SAVE_SOURCE

protected static final int JBUF_SAVE_SOURCE
Remaining modes require a full-image buffer to have been created

See Also:
Constant Field Values

JBUF_CRANK_DEST

protected static final int JBUF_CRANK_DEST
See Also:
Constant Field Values

JBUF_SAVE_AND_PASS

protected static final int JBUF_SAVE_AND_PASS
See Also:
Constant Field Values

width

protected int width

height

protected int height

inputComponents

protected int inputComponents

inColorSpace

protected int inColorSpace

numComponents

protected int numComponents

dataPrecision

protected int dataPrecision

compInfoVector

protected java.util.Vector compInfoVector

curCompInfo

protected java.util.Vector curCompInfo

jpegColorSpace

protected int jpegColorSpace

optimizeCoding

protected boolean optimizeCoding

rawDataIn

protected boolean rawDataIn

arithCode

protected boolean arithCode

CCIR601sampling

protected boolean CCIR601sampling

progressiveMode

protected boolean progressiveMode

numScans

protected int numScans

scanInfo

protected java.lang.Object scanInfo

compsInScan

protected int compsInScan

maxHsampFactor

protected int maxHsampFactor

maxVsampFactor

protected int maxVsampFactor

totaliMCURows

protected int totaliMCURows

MCUsPerRow

protected int MCUsPerRow

MCURowsInScan

protected int MCURowsInScan

blocksInMCU

protected int blocksInMCU

MCUmembership

protected int[] MCUmembership

Ss

protected int Ss

Se

protected int Se

Ah

protected int Ah

Al

protected int Al

restartInterval

protected int restartInterval

restartInRows

protected int restartInRows

cconvert

protected JPEGColor cconvert

downsample

protected JPEGSample downsample

master

protected fi.faidon.jis.JPEGMaster master

prep

protected JPEGPrepController prep

main

protected fi.faidon.jis.JPEGMainController main
Constructor Detail

JPEGImageSaver

public JPEGImageSaver()
Method Detail

getFormatCode

public java.lang.String getFormatCode()
ImageSaverInterface method implementations.

Specified by:
getFormatCode in class ImageSaverInterface

getFormatString

public java.lang.String getFormatString()
Specified by:
getFormatString in class ImageSaverInterface

getFormatExtension

public java.lang.String getFormatExtension()
Specified by:
getFormatExtension in class ImageSaverInterface

saveIt

public boolean saveIt()
Save the image. This follows more or less the write_JPEG_file function in Example.c of the IJG Jpeg-6a library.

Specified by:
saveIt in class ImageSaverInterface

checkSave

public int checkSave()
Return ImageObserver constants for indicating the state of the image saving.

Specified by:
checkSave in class ImageSaverInterface

setProperties

public void setProperties(java.util.Hashtable props)
ImageConsumer method implementations.

Specified by:
setProperties in interface java.awt.image.ImageConsumer

setHints

public void setHints(int hintflags)
Specified by:
setHints in interface java.awt.image.ImageConsumer

setColorModel

public void setColorModel(java.awt.image.ColorModel model)
If the default color model is an indexed color model and if it has a transparency pixel, then we put in an alpha channel.

Specified by:
setColorModel in interface java.awt.image.ImageConsumer

setDimensions

public void setDimensions(int w,
                          int h)
Specified by:
setDimensions in interface java.awt.image.ImageConsumer

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      java.awt.image.ColorModel model,
                      byte[] pixels,
                      int off,
                      int scansize)
Write the pixels into the file as RGB data. For this to work correctly, pixels should be delivered in topdownleftright order with complete scanlines. If we have several lines, the lines should be complete scanlines, otherwise the saving fails.

Specified by:
setPixels in interface java.awt.image.ImageConsumer
See Also:
ImageConsumer.

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      java.awt.image.ColorModel model,
                      int[] pixels,
                      int off,
                      int scansize)
Specified by:
setPixels in interface java.awt.image.ImageConsumer
See Also:
ImageConsumer.

imageComplete

public void imageComplete(int status)
Get imageComplete message so that we can close the output file.

Specified by:
imageComplete in interface java.awt.image.ImageConsumer
See Also:
ImageConsumer.

writeFrameHeader

public void writeFrameHeader()
Write frame header. This consists of DQT and SOFn markers. Note that we do not emit the SOF until we have emitted the DQT(s). This avoids compatibility problems with incorrect implementations that try to error-check the quant table numbers as soon as they see the SOF. see write_frame_header in jcmarker.c of IJG Jpeg-6a library.


writeScanHeader

public void writeScanHeader()
Write scan header. This consists of DHT or DAC markers, optional DRI, and SOS. Compressed data will be written following the SOS. see write_scan_header in jcmarker.c of IJG Jpeg-6a library.


emit2Bytes

public void emit2Bytes(int value)
Emit a numeric value as two bytes.


emitByte

public void emitByte(int value)
Emit a numeric value as a byte.


jcopySampleRows

public static void jcopySampleRows(int[][] inputArray,
                                   int sourceRow,
                                   int[][] outputArray,
                                   int destRow,
                                   int numRows,
                                   int numCols)
Copy some rows of samples from one place to another. num_rows rows are copied from input_array[source_row++] to output_array[dest_row++]; these areas may overlap for duplication. The source and destination arrays must be at least as wide as num_cols. This method is here just to avoid getting as many files as in the C implementation. see jcopy_sample_rows in JQUANT1.c of IJG Jpeg-6a library.