Package net.sourceforge.jiu.codecs
Class PCDCodec
- java.lang.Object
-
- net.sourceforge.jiu.ops.Operation
-
- net.sourceforge.jiu.codecs.ImageCodec
-
- net.sourceforge.jiu.codecs.PCDCodec
-
- All Implemented Interfaces:
YCbCrIndex
public class PCDCodec extends ImageCodec implements YCbCrIndex
A codec to read Kodak Photo-CD (image pac) image files. Typical file extension is.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.Limitations
Only the lowest three resolutions are supported by this codec.Sample PCD files
You can download sample PCD image files from Kodak's website.- Author:
- Marco Schmidt
-
-
Field Summary
Fields Modifier and Type Field Description private byte[][]dataprivate RandomAccessFileinprivate static byte[]MAGICprivate booleanmonochromeprivate static intNO_ROTATIONprivate intnumChannelsprivate static long[]PCD_FILE_OFFSETSstatic intPCD_RESOLUTION_1Base/16, the minimum pixel resolution, 192 x 128 pixels.static intPCD_RESOLUTION_2Base/4, the second pixel resolution, 384 x 256 pixels.static intPCD_RESOLUTION_3Base, the third pixel resolution, 768 x 512 pixels.static intPCD_RESOLUTION_4Base*4, the fourth pixel resolution, 1536 x 1024 pixels.static intPCD_RESOLUTION_5Base*16, the fifth pixel resolution, 3072 x 2048 pixels.static intPCD_RESOLUTION_6Base*64, the sixth pixel resolution, 6144 x 4096 pixels.static intPCD_RESOLUTION_DEFAULTIndex for the default resolution , Base (PCD_RESOLUTION_3).static int[][]PCD_RESOLUTIONSThis two-dimensional int array holds all possible pixel resolutions for a PCD file.private booleanperformColorConversionprivate intresolutionIndexprivate static intROTATE_180private static intROTATE_90_LEFTprivate static intROTATE_90_RIGHTprivate static intSECTOR_SIZE-
Fields inherited from interface net.sourceforge.jiu.color.YCbCrIndex
INDEX_CB, INDEX_CR, INDEX_Y
-
-
Constructor Summary
Constructors Constructor 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 resolutionPCD_RESOLUTION_DEFAULT, 768 x 512 pixels (or vice versa)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[][]allocateMemory()private voidconvertToRgb(int width, int height)private IntegerImagecreateImage(int width, int height)String[]getFileExtensions()Returns all file extensions that are typical for this file format.StringgetFormatName()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, ornullif none are available.booleanisLoadingSupported()Returns if this codec is able to load images in the file format supported by this codec.booleanisSavingSupported()Returns if this codec is able to save images in the file format supported by this codec.private voidload()Attempts to load an image.private voidloadUncompressedImage(int resolution)Loads one of the three lowest resolution images from the file.voidprocess()Checks the parameter and loads an image.private voidrotateArrays(int rotationAngle, int width, int height)voidsetColorConversion(boolean performColorConversion)Specify whether color is converted from PCD's YCbCr color space to RGB color space.voidsetFile(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.voidsetMonochrome(boolean monochrome)Specifies whether the image is to be loaded as gray or color image.voidsetResolutionIndex(int resolutionIndex)-
Methods inherited from class net.sourceforge.jiu.codecs.ImageCodec
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
-
Methods inherited from class net.sourceforge.jiu.ops.Operation
addProgressListener, addProgressListeners, getAbort, removeProgressListener, setAbort, setProgress, setProgress
-
-
-
-
Field Detail
-
PCD_RESOLUTION_1
public static final int PCD_RESOLUTION_1
Base/16, the minimum pixel resolution, 192 x 128 pixels.- See Also:
- Constant Field Values
-
PCD_RESOLUTION_2
public static final int PCD_RESOLUTION_2
Base/4, the second pixel resolution, 384 x 256 pixels.- See Also:
- Constant Field Values
-
PCD_RESOLUTION_3
public static final int PCD_RESOLUTION_3
Base, the third pixel resolution, 768 x 512 pixels.- See Also:
- Constant Field Values
-
PCD_RESOLUTION_4
public static final int PCD_RESOLUTION_4
Base*4, the fourth pixel resolution, 1536 x 1024 pixels. Unsupported- See Also:
- Constant Field Values
-
PCD_RESOLUTION_5
public static final int PCD_RESOLUTION_5
Base*16, the fifth pixel resolution, 3072 x 2048 pixels. Unsupported- See Also:
- Constant Field Values
-
PCD_RESOLUTION_6
public static final int PCD_RESOLUTION_6
Base*64, the sixth pixel resolution, 6144 x 4096 pixels. Unsupported- See Also:
- Constant Field Values
-
PCD_RESOLUTION_DEFAULT
public static final int PCD_RESOLUTION_DEFAULT
Index for the default resolution , Base (PCD_RESOLUTION_3).- See Also:
- Constant Field Values
-
PCD_RESOLUTIONS
public static final int[][] PCD_RESOLUTIONS
This two-dimensional int array holds all possible pixel resolutions for a PCD file. Use one of the PCD resolution constants (e.g.PCD_RESOLUTION_3as 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.
-
PCD_FILE_OFFSETS
private static final long[] PCD_FILE_OFFSETS
-
NO_ROTATION
private static final int NO_ROTATION
- See Also:
- Constant Field Values
-
ROTATE_90_LEFT
private static final int ROTATE_90_LEFT
- See Also:
- Constant Field Values
-
ROTATE_180
private static final int ROTATE_180
- See Also:
- Constant Field Values
-
ROTATE_90_RIGHT
private static final int ROTATE_90_RIGHT
- See Also:
- Constant Field Values
-
SECTOR_SIZE
private static final int SECTOR_SIZE
- See Also:
- Constant Field Values
-
MAGIC
private static final byte[] MAGIC
-
performColorConversion
private boolean performColorConversion
-
monochrome
private boolean monochrome
-
numChannels
private int numChannels
-
resolutionIndex
private int resolutionIndex
-
in
private RandomAccessFile in
-
data
private byte[][] data
-
-
Constructor Detail
-
PCDCodec
public 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)
-
-
Method Detail
-
allocateMemory
private byte[][] allocateMemory()
-
convertToRgb
private void convertToRgb(int width, int height)
-
createImage
private IntegerImage createImage(int width, int height)
-
getFileExtensions
public String[] getFileExtensions()
Description copied from class:ImageCodecReturns all file extensions that are typical for this file format. The default implementation in ImageCodec returnsnull. 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.- Overrides:
getFileExtensionsin classImageCodec- Returns:
- String array with typical file extensions
-
getFormatName
public String 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
public String[] 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
private void load() throws InvalidFileStructureException, IOException, UnsupportedTypeException, WrongFileFormatExceptionAttempts to load an image. The codec must have been given an input stream, all other parameters (do not convert color to RGB, load monochrome channel only, load other resolution than default) can optionally be chosen by calling the corresponding methods.- Throws:
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
-
loadUncompressedImage
private void loadUncompressedImage(int resolution) throws IllegalArgumentException, IOExceptionLoads one of the three lowest resolution images from the file. First skips as many bytes as there are between the current stream offset and the offset of the image in the PCD file (first three images are at fixed positions). Then reads the pixels from in to data.Note that there are
widthtimesheightsamples 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).- Parameters:
resolution- one of PCD_RESOLUTION_1, PCD_RESOLUTION_2 or PCD_RESOLUTION_3- Throws:
an- IOException if there were any reading errorsIllegalArgumentExceptionIOException
-
process
public void process() throws InvalidFileStructureException, MissingParameterException, OperationFailedException, UnsupportedTypeException, WrongFileFormatExceptionChecks the parameter and loads an image.- Overrides:
processin classOperation- Throws:
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.)OperationFailedExceptionInvalidFileStructureExceptionUnsupportedTypeExceptionWrongFileFormatException
-
rotateArrays
private void rotateArrays(int rotationAngle, int width, int height)
-
setColorConversion
public void setColorConversion(boolean performColorConversion)
Specify whether color is converted from PCD's YCbCr color space to RGB color space. The default istrue, and you should only change this if you really know what you are doing. If you simply want the luminance (gray) channel, usesetMonochrome(boolean)withtrueas parameter.- Parameters:
performColorConversion- boolean that determines whether color conversion is applied
-
setFile
public void setFile(String fileName, CodecMode codecMode) throws IOException, UnsupportedCodecModeException
Description copied from class:ImageCodecGives a file name and codec mode to the codec which will then try to create the corresponding I/O object. The default implementation in ImageCodec creates a DataInputStream object wrapped around a BufferedInputStream wrapped around a FileInputStream for CodecMode.LOAD. Similar for CodecMode.SAVE: a DataOutputStream around a BufferedOutputStream object around a FileOutputStream object. Codecs that need different I/O objects must override this method (some codecs may need random access and thus require a RandomAccessFile object).- Overrides:
setFilein classImageCodec- Parameters:
fileName- name of the file to be used for loading or savingcodecMode- defines whether file is to be used for loading or saving- Throws:
IOExceptionUnsupportedCodecModeException
-
setMonochrome
public void setMonochrome(boolean monochrome)
Specifies whether the image is to be loaded as gray or color image. If argument is true, only the gray channel is loaded.
-
setResolutionIndex
public void setResolutionIndex(int resolutionIndex)
-
-