public class PalmCodec extends ImageCodec
BilevelImage
: will be saved as a 1 bit per pixel, monochrome file.Gray8Image
: will be saved as an 8 bits per pixel file with a custom
palette which will contain the 256 shades of gray from black - (0, 0, 0) - to
white - (255, 255, 255).Paletted8Image
: it is first checked if the image is using the
Palm system 8 bits per pixel palette. If so, an 8 bits per pixel file
with no custom palette is written, otherwise an 8 bits per pixel file
with a custom palette (of the original length) is written.
RGB24Image
: will be saved as a 16 bits per pixel, direct color file.
Some information will get lost when converting from 24 to 16 bits per pixel.
Instead of 256 shades for each red, green and blue (and thus, 2563 = 16,777,216
possible colors) the resulting file will only
use 32 shades of red and blue and 64 shades of green (65,536 possible colors).setFile(java.lang.String, net.sourceforge.jiu.codecs.CodecMode)
which does that automatically.
.palm
as file extension for this file format.
This is by no means official, but I find it helpful.
PalmCodec codec = new PalmCodec(); codec.setFile("test.palm", CodecMode.LOAD); codec.process(); PixelImage image = codec.getImage(); codec.close();Save an image to a Palm file using RLE compression:
PalmCodec codec = new PalmCodec(); codec.setImage(image); codec.setCompression(PalmCodec.COMPRESSION_RLE); codec.setFile("out.palm", CodecMode.SAVE); codec.process(); codec.close();
pnmtopalm
and
palmtopnm
that are part of the
Netpbm package,Modifier and Type | Field | Description |
---|---|---|
private int |
bitsPerPixel |
|
private int |
blueBits |
|
private int |
bytesPerRow |
|
private long |
compressedDataOffset |
|
private int |
compression |
|
static int |
COMPRESSION_NONE |
Constant for compression type Uncompressed.
|
static int |
COMPRESSION_PACKBITS |
Constant for compression type Packbits.
|
static int |
COMPRESSION_RLE |
Constant for compression type RLE (run length encoding).
|
static int |
COMPRESSION_SCANLINE |
Constant for compression type Scanline.
|
private static int |
FLAG_COLOR_TABLE |
|
private static int |
FLAG_COMPRESSED |
|
private static int |
FLAG_DIRECT_COLOR |
|
private static int |
FLAG_TRANSPARENCY |
|
private int |
flags |
|
private int |
greenBits |
|
private int |
height |
|
private Palette |
palette |
|
private static short[][] |
PALM_SYSTEM_PALETTE_16_COLOR |
|
private static short[][] |
PALM_SYSTEM_PALETTE_16_GRAY |
|
private static short[][] |
PALM_SYSTEM_PALETTE_256 |
|
private static short[][] |
PALM_SYSTEM_PALETTE_4_GRAY |
|
private int |
redBits |
|
private byte[] |
rgb |
|
private byte[] |
transColor |
|
private int |
transparencyIndex |
|
private int |
version |
|
private int |
width |
Constructor | Description |
---|---|
PalmCodec() |
Modifier and Type | Method | Description |
---|---|---|
private static Palette |
createPalette(short[][] data) |
|
static Palette |
createSystem2BitGrayscalePalette() |
Creates the 2 bits per pixel Palm system palette with grayscale values.
|
static Palette |
createSystem4BitColorPalette() |
Creates the 4 bits per pixel Palm system palette with color values.
|
static Palette |
createSystem4BitGrayscalePalette() |
Creates the 4 bits per pixel Palm system palette with grayscale values.
|
static Palette |
createSystem8BitPalette() |
Creates the 8 bits per pixel Palm system palette.
|
int |
getCompression() |
Returns the Palm compression method.
|
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. |
int |
getTransparencyIndex() |
Returns the transpareny index if one is available (
hasTransparencyIndex()
returns true ) or an undefined value otherwise. |
boolean |
hasTransparencyIndex() |
Returns whether a transpareny index is available and can be
retrieved via
getTransparencyIndex() . |
private void |
invertBilevelData(byte[] row) |
|
private static boolean |
isEqualPalette(Palette palette,
short[][] data) |
|
boolean |
isLoadingSupported() |
Returns if this codec is able to load images in the file format supported by this codec.
|
static boolean |
isPalmSystemPalette256(Palette palette) |
Returns if the argument palette is the Palm system palette
with 256 colors.
|
static boolean |
isPalmSystemPaletteColor16(Palette palette) |
Returns if the argument palette is the Palm system color palette
with 16 entries.
|
static boolean |
isPalmSystemPaletteGray16(Palette palette) |
Returns if the argument palette is the Palm system grayscale palette
with 16 entries.
|
static boolean |
isPalmSystemPaletteGray4(Palette palette) |
Returns if the argument palette is the Palm system grayscale palette
with 4 entries.
|
boolean |
isSavingSupported() |
Returns if this codec is able to save images in the file format supported by this codec.
|
private void |
load() |
|
private void |
loadHeader(DataInput in) |
|
private void |
loadImage(DataInput in) |
|
private void |
loadImageData(DataInput in) |
|
private void |
loadPalette(DataInput in) |
|
void |
process() |
This method does the actual work of the operation.
|
void |
removeTransparencyIndex() |
Removes the transparency index if one has been set.
|
private void |
save() |
|
private void |
save(DataOutput out,
BilevelImage image) |
|
private void |
save(DataOutput out,
Gray8Image image) |
|
private void |
save(DataOutput out,
Paletted8Image image) |
|
private void |
save(DataOutput out,
RGB24Image image) |
|
private void |
saveFinalCompressedSize(DataOutput out) |
|
private void |
saveHeader(DataOutput out) |
|
private void |
saveInitialCompressedSize(DataOutput out) |
|
private void |
savePalette(DataOutput out,
Palette palette) |
|
private void |
saveRow(DataOutput out,
boolean firstRow,
byte[] row,
byte[] prev) |
|
private void |
saveRowRLE(DataOutput out,
byte[] row) |
|
private void |
saveRowScanLine(DataOutput out,
boolean firstRow,
byte[] row,
byte[] prev) |
|
void |
setCompression(int newCompressionType) |
Sets the compression algorithm to be used for saving an image.
|
private void |
setCorrectVersion() |
|
void |
setFile(String fileName,
CodecMode codecMode) |
Reuses super.setFile when used for CodecMode.LOAD, but
creates a RandomAccessFile instead of a FileOutputStream
in write mode so that the compressed size can be written
correcly (requires a seek operation).
|
void |
setTransparencyIndex(int newIndex) |
Sets a new transparency index when saving an image.
|
private void |
store(PixelImage image,
int y,
byte[] row) |
|
String |
suggestFileExtension(PixelImage image) |
Attempts to suggest a filename extension.
|
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, setImage, setImageIndex, setInputStream, setOutputStream, setRandomAccessFile
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
public static final int COMPRESSION_NONE
public static final int COMPRESSION_PACKBITS
public static final int COMPRESSION_RLE
public static final int COMPRESSION_SCANLINE
private static final int FLAG_COMPRESSED
private static final int FLAG_COLOR_TABLE
private static final int FLAG_TRANSPARENCY
private static final int FLAG_DIRECT_COLOR
private static final short[][] PALM_SYSTEM_PALETTE_4_GRAY
private static final short[][] PALM_SYSTEM_PALETTE_16_COLOR
private static final short[][] PALM_SYSTEM_PALETTE_16_GRAY
private static final short[][] PALM_SYSTEM_PALETTE_256
private int bitsPerPixel
private int blueBits
private int bytesPerRow
private int compression
private long compressedDataOffset
private int flags
private int greenBits
private int height
private Palette palette
private int redBits
private byte[] rgb
private byte[] transColor
private int transparencyIndex
private int version
private int width
private static Palette createPalette(short[][] data)
public static Palette createSystem2BitGrayscalePalette()
public static Palette createSystem4BitColorPalette()
public static Palette createSystem4BitGrayscalePalette()
public static Palette createSystem8BitPalette()
public int getCompression()
setCompression(int)
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 int getTransparencyIndex()
hasTransparencyIndex()
returns true
) or an undefined value otherwise.public boolean hasTransparencyIndex()
getTransparencyIndex()
.getTransparencyIndex()
,
removeTransparencyIndex()
,
setTransparencyIndex(int)
private void invertBilevelData(byte[] row)
private static boolean isEqualPalette(Palette palette, short[][] data)
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 static boolean isPalmSystemPaletteGray4(Palette palette)
palette
- to be checkedcreateSystem2BitGrayscalePalette()
public static boolean isPalmSystemPaletteGray16(Palette palette)
palette
- to be checkedcreateSystem4BitGrayscalePalette()
public static boolean isPalmSystemPaletteColor16(Palette palette)
palette
- to be checkedcreateSystem4BitColorPalette()
public static boolean isPalmSystemPalette256(Palette palette)
palette
- to be checkedcreateSystem8BitPalette()
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 InvalidFileStructureException, IOException, OperationFailedException, UnsupportedTypeException, WrongFileFormatException
private void loadHeader(DataInput in) throws InvalidFileStructureException, IOException, UnsupportedTypeException, WrongFileFormatException
private void loadImage(DataInput in) throws InvalidFileStructureException, IOException, UnsupportedTypeException, WrongFileFormatException, WrongParameterException
private void loadImageData(DataInput in) throws InvalidFileStructureException, IOException
private void loadPalette(DataInput in) throws InvalidFileStructureException, IOException, UnsupportedTypeException, WrongFileFormatException
public void process() throws InvalidFileStructureException, MissingParameterException, OperationFailedException, WrongParameterException
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
InvalidFileStructureException
public void removeTransparencyIndex()
private void save() throws IOException, OperationFailedException, UnsupportedTypeException
private void save(DataOutput out, BilevelImage image) throws IOException
IOException
private void save(DataOutput out, Gray8Image image) throws IOException
IOException
private void save(DataOutput out, Paletted8Image image) throws IOException
IOException
private void save(DataOutput out, RGB24Image image) throws IOException
IOException
private void saveFinalCompressedSize(DataOutput out) throws IOException
IOException
private void saveHeader(DataOutput out) throws IOException
IOException
private void saveInitialCompressedSize(DataOutput out) throws IOException
IOException
private void savePalette(DataOutput out, Palette palette) throws IOException
IOException
private void saveRow(DataOutput out, boolean firstRow, byte[] row, byte[] prev) throws IOException
IOException
private void saveRowRLE(DataOutput out, byte[] row) throws IOException
IOException
private void saveRowScanLine(DataOutput out, boolean firstRow, byte[] row, byte[] prev) throws IOException
IOException
public void setCompression(int newCompressionType)
newCompressionType
- int value that is one of the COMPRESSION_xyz constants of this classIllegalArgumentException
- if the compression type is unsupportedgetCompression()
private void setCorrectVersion()
public void setFile(String fileName, CodecMode codecMode) throws IOException, UnsupportedCodecModeException
setFile
in class ImageCodec
fileName
- name of the file to be openedcodecMode
- defines whether this codec object is to be used for loading or savingIOException
UnsupportedCodecModeException
public void setTransparencyIndex(int newIndex)
newIndex
- the new transparency index, must be smaller than the number of entries in the palettegetTransparencyIndex()
,
hasTransparencyIndex()
,
removeTransparencyIndex()
private void store(PixelImage image, int y, byte[] row)
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 recommended