public class PCDCodec extends ImageCodec implements YCbCrIndex
.pcd
.
PCD is designed to store the same image in several resolutions.
Not all resolutions are always present in a file.
Typically, the first five resolutions are available and the file size
is between four and six megabytes.
Lossless compression (Huffman encoding) is used to store the higher resolution images.
All images are in 24 bit YCbCr colorspace, with a component subsampling of 4:1:1 (Y:Cb:Cr)
in both horizontal and vertical direction.
Modifier and Type | Field and Description |
---|---|
private byte[][] |
data |
private java.io.RandomAccessFile |
in |
private static byte[] |
MAGIC |
private boolean |
monochrome |
private static int |
NO_ROTATION |
private int |
numChannels |
private static long[] |
PCD_FILE_OFFSETS |
static int |
PCD_RESOLUTION_1
Base/16, the minimum pixel resolution, 192 x 128 pixels.
|
static int |
PCD_RESOLUTION_2
Base/4, the second pixel resolution, 384 x 256 pixels.
|
static int |
PCD_RESOLUTION_3
Base, the third pixel resolution, 768 x 512 pixels.
|
static int |
PCD_RESOLUTION_4
Base*4, the fourth pixel resolution, 1536 x 1024 pixels.
|
static int |
PCD_RESOLUTION_5
Base*16, the fifth pixel resolution, 3072 x 2048 pixels.
|
static int |
PCD_RESOLUTION_6
Base*64, the sixth pixel resolution, 6144 x 4096 pixels.
|
static int |
PCD_RESOLUTION_DEFAULT
Index for the default resolution , Base (
PCD_RESOLUTION_3 ). |
static int[][] |
PCD_RESOLUTIONS
This two-dimensional int array holds all possible pixel resolutions for
a PCD file.
|
private boolean |
performColorConversion |
private int |
resolutionIndex |
private static int |
ROTATE_180 |
private static int |
ROTATE_90_LEFT |
private static int |
ROTATE_90_RIGHT |
private static int |
SECTOR_SIZE |
INDEX_CB, INDEX_CR, INDEX_Y
Constructor and Description |
---|
PCDCodec()
This constructor chooses the default settings for PCD image loading:
load color image (all channels, not only luminance)
perform color conversion from PCD's native YCbCr color space to RGB
load the image in the default resolution
PCD_RESOLUTION_DEFAULT , 768 x 512 pixels (or vice versa)
|
Modifier and Type | Method and Description |
---|---|
private byte[][] |
allocateMemory() |
private void |
convertToRgb(int width,
int height) |
private IntegerImage |
createImage(int width,
int height) |
java.lang.String[] |
getFileExtensions()
Returns all file extensions that are typical for this file format.
|
java.lang.String |
getFormatName()
Returns the name of the file format supported by this codec.
|
java.lang.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()
Attempts to load an image.
|
private void |
loadUncompressedImage(int resolution)
Loads one of the three lowest resolution images from the file.
|
void |
process()
Checks the parameter and loads an image.
|
private void |
rotateArrays(int rotationAngle,
int width,
int height) |
void |
setColorConversion(boolean performColorConversion)
Specify whether color is converted from PCD's YCbCr color space to
RGB color space.
|
void |
setFile(java.lang.String fileName,
CodecMode codecMode)
Gives a file name and codec mode to the codec which will then
try to create the corresponding I/O object.
|
void |
setMonochrome(boolean monochrome)
Specifies whether the image is to be loaded as gray or color image.
|
void |
setResolutionIndex(int resolutionIndex) |
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, setImage, setImageIndex, setInputStream, setOutputStream, setRandomAccessFile, suggestFileExtension
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
public static final int PCD_RESOLUTION_1
public static final int PCD_RESOLUTION_2
public static final int PCD_RESOLUTION_3
public static final int PCD_RESOLUTION_4
public static final int PCD_RESOLUTION_5
public static final int PCD_RESOLUTION_6
public static final int PCD_RESOLUTION_DEFAULT
PCD_RESOLUTION_3
).public static final int[][] PCD_RESOLUTIONS
PCD_RESOLUTION_3
as first index.
The second index must be 0 or 1 and leads to either width or
height.
Example: PCD_RESOLUTION[PCD_RESOLUTION_3][1]
will evalute
as 512, which can be width or height, depending on the image being
in landscape or portrait mode.
You may want to use these resolution values in your program
to prompt the user which resolution to load from the file.private static final long[] PCD_FILE_OFFSETS
private static final int NO_ROTATION
private static final int ROTATE_90_LEFT
private static final int ROTATE_180
private static final int ROTATE_90_RIGHT
private static final int SECTOR_SIZE
private static final byte[] MAGIC
private boolean performColorConversion
private boolean monochrome
private int numChannels
private int resolutionIndex
private java.io.RandomAccessFile in
private byte[][] data
public PCDCodec()
PCD_RESOLUTION_DEFAULT
, 768 x 512 pixels (or vice versa)private byte[][] allocateMemory()
private void convertToRgb(int width, int height)
private IntegerImage createImage(int width, int height)
public java.lang.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 java.lang.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 java.lang.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 InvalidFileStructureException, java.io.IOException, UnsupportedTypeException, WrongFileFormatException
java.io.IOException
- if there were reading errorsOutOfMemoryException
- if there was not enough free memory
availableInvalidFileStructureException
- if the file seems to be a PCD
stream but has logical errors in itWrongFileFormatException
- if this is not a PCD fileUnsupportedTypeException
private void loadUncompressedImage(int resolution) throws java.lang.IllegalArgumentException, java.io.IOException
Note that there are width
times height
samples for Y, but only one fourth that many samples for each Cb and Cr
(because of the 4:1:1 subsampling of the two chroma components).
resolution
- one of PCD_RESOLUTION_1, PCD_RESOLUTION_2 or PCD_RESOLUTION_3an
- IOException if there were any reading errorsjava.lang.IllegalArgumentException
java.io.IOException
public void process() throws InvalidFileStructureException, MissingParameterException, OperationFailedException, UnsupportedTypeException, WrongFileFormatException
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
UnsupportedTypeException
WrongFileFormatException
private void rotateArrays(int rotationAngle, int width, int height)
public void setColorConversion(boolean performColorConversion)
true
, and you should only change this
if you really know what you are doing.
If you simply want the luminance (gray) channel, use
setMonochrome(boolean)
with true
as parameter.performColorConversion
- boolean that determines whether color conversion is appliedpublic void setFile(java.lang.String fileName, CodecMode codecMode) throws java.io.IOException, UnsupportedCodecModeException
ImageCodec
setFile
in class ImageCodec
fileName
- name of the file to be used for loading or savingcodecMode
- defines whether file is to be used for loading or savingjava.io.IOException
UnsupportedCodecModeException
public void setMonochrome(boolean monochrome)
public void setResolutionIndex(int resolutionIndex)