public class BMPCodec extends ImageCodec
Typical file extensions are .bmp
and .rle
(the latter is only used for compressed files).
This codec supports the bounds concept for loading and saving.
BilevelImage
can be given to the codec and it will load the image to that object
(if the image's resolution is sufficient).
If no image object is given to the codec, a new
MemoryBilevelImage
will be created.Paletted8Image
object.
This requires 50 % more space than is necessary, but there is
no dedicated 4 bit image data class in JIU.Paletted8Image
object.RGB24Image
object.
BilevelImage
objects are stored as 1 bit per pixel BMP files.Gray8Image
and
Paletted8Image
objects are stored as
paletted 8 bits per pixel files.
It doesn't really matter how many entries the palette has, the BMP file's
palette will always have 256 entries, filled up with zero entries if necessary.RGB24Image
objects are stored as 24 bpp BMP files.
InputStream
, OutputStream
,
DataInput
, DataOutput
,
RandomAccessFile
).
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.
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();
Modifier and Type | Field | Description |
---|---|---|
private int |
colorDepth |
|
private int |
compression |
|
private int |
dataOffset |
|
private int |
imageHeight |
|
private int |
imageWidth |
|
private DataInput |
in |
|
private DataOutput |
out |
|
private Palette |
palette |
Constructor | Description |
---|---|
BMPCodec() |
Modifier and Type | Method | Description |
---|---|---|
String[] |
getFileExtensions() |
Returns all file extensions that are typical for this file format.
|
String |
getFormatName() |
Returns the name of the file format supported by this codec.
|
String[] |
getMimeTypes() |
Return the MIME
(Multipurpose Internet Mail Extensions) type strings for this format, or
null
if none are available. |
boolean |
isLoadingSupported() |
Returns if this codec is able to load images in the file format supported by this codec.
|
boolean |
isSavingSupported() |
Returns if this codec is able to save images in the file format supported by this codec.
|
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() |
This method does the actual work of the operation.
|
private void |
save() |
|
String |
suggestFileExtension(PixelImage image) |
Attempts to suggest a filename extension.
|
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() |
appendComment, checkBounds, checkImageResolution, close, getBoundsHeight, getBoundsWidth, getBoundsX1, getBoundsX2, getBoundsY1, getBoundsY2, getComment, getDataInput, getDataOutput, getDpiX, getDpiY, 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, setRandomAccessFile
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
private int colorDepth
private int compression
private int dataOffset
private int imageHeight
private int imageWidth
private DataInput in
private DataOutput out
private Palette palette
public String[] getFileExtensions()
ImageCodec
null
.
The file extension strings should include a leading dot
and are supposed to be lower case (if that is allowed for
the given file format).
Example: {".jpg", ".jpeg"}
for the JPEG file format.getFileExtensions
in class ImageCodec
public String getFormatName()
ImageCodec
ImageCodec
must 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 BMP
or Portable Anymap (PNM)
.getFormatName
in class ImageCodec
public String[] getMimeTypes()
ImageCodec
null
if none are available.getMimeTypes
in class ImageCodec
public boolean isLoadingSupported()
ImageCodec
true
is returned this does not necessarily mean that all files in this
format can be read, but at least some.isLoadingSupported
in class ImageCodec
public boolean isSavingSupported()
ImageCodec
true
is returned this does not necessarily mean that all types files in this
format can be written, but at least some.isSavingSupported
in class ImageCodec
private void load() throws MissingParameterException, OperationFailedException, UnsupportedTypeException, WrongFileFormatException
private void loadCompressedPaletted4Stream() throws IOException
IOException
private void loadCompressedPaletted8Stream() throws IOException
IOException
private void loadHeader() throws IOException, MissingParameterException, OperationFailedException, UnsupportedTypeException, WrongFileFormatException
private void loadStream() throws IOException, MissingParameterException, OperationFailedException, UnsupportedTypeException
private void loadUncompressedBilevelStream() throws IOException, OperationFailedException
IOException
OperationFailedException
private void loadUncompressedPaletted4Stream() throws IOException
IOException
private void loadUncompressedPaletted8Stream() throws IOException
IOException
private void loadUncompressedRgb24Stream() throws IOException
IOException
private void loadUncompressedStream() throws IOException, OperationFailedException
IOException
OperationFailedException
public void process() throws MissingParameterException, OperationFailedException
Operation
process
in class Operation
MissingParameterException
- if any mandatory parameter was not given to the operationWrongParameterException
- if at least one of the input parameters was
not initialized appropriately (values out of the valid interval, etc.)OperationFailedException
private void save() throws MissingParameterException, OperationFailedException, UnsupportedTypeException
public String suggestFileExtension(PixelImage image)
ImageCodec
PNMCodec
).
This default implementation always returns null
.suggestFileExtension
in class ImageCodec
image
- the image that is to be written to a filenull
if no file extension can be recommendedprivate void writeHeader(PixelImage image, int filesize, int offset, int numBits) throws IOException
IOException
private void writeInt(int value) throws IOException
IOException
private void writePalette() throws IOException
IOException
private void writeShort(int value) throws IOException
IOException
private void writeStream() throws IOException
IOException