net.sourceforge.jiu.codecs

Class RASCodec


public class RASCodec
extends ImageCodec

A codec to read and write Sun Raster (RAS) image files. The typical file extension for this format is .ras.

Usage example

This code snippet demonstrate how to read a RAS file.
 RASCodec codec = new RASCodec();
 codec.setFile("image.ras", CodecMode.LOAD);
 codec.process();
 PixelImage loadedImage = codec.getImage();
 

Supported file types when reading

Only uncompressed RAS files are read. Only 8 bit (gray and paletted) and 24 bit are supported when reading.

Supported image types when writing

Only Paletted8Image / uncompressed is supported when writing.

Bounds

The bounds concept of ImageCodec is supported so that you can load or save only part of an image.

File format documentation

This file format is documented as a man page rasterfile(5) on Sun Unix systems. That documentation can also be found online, e.g. at http://www.doc.ic.ac.uk/~mac/manuals/sunos-manual-pages/sunos4/usr/man/man5/rasterfile.5.html. A web search for rasterfile(5) brings up other places as well.
Author:
Marco Schmidt

Field Summary

private static int
COMPRESSION_NONE
private static int
RAS_HEADER_SIZE
private static int
RAS_MAGIC
private int
bytesPerRow
private int
depth
private int
height
private DataInput
in
private int
length
private int
mapLength
private int
mapType
private int
numColors
private DataOutput
out
private int
paddingBytes
private Palette
palette
private int
type
private int
width

Fields inherited from class net.sourceforge.jiu.codecs.ImageCodec

boundsAvail, boundsHeight, boundsWidth, boundsX1, boundsX2, boundsY1, boundsY2, comments, din, dout, dpiX, dpiY, image, imageIndex, in, mode, out, raf

Fields inherited from class net.sourceforge.jiu.ops.Operation

abort, progressListeners

Method Summary

String
getFormatName()
String[]
getMimeTypes()
boolean
isLoadingSupported()
boolean
isSavingSupported()
private void
load()
Loads an image from an RAS input stream.
void
process()
private void
readHeader()
private IntegerImage
readImage()
private Palette
readPalette()
private void
save()
private void
saveData(Paletted8Image image)
private void
saveHeader(PixelImage image)
private void
savePalette(Palette palette)
String
suggestFileExtension(PixelImage image)

Methods inherited from class net.sourceforge.jiu.codecs.ImageCodec

appendComment, checkBounds, checkImageResolution, close, getBoundsHeight, getBoundsWidth, getBoundsX1, getBoundsX2, getBoundsY1, getBoundsY2, getComment, getDataInput, getDataOutput, getDpiX, getDpiY, getFileExtensions, getFormatName, getImage, getImageIndex, getInputAsDataInput, getInputStream, getMimeTypes, getMode, getNumComments, getOutputAsDataOutput, getOutputStream, getRandomAccessFile, hasBounds, initModeFromIOObjects, isLoadingSupported, isRowRequired, isSavingSupported, isTileRequired, removeAllComments, removeBounds, setBounds, setBoundsIfNecessary, setDataInput, setDataOutput, setDpi, setFile, setFile, setImage, setImageIndex, setInputStream, setOutputStream, setRandomAccessFile, suggestFileExtension

Methods inherited from class net.sourceforge.jiu.ops.Operation

addProgressListener, addProgressListeners, getAbort, process, removeProgressListener, setAbort, setProgress, setProgress

Field Details

COMPRESSION_NONE

private static final int COMPRESSION_NONE
Field Value:
1

RAS_HEADER_SIZE

private static final int RAS_HEADER_SIZE
Field Value:
32

RAS_MAGIC

private static final int RAS_MAGIC
Field Value:
1504078485

bytesPerRow

private int bytesPerRow

depth

private int depth

height

private int height

in

private DataInput in

length

private int length

mapLength

private int mapLength

mapType

private int mapType

numColors

private int numColors

out

private DataOutput out

paddingBytes

private int paddingBytes

palette

private Palette palette

type

private int type

width

private int width

Method Details

getFormatName

public String getFormatName()
Overrides:
getFormatName in interface ImageCodec

getMimeTypes

public String[] getMimeTypes()
Overrides:
getMimeTypes in interface ImageCodec

isLoadingSupported

public boolean isLoadingSupported()
Overrides:
isLoadingSupported in interface ImageCodec

isSavingSupported

public boolean isSavingSupported()
Overrides:
isSavingSupported in interface ImageCodec

load

private void load()
            throws IOException,
                   OperationFailedException
Loads an image from an RAS input stream. It is assumed that a stream was given to this codec using setInputStream(InputStream).

process

public void process()
            throws OperationFailedException
Overrides:
process in interface Operation

readHeader

private void readHeader()
            throws InvalidFileStructureException,
                   UnsupportedTypeException,
                   WrongFileFormatException,
                   WrongParameterException,
                   IOException

readImage

private IntegerImage readImage()
            throws InvalidFileStructureException,
                   IOException

readPalette

private Palette readPalette()
            throws InvalidFileStructureException,
                   IOException

save

private void save()
            throws IOException,
                   UnsupportedTypeException,
                   WrongParameterException

saveData

private void saveData(Paletted8Image image)
            throws IOException

saveHeader

private void saveHeader(PixelImage image)
            throws IOException,
                   UnsupportedTypeException,
                   WrongParameterException

savePalette

private void savePalette(Palette palette)
            throws IOException

suggestFileExtension

public String suggestFileExtension(PixelImage image)
Overrides:
suggestFileExtension in interface ImageCodec