net.sourceforge.jiu.codecs

Class BMPCodec


public class BMPCodec
extends ImageCodec

A codec to read and write Windows BMP image files.

Typical file extensions are .bmp and .rle (the latter is only used for compressed files).

Bounds

This codec supports the bounds concept for loading and saving.

Supported BMP types when loading

There is no support for 16 bpp images or BI_BITFIELDS compression (for lack of test files).

Supported JIU image data classes when saving to BMP

There is no support for compressed BMP files when saving.

I/O classes

BMPCodec works with all input and output classes supported by ImageCodec (java.io.InputStream, java.io.OutputStream, java.io.DataInput, java.io.DataOutput, java.io.RandomAccessFile).

Problems

The RLE-compressed BMP files that I could test this codec on seem to have an end-of-line code at the end of every line instead of relying on the decoder to know when it has unpacked enough bytes for a line. Whenever this codec encounters an EOL symbol and has a current column value of 0, the EOL is ignored.

Usage examples

Write an image to a BMP file.
 BMPCodec codec = new BMPCodec();
 codec.setImage(image);
 codec.setFile("out.bmp", CodecMode.SAVE);
 codec.process();
 codec.close();
 
Read an image from a BMP file.
 BMPCodec codec = new BMPCodec();
 codec.setFile("image.bmp", CodecMode.LOAD);
 codec.process();
 codec.close();
 PixelImage image = codec.getImage();
 
Author:
Marco Schmidt
Since:
0.7.0

Field Summary

private int
colorDepth
private int
compression
private int
dataOffset
private int
imageHeight
private int
imageWidth
private DataInput
in
private DataOutput
out
private Palette
palette

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[]
getFileExtensions()
String
getFormatName()
String[]
getMimeTypes()
boolean
isLoadingSupported()
boolean
isSavingSupported()
private void
load()
private void
loadCompressedPaletted4Stream()
private void
loadCompressedPaletted8Stream()
private void
loadHeader()
private void
loadStream()
private void
loadUncompressedBilevelStream()
private void
loadUncompressedPaletted4Stream()
private void
loadUncompressedPaletted8Stream()
private void
loadUncompressedRgb24Stream()
private void
loadUncompressedStream()
void
process()
private void
save()
String
suggestFileExtension(PixelImage image)
private void
writeHeader(PixelImage image, int filesize, int offset, int numBits)
private void
writeInt(int value)
private void
writePalette()
Write the palette associated with the image getImage().
private void
writeShort(int value)
private void
writeStream()

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

colorDepth

private int colorDepth

compression

private int compression

dataOffset

private int dataOffset

imageHeight

private int imageHeight

imageWidth

private int imageWidth

in

private DataInput in

out

private DataOutput out

palette

private Palette palette

Method Details

getFileExtensions

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

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 MissingParameterException,
                   OperationFailedException,
                   UnsupportedTypeException,
                   WrongFileFormatException

loadCompressedPaletted4Stream

private void loadCompressedPaletted4Stream()
            throws IOException

loadCompressedPaletted8Stream

private void loadCompressedPaletted8Stream()
            throws IOException

loadHeader

private void loadHeader()
            throws IOException,
                   MissingParameterException,
                   OperationFailedException,
                   UnsupportedTypeException,
                   WrongFileFormatException

loadStream

private void loadStream()
            throws IOException,
                   MissingParameterException,
                   OperationFailedException,
                   UnsupportedTypeException

loadUncompressedBilevelStream

private void loadUncompressedBilevelStream()
            throws IOException,
                   OperationFailedException

loadUncompressedPaletted4Stream

private void loadUncompressedPaletted4Stream()
            throws IOException

loadUncompressedPaletted8Stream

private void loadUncompressedPaletted8Stream()
            throws IOException

loadUncompressedRgb24Stream

private void loadUncompressedRgb24Stream()
            throws IOException

loadUncompressedStream

private void loadUncompressedStream()
            throws IOException,
                   OperationFailedException

process

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

save

private void save()
            throws MissingParameterException,
                   OperationFailedException,
                   UnsupportedTypeException

suggestFileExtension

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

writeHeader

private void writeHeader(PixelImage image,
                         int filesize,
                         int offset,
                         int numBits)
            throws IOException

writeInt

private void writeInt(int value)
            throws IOException

writePalette

private void writePalette()
            throws IOException
Write the palette associated with the image getImage(). Required not only for image objects that implement PalettedImage but also for BilevelImage and Grayscale8Image. For the latter two the palette values must be explicitly written into the file.

writeShort

private void writeShort(int value)
            throws IOException

writeStream

private void writeStream()
            throws IOException