ar.com.hjg.pngj.chunks
Class PngChunk

java.lang.Object
  extended by ar.com.hjg.pngj.chunks.PngChunk
Direct Known Subclasses:
PngChunkMultiple, PngChunkSingle

public abstract class PngChunk
extends Object

Represents a instance of a PNG chunk

See http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks .html

Concrete classes should extend PngChunkSingle or PngChunkMultiple

Note that some methods/fields are type-specific (getOrderingConstraint(), allowsMultiple()),
some are 'almost' type-specific (id,crit,pub,safe; the exception is PngUKNOWN),
and the rest are instance-specific


Nested Class Summary
static class PngChunk.ChunkOrderingConstraint
          Possible ordering constraint for a PngChunk type -only relevant for ancillary chunks.
 
Field Summary
 boolean crit
          Autocomputed at creation time
 String id
          Chunk-id: 4 letters
 boolean pub
          Autocomputed at creation time
 boolean safe
          Autocomputed at creation time
 
Method Summary
abstract  boolean allowsMultiple()
           
static
<T extends PngChunk>
T
cloneChunk(T chunk, ImageInfo info)
          Makes a clone (deep copy) calling cloneDataFromRead(PngChunk)
abstract  void cloneDataFromRead(PngChunk other)
          Makes a copy of the chunk.
abstract  ChunkRaw createRawChunk()
          Creates the physical chunk.
static PngChunk factory(ChunkRaw chunk, ImageInfo info)
          This factory creates the corresponding chunk and parses the raw chunk.
static PngChunk factoryFromId(String cid, ImageInfo info)
          Creates one new blank chunk of the corresponding type, according to factoryMap (PngChunkUNKNOWN if not known)
static void factoryRegister(String chunkId, Class<? extends PngChunk> chunkClass)
          Registers a chunk-id (4 letters) to be associated with a PngChunk class This method should be called by user code that wants to add some chunks (not implmemented in this library) to the factory, so that the PngReader knows about it.
 int getChunkGroup()
          In which "chunkGroup" (see ChunksListfor definition) this chunks instance was read or written.
abstract  PngChunk.ChunkOrderingConstraint getOrderingConstraint()
          see PngChunk.ChunkOrderingConstraint
 boolean hasPriority()
           
static boolean isKnown(String id)
          True if the chunk-id type is known.
abstract  void parseFromRaw(ChunkRaw c)
          Parses raw chunk and fill inside data.
 void setChunkGroup(int chunkGroup)
           
 void setPriority(boolean priority)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

crit

public final boolean crit
Autocomputed at creation time


id

public final String id
Chunk-id: 4 letters


pub

public final boolean pub
Autocomputed at creation time


safe

public final boolean safe
Autocomputed at creation time

Method Detail

allowsMultiple

public abstract boolean allowsMultiple()

cloneChunk

public static <T extends PngChunk> T cloneChunk(T chunk,
                                                ImageInfo info)
Makes a clone (deep copy) calling cloneDataFromRead(PngChunk)


cloneDataFromRead

public abstract void cloneDataFromRead(PngChunk other)
Makes a copy of the chunk.

This is used when copying chunks from a reader to a writer

It should normally be a deep copy, and after the cloning this.equals(other) should return true


createRawChunk

public abstract ChunkRaw createRawChunk()
Creates the physical chunk. This is used when writing (serialization). Each particular chunk class implements its own logic.

Returns:
A newly allocated and filled raw chunk

factory

public static PngChunk factory(ChunkRaw chunk,
                               ImageInfo info)
This factory creates the corresponding chunk and parses the raw chunk. This is used when reading.


factoryFromId

public static PngChunk factoryFromId(String cid,
                                     ImageInfo info)
Creates one new blank chunk of the corresponding type, according to factoryMap (PngChunkUNKNOWN if not known)


factoryRegister

public static void factoryRegister(String chunkId,
                                   Class<? extends PngChunk> chunkClass)
Registers a chunk-id (4 letters) to be associated with a PngChunk class

This method should be called by user code that wants to add some chunks (not implmemented in this library) to the factory, so that the PngReader knows about it.


getChunkGroup

public final int getChunkGroup()
In which "chunkGroup" (see ChunksListfor definition) this chunks instance was read or written.

-1 if not read or written (eg, queued)


getOrderingConstraint

public abstract PngChunk.ChunkOrderingConstraint getOrderingConstraint()
see PngChunk.ChunkOrderingConstraint


hasPriority

public boolean hasPriority()

isKnown

public static boolean isKnown(String id)
True if the chunk-id type is known.

A chunk is known if we recognize its class, according with factoryMap

This is not necessarily the same as being "STANDARD", or being implemented in this library

Unknown chunks will be parsed as instances of PngChunkUNKNOWN


parseFromRaw

public abstract void parseFromRaw(ChunkRaw c)
Parses raw chunk and fill inside data. This is used when reading (deserialization). Each particular chunk class implements its own logic.


setChunkGroup

public final void setChunkGroup(int chunkGroup)
See Also:
getChunkGroup()

setPriority

public void setPriority(boolean priority)

toString

public String toString()
Overrides:
toString in class Object