Class PBMDecoder
java.lang.Object
org.monte.media.pbm.PBMDecoder
- All Implemented Interfaces:
IFFVisitor
Creates Image objects by reading an IFF PBM stream.
PBM regular expression
PBM ::= "FORM" #{ "PBM" BMHD [CMAP] [GRAB] [DEST] [SPRT] [CAMG] CRNG* CCRT* [BODY] }
BMHD ::= "BMHD" #{ BitMapHeader }
CMAP ::= "CMAP" #{ (red green blue)* } [0]
GRAB ::= "GRAB" #{ Point2D }
DEST ::= "DEST" #{ DestMerge }
SPRT ::= "SPRT" #{ SpritePrecedence }
CAMG ::= "CAMG" #{ LONG }
CRNG ::= "CRNG" #{ CRange }
CCRT ::= "CCRT" #{ CycleInfo }
BODY ::= "BODY" #{ UBYTE* } [0]
The token "#" represents a
ckSize LONG count of the following braced data bytes. E.g., a
BMHD's "#" should equal
sizeof(BitMapHeader). Literal strings are shown in "quotes",
[square bracket items] are optional, and "*" means 0 or more repetitions. A
sometimes-needed pad byte is shown as "[0]".- Author:
- Werner Randelshofer, Hausmatt 10, CH-6405 Goldau, Switzerland
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intprotected intprotected intRaster width_ and heigth in pixelsprotected intprotected intNumber of source bitplanes.protected intSource "page" size in pixels.protected intSource "page" size in pixels.protected intTransparent "color number" (sort of).protected intRaster width_ and heigth in pixelsprotected intPixel aspect, a ratio width : heightprotected intpixel position for this imageprotected intPixel aspect, a ratio width : heightprotected intpixel position for this imageprotected static final intprotected static final intprotected ColorModelCMAP data.protected static final intPBM BMHD chunk: compression algorithm.protected static final intPBM BMHD chunk: compression algorithm.protected static final intprotected static final intprotected InputStreamInput stream to decode from.protected URLURL to get the input stream from.protected ColorCyclingMemoryImageSourceBODY dataprotected static final intPBM BMHD chunk: masking technique.protected static final intPBM BMHD chunk: masking technique.protected static final intPBM BMHD chunk: masking technique.protected static final intPBM BMHD chunk: masking technique.protected static final intChunk ID's.protected ArrayList<ColorCyclingMemoryImageSource> Stores all the PBM pictures found during decoding as an instance of MemoryImageSource. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddecodeBMHD(IFFChunk chunk) Decodes the bitmap header (PBM BMHD).protected voiddecodeBODY(IFFChunk chunk) protected voiddecodeCMAP(IFFChunk chunk) protected ColorCycledecodeCRNG(IFFChunk chunk) Decodes the color range cycling (ILBM CRNG).protected ColorCycledecodeDRNG(IFFChunk chunk) Decodes the DPaint IV enhanced color cycle chunk (ILBM DRNG)voidenterGroup(IFFChunk chunk) voidleaveGroup(IFFChunk chunk) produce()Processes the input stream and creates a vector of MemoryImageSource instances.voidregisterChunks(IFFParser iff) static intunpackByteRun1(byte[] in, byte[] out) ByteRun1 run decoder.voidvisitChunk(IFFChunk group, IFFChunk chunk)
-
Field Details
-
PBM_ID
protected static final int PBM_IDChunk ID's. -
BMHD_ID
protected static final int BMHD_ID -
CMAP_ID
protected static final int CMAP_ID -
CRNG_ID
protected static final int CRNG_ID -
DRNG_ID
protected static final int DRNG_ID -
BODY_ID
protected static final int BODY_ID -
MSK_NONE
protected static final int MSK_NONEPBM BMHD chunk: masking technique.- See Also:
-
MSK_HAS_MASK
protected static final int MSK_HAS_MASKPBM BMHD chunk: masking technique.- See Also:
-
MSK_HAS_TRANSPARENT_COLOR
protected static final int MSK_HAS_TRANSPARENT_COLORPBM BMHD chunk: masking technique.- See Also:
-
MSK_LASSO
protected static final int MSK_LASSOPBM BMHD chunk: masking technique.- See Also:
-
CMP_NONE
protected static final int CMP_NONEPBM BMHD chunk: compression algorithm.- See Also:
-
CMP_BYTE_RUN_1
protected static final int CMP_BYTE_RUN_1PBM BMHD chunk: compression algorithm.- See Also:
-
inputStream
Input stream to decode from. -
location
URL to get the input stream from. -
sources
Stores all the PBM pictures found during decoding as an instance of MemoryImageSource. -
bmhdWidth
protected int bmhdWidthRaster width_ and heigth in pixels -
bmhdHeight
protected int bmhdHeightRaster width_ and heigth in pixels -
bmhdXPosition
protected int bmhdXPositionpixel position for this image -
bmhdYPosition
protected int bmhdYPositionpixel position for this image -
bmhdNbPlanes
protected int bmhdNbPlanesNumber of source bitplanes. -
bmhdMasking
protected int bmhdMasking -
bmhdCompression
protected int bmhdCompression -
bmhdTransparentColor
protected int bmhdTransparentColorTransparent "color number" (sort of). -
bmhdXAspect
protected int bmhdXAspectPixel aspect, a ratio width : height -
bmhdYAspect
protected int bmhdYAspectPixel aspect, a ratio width : height -
bmhdPageWidth
protected int bmhdPageWidthSource "page" size in pixels. -
bmhdPageHeight
protected int bmhdPageHeightSource "page" size in pixels. -
cmapColorModel
CMAP data. -
memoryImageSource
BODY data
-
-
Constructor Details
-
PBMDecoder
Constructors -
PBMDecoder
-
-
Method Details
-
produce
Processes the input stream and creates a vector of MemoryImageSource instances.- Returns:
- A vector of java.awt.img.MemoryImageSource.
- Throws:
IOException
-
registerChunks
-
enterGroup
- Specified by:
enterGroupin interfaceIFFVisitor
-
leaveGroup
- Specified by:
leaveGroupin interfaceIFFVisitor
-
visitChunk
- Specified by:
visitChunkin interfaceIFFVisitor- Throws:
ParseExceptionAbortException
-
decodeBMHD
Decodes the bitmap header (PBM BMHD).typedef UBYTE Masking; // Choice of masking technique #define mskNone 0 #define mskHasMask 1 #define mskHasTransparentColor 2 #define mskLasso 3 typedef UBYTE Compression; // Choice of compression algorithm // applied to the rows of all source and mask planes. // "cmpByteRun1" is the byte run encoding. Do not compress // accross rows! #define cmpNone 0 #define cmpByteRun1 1 typedef struct { UWORD w, h; // raster width and height in pixels WORD x, y; // pixel position for this image UBYTE nbPlanes; // # source bitplanes Masking masking; Compression compression; UBYTE pad1; // unused; ignore on read, write as 0 UWORD transparentColor; // transparent "color number" (sort of) UBYTE xAspect, yAspect; // pixel aspect, a ratio width : height WORD pageWidth, pageHeight; // source "page" size in pixels } BitmapHeader;- Throws:
ParseException
-
decodeCMAP
- Throws:
ParseException
-
decodeCRNG
Decodes the color range cycling (ILBM CRNG).#define RNG_NORATE 36 // Dpaint uses this rate to mean non-active set { active = 1, reverse = 2 } crngActive; // A CRange is store in a CRNG chunk. typedef struct { WORD pad1; // reserved for future use; store 0 here * WORD rate; // 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 WORD set crngActive flags; // bit0 set = active, bit 1 set = reverse UBYTE low; UBYTE high; // lower and upper color registers selected } ilbmColorRegisterRangeChunk;- Throws:
ParseException
-
decodeDRNG
Decodes the DPaint IV enhanced color cycle chunk (ILBM DRNG)The RNG_ACTIVE flag is set when the range is cyclable. A range should only have the RNG _ACTIVE if it:
- contains at least one color register
- has a defined rate
- has more than one color and/or color register
ILBM DRNG DPaint IV enhanced color cycle chunk -------------------------------------------- set { RNG_ACTIVE=1,RNG_DP_RESERVED=4 } drngFlags; /* True color cell * / typedef struct { UBYTE cell; UBYTE r; UBYTE g; UBYTE b; } ilbmDRNGDColor; /* Color register cell * / typedef struct { UBYTE cell; UBYTE index; } ilbmDRNGDIndex; /* DRNG chunk. * / typedef struct { UBYTE min; /* min cell value * / UBYTE max; /* max cell value * / UWORD rate; /* color cycling rate, 16384 = 60 steps/second * / UWORD set drngFlags flags; /* 1=RNG_ACTIVE, 4=RNG_DP_RESERVED * / UBYTE ntrue; /* number of DColorCell structs to follow * / UBYTE ntregs; /* number of DIndexCell structs to follow * / ilbmDRNGDColor[ntrue] trueColorCells; ilbmDRNGDIndex[ntregs] colorRegisterCells; } ilbmDRangeChunk;- Throws:
ParseException
-
decodeBODY
- Throws:
ParseException
-
unpackByteRun1
ByteRun1 run decoder.The run encoding scheme by byteRun1 is best described by pseudo code for the decoder Unpacker (called UnPackBits in the Macintosh toolbox.
UnPacker: LOOP until produced the desired number of bytes Read the next source byte into n SELECT n FROM [0..127] => copy the next n+1 bytes literally [-1..-127] => replicate the next byte -n+1 times -128 => no operation ENDCASE; ENDLOOP;- Parameters:
in-out-- Throws:
ParseException
-