Package net.sourceforge.jiu.codecs
Class RASCodec
java.lang.Object
net.sourceforge.jiu.ops.Operation
net.sourceforge.jiu.codecs.ImageCodec
net.sourceforge.jiu.codecs.RASCodec
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
OnlyPaletted8Image / 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 pagerasterfile(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
FieldsModifier and TypeFieldDescriptionprivate intprivate static final intprivate intprivate intprivate DataInputprivate intprivate intprivate intprivate intprivate DataOutputprivate intprivate Paletteprivate static final intprivate static final intprivate intprivate int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the name of the file format supported by this codec.String[]Return the MIME (Multipurpose Internet Mail Extensions) type strings for this format, ornullif none are available.booleanReturns if this codec is able to load images in the file format supported by this codec.booleanReturns if this codec is able to save images in the file format supported by this codec.private voidload()Loads an image from an RAS input stream.voidprocess()This method does the actual work of the operation.private voidprivate IntegerImageprivate Paletteprivate voidsave()private voidsaveData(Paletted8Image image) private voidsaveHeader(PixelImage image) private voidsavePalette(Palette palette) suggestFileExtension(PixelImage image) Attempts to suggest a filename extension.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, getImage, getImageIndex, getInputAsDataInput, getInputStream, getMode, getNumComments, getOutputAsDataOutput, getOutputStream, getRandomAccessFile, hasBounds, initModeFromIOObjects, isRowRequired, isTileRequired, removeAllComments, removeBounds, setBounds, setBoundsIfNecessary, setDataInput, setDataOutput, setDpi, setFile, setFile, setImage, setImageIndex, setInputStream, setOutputStream, setRandomAccessFileMethods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
-
Field Details
-
RAS_MAGIC
private static final int RAS_MAGIC- See Also:
-
COMPRESSION_NONE
private static final int COMPRESSION_NONE- See Also:
-
RAS_HEADER_SIZE
private static final int RAS_HEADER_SIZE- See Also:
-
width
private int width -
height
private int height -
depth
private int depth -
length
private int length -
type
private int type -
mapType
private int mapType -
mapLength
private int mapLength -
bytesPerRow
private int bytesPerRow -
paddingBytes
private int paddingBytes -
numColors
private int numColors -
in
-
out
-
palette
-
-
Constructor Details
-
RASCodec
public RASCodec()
-
-
Method Details
-
getFormatName
Description copied from class:ImageCodecReturns the name of the file format supported by this codec. All classes extendingImageCodecmust override this method. When overriding, leave out any words in a particular language so that this format name can be understood by everyone. Usually it is enough to return the format creator plus a typical abbreviation, e.g.Microsoft BMPorPortable Anymap (PNM).- Specified by:
getFormatNamein classImageCodec- Returns:
- name of the file format supported by this codec
-
getMimeTypes
Description copied from class:ImageCodecReturn the MIME (Multipurpose Internet Mail Extensions) type strings for this format, ornullif none are available.- Specified by:
getMimeTypesin classImageCodec- Returns:
- MIME type strings or null
-
isLoadingSupported
public boolean isLoadingSupported()Description copied from class:ImageCodecReturns if this codec is able to load images in the file format supported by this codec. Iftrueis returned this does not necessarily mean that all files in this format can be read, but at least some.- Specified by:
isLoadingSupportedin classImageCodec- Returns:
- if loading is supported
-
isSavingSupported
public boolean isSavingSupported()Description copied from class:ImageCodecReturns if this codec is able to save images in the file format supported by this codec. Iftrueis returned this does not necessarily mean that all types files in this format can be written, but at least some.- Specified by:
isSavingSupportedin classImageCodec- Returns:
- if saving is supported
-
load
Loads an image from an RAS input stream. It is assumed that a stream was given to this codec usingImageCodec.setInputStream(InputStream).- Throws:
InvalidFileStructureException- if the input stream is corruptIOException- if there were problems reading from the input streamUnsupportedTypeException- if an unsupported flavor of the RAS format is encounteredWrongFileFormatException- if this is not a valid RAS streamOperationFailedException
-
process
Description copied from class:OperationThis method does the actual work of the operation. It must be called after all parameters have been given to the operation object.- Overrides:
processin classOperation- Throws:
WrongParameterException- if at least one of the input parameters was not initialized appropriately (values out of the valid interval, etc.)MissingParameterException- if any mandatory parameter was not given to the operationOperationFailedException
-
readHeader
private void readHeader() throws InvalidFileStructureException, UnsupportedTypeException, WrongFileFormatException, WrongParameterException, IOException -
readImage
-
readPalette
-
save
-
saveData
- Throws:
IOException
-
saveHeader
private void saveHeader(PixelImage image) throws IOException, UnsupportedTypeException, WrongParameterException -
savePalette
- Throws:
IOException
-
suggestFileExtension
Description copied from class:ImageCodecAttempts to suggest a filename extension. The type of the argument image will be taken into consideration, although this will be necessary for some file formats only (as an example, PNM has different extensions for different image types, seePNMCodec). This default implementation always returnsnull.- Overrides:
suggestFileExtensionin classImageCodec- Parameters:
image- the image that is to be written to a file- Returns:
- the file extension, including a leading dot, or
nullif no file extension can be recommended
-