com.c3d.image.hips
Class HipsByteImage

java.lang.Object
  |
  +--com.c3d.image.hips.HipsImage
        |
        +--com.c3d.image.hips.HipsByteImage

public class HipsByteImage
extends HipsImage

Read a HIPS byte-coded image into memory. The (unsigned) chars are stored as bytes, which is almost certainly wrong.


Field Summary
protected  byte[][] frames_
           
 
Fields inherited from class com.c3d.image.hips.HipsImage
BUFSIZ, cols_, fcol_, frow_, isDataLoaded_, num_frame_, numcolor_, ocols_, orig_date_, orig_name_, orows_, params_, PFAHC, PFAHC3, PFASCII, PFBQ, PFBT, PFBYTE, PFCHAIN, PFCOLVEC, PFCOMPLEX, PFDBLCOM, PFDOUBLE, PFDVFFT2D, PFDVFFT3D, PFDVVFFT3D, PFFLOAT, PFFLOATPYR, PFGEN, PFGRLE, PFHIST, PFINT, PFINTPYR, PFLSBF, PFLUT, PFMIXED, PFMSBF, PFOCT, PFPOLAR, PFPOLYLINE, PFQUAD, PFQUAD1, PFRGB, PFRGBZ, PFRGISPLINE, PFRGPLINE, PFRLEB, PFRLED, PFRLEW, PFSBYTE, PFSHORT, PFSPAN, PFSRLE, PFSTEREO, PFUINT, PFUKOOA, PFUSHORT, PFVFFT2D, PFVFFT3D, PFVVFFT3D, pixel_format_, PLOT3D, rows_, seq_desc_, seq_history_, seq_name_, sizedesc_, sizehist_
 
Constructor Summary
  HipsByteImage(java.awt.Image image)
          Create a BufferedImage from a HIPS byte image.
  HipsByteImage(java.io.InputStream in)
          Load a byte image from a InputStream.
protected HipsByteImage(java.io.InputStream in, HipsImage hdr)
           
  HipsByteImage(int w, int h, int nImages, int nFramesPerImage)
           
  HipsByteImage(int w, int h, int nImages, int nFramesPerImage, byte[][] frames)
           
  HipsByteImage(java.lang.String fileName)
          Load a byte image from a InputStream.
 
Method Summary
protected static double b2d(byte b)
          Ugh...
 byte[] getFrame(int i)
          Return the i'th frame.
 byte[][] getFrames()
          Return all frames
 float[] getPixel(float x, float y, int imageIndex)
          Return the pixel at the specified location and in the specified image in the sequence.
 float[] getPixel(int xi, int yi, int imageIndex)
          Return the pixel at the specified location and in the specified image in the sequence.
 int[] rgbPixels(int imageIndex)
          Converts the plane information into a pixel in the direct colour model of java.
 HipsImage scale(double xScale, double yScale)
           
 HipsByteImage selectComponent(int index)
          Select an individual component color from a color image
 HipsByteImage selectFrame(int index)
          Select an individual component color from a color image
 void setFrame(int i, byte[] data)
          Set the i'th frame.
 HipsImage subImage(int srcX, int srcY, int width, int height)
           
 HipsByteImage toGray()
          Convert an image to gray
protected  void writeData(java.io.OutputStream out)
           
 
Methods inherited from class com.c3d.image.hips.HipsImage
b2i, bilinearInterp, byte2pixels, byte2pixels, cols, copyFrom, fcol, finishLine, frow, getHeight, getParam, getWidth, i2b, int2pixels, int2pixels, isDataLoaded, isMSB, main, num_frame, numcolor, numImage, numparam, numpix, orig_date, orig_name, params, pixel_format, readFrame, readFromStream, readLine, rows, seq_desc, seq_history, seq_name, setMSB, setParam, sizedesc, sizehist, sizeimage, sizepix, swab, swab2, writeBytes, writeFrame, writeLine, writeToFile, writeToStream
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frames_

protected byte[][] frames_
Constructor Detail

HipsByteImage

public HipsByteImage(java.io.InputStream in)
              throws HipsException,
                     java.io.IOException
Load a byte image from a InputStream. The stream is left open after the call.
Parameters:
in - The input stream

HipsByteImage

public HipsByteImage(java.lang.String fileName)
              throws HipsException,
                     java.io.FileNotFoundException,
                     java.io.IOException
Load a byte image from a InputStream. The stream is left open after thee call.
Parameters:
in - The input filename

HipsByteImage

protected HipsByteImage(java.io.InputStream in,
                        HipsImage hdr)
                 throws HipsException,
                        java.io.IOException

HipsByteImage

public HipsByteImage(java.awt.Image image)
              throws HipsException
Create a BufferedImage from a HIPS byte image. The image is created using the data from the HIPS image directly (in a databuffer) for efficiency public BufferedImage toBufferedAlphaImage(int imageIndex) { int w = getWidth(); int h = getHeight(); if (numcolor() != 1 && numcolor() != 3) { return null; } boolean isGray = (numcolor() == 1); ColorSpace colorSpace = isGray ? ColorSpace.getInstance(ColorSpace.CS_GRAY) : ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB); int[] bits = isGray ? new int[]{8} : new int[]{8,8,8,8}; ColorModel colorModel = new ComponentColorModel(colorSpace, bits, isGray ? false : true, false, isGray ? Transparency.OPAQUE : Transparency.TRANSLUCENT, DataBuffer.TYPE_BYTE); SampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE, w, h, isGray ? 1 : 4); DataBufferByte dataBuffer = null; if (isGray) { dataBuffer = new DataBufferByte(frames_, numpix()); } else { int sz = w*h; byte[][] frames = new byte[4][]; for (int i = 0; i < 3; i++) { frames[i] = frames_[i]; } frames[3] = new byte[sz]; for (int i = 0; i < sz; i++) { frames[3][i] = (byte)0xA0; } dataBuffer = new DataBufferByte(frames, numpix()); } WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, new Point(0,0)); return new BufferedImage(colorModel, raster, isGray ? true : false, null); } /** Create a BufferedImage from a HIPS byte image. The image is created using the data from the HIPS image directly (in a databuffer) for efficiency public BufferedImage toBufferedImage(int imageIndex) { int w = getWidth(); int h = getHeight(); if (numcolor() != 1 && numcolor() != 3) { return null; } boolean isGray = (numcolor() == 1); ColorSpace colorSpace = isGray ? ColorSpace.getInstance(ColorSpace.CS_GRAY) : ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB); int[] bits = isGray ? new int[]{8} : new int[]{8,8,8}; ColorModel colorModel = new ComponentColorModel(colorSpace, bits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); SampleModel sampleModel = new BandedSampleModel(DataBuffer.TYPE_BYTE, w, h, isGray ? 1 : 3); DataBuffer dataBuffer = new DataBufferByte(frames_, numpix()); WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuffer, new Point(0,0)); return new BufferedImage(colorModel, raster, true, null); } /** Load a HIPS image from an AWT image. The image is always in the default RGB format

HipsByteImage

public HipsByteImage(int w,
                     int h,
                     int nImages,
                     int nFramesPerImage)

HipsByteImage

public HipsByteImage(int w,
                     int h,
                     int nImages,
                     int nFramesPerImage,
                     byte[][] frames)
              throws HipsException
Method Detail

selectComponent

public HipsByteImage selectComponent(int index)
Select an individual component color from a color image

selectFrame

public HipsByteImage selectFrame(int index)
Select an individual component color from a color image

toGray

public HipsByteImage toGray()
Convert an image to gray

writeData

protected void writeData(java.io.OutputStream out)
                  throws java.io.IOException
Overrides:
writeData in class HipsImage

subImage

public HipsImage subImage(int srcX,
                          int srcY,
                          int width,
                          int height)
Overrides:
subImage in class HipsImage

getPixel

public float[] getPixel(int xi,
                        int yi,
                        int imageIndex)
Return the pixel at the specified location and in the specified image in the sequence. All values will be betwen 0.0 and 255.0. All images (even mono ones) return three value. When the image is mono all three values are the same.
Parameters:
xi - The x-location (column) of the pixel
yi - The y-location (row) of the pixel
imageIndex - The index of the image in the sequence (starting at 0) for which the pixel value is required.
Returns:
Three floating point numbers.
Overrides:
getPixel in class HipsImage

getPixel

public float[] getPixel(float x,
                        float y,
                        int imageIndex)
Return the pixel at the specified location and in the specified image in the sequence. All values will be betwen 0.0 and 255.0. All images (even mono ones) return three value. When the image is mono all three values are the same.

Floating point numbers are returned in case a a non-integral pixel location is chosen. Bilinear interpolation is used to obtain the value of pixels at non-integral locations.

Parameters:
x - The x-location (column) of the pixel
y - The y-location (row) of the pixel
imageIndex - The index of the image in the sequence (starting at 0) for which the pixel value is required.
Returns:
Three floating point numbers.
Overrides:
getPixel in class HipsImage

getFrame

public byte[] getFrame(int i)
Return the i'th frame. The number of frames can be found from num_frame(). Starts at 0.
Parameters:
i - The frame of data you want, returned as a linear array of bytes.
See Also:
HipsImage

getFrames

public byte[][] getFrames()
Return all frames
Returns:
The image data

setFrame

public void setFrame(int i,
                     byte[] data)
Set the i'th frame.
Parameters:
i - The frame of data you want to set
data - The data.
See Also:
HipsImage

rgbPixels

public int[] rgbPixels(int imageIndex)
                throws HipsException
Converts the plane information into a pixel in the direct colour model of java. It has to convert from the signed form of pixels to an unsigned representation before packing into an integer.
Parameters:
x - the x-location (column) of the pixel
y - the y-location (row) of the pixel
imageIndex - The image being indexex
Returns:
a Java direct color pixel
Overrides:
rgbPixels in class HipsImage

scale

public HipsImage scale(double xScale,
                       double yScale)
Overrides:
scale in class HipsImage

b2d

protected static final double b2d(byte b)
Ugh... converts signed bytes to unsigned value