ar.com.hjg.pngj.chunks
Class ChunkHelper

java.lang.Object
  extended by ar.com.hjg.pngj.chunks.ChunkHelper

public class ChunkHelper
extends java.lang.Object


Field Summary
static byte[] b_IDAT
           
static byte[] b_IEND
           
static byte[] b_IHDR
           
static byte[] b_PLTE
           
static java.lang.String bKGD
           
static java.lang.String cHRM
           
static java.lang.String gAMA
           
static java.lang.String hIST
           
static java.lang.String iCCP
           
static java.lang.String IDAT
           
static java.lang.String IEND
           
static java.lang.String IHDR
           
static java.lang.String iTXt
           
static java.lang.String pHYs
           
static java.lang.String PLTE
           
static java.lang.String sBIT
           
static java.lang.String sPLT
           
static java.lang.String sRGB
           
static java.lang.String tEXt
           
static java.lang.String tIME
           
static java.lang.String tRNS
           
static java.lang.String zTXt
           
 
Constructor Summary
ChunkHelper()
           
 
Method Summary
static byte[] compressBytes(byte[] ori, boolean compress)
           
static byte[] compressBytes(byte[] ori, int offset, int len, boolean compress)
           
static boolean equivalent(PngChunk c1, PngChunk c2)
          MY adhoc criteria: two chunks are "equivalent" ("practically equal") if they have same id and (perhaps, if multiple are allowed) if the match also in some "internal key" (eg: key for string values, palette for sPLT, etc) Notice that the use of this is optional, and that the PNG standard allows Text chunks that have same key
static java.util.List<PngChunk> filterList(java.util.List<PngChunk> target, ChunkPredicate predicateKeep)
          Returns only the chunks that "match" the predicate See also trimList()
static boolean isCritical(java.lang.String id)
          critical chunk : first letter is uppercase
static boolean isPublic(java.lang.String id)
          public chunk: second letter is uppercase
static boolean isSafeToCopy(java.lang.String id)
          Safe to copy chunk: fourth letter is lower case
static boolean isUnknown(PngChunk c)
          "Unknown" just means that our chunk factory (even when it has been augmented by client code) did not recognize its id
static boolean maskMatch(int v, int mask)
           
static int posNullByte(byte[] b)
          Finds position of null byte in array
static boolean shouldLoad(java.lang.String id, ChunkLoadBehaviour behav)
          Decides if a chunk should be loaded, according to a ChunkLoadBehaviour
static byte[] toBytes(java.lang.String x)
          Converts to bytes using Latin1 (ISO-8859-1)
static byte[] toBytesUTF8(java.lang.String x)
          Converts to bytes using UTF-8
static java.lang.String toString(byte[] x)
          Converts to String using Latin1 (ISO-8859-1)
static java.lang.String toString(byte[] x, int offset, int len)
          Converts to String using Latin1 (ISO-8859-1)
static java.lang.String toStringUTF8(byte[] x)
          Converts to string using UTF-8
static java.lang.String toStringUTF8(byte[] x, int offset, int len)
          Converts to string using UTF-8
static int trimList(java.util.List<PngChunk> target, ChunkPredicate predicateRemove)
          Remove (in place) the chunks that "match" the predicate See also filterList
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

b_IDAT

public static final byte[] b_IDAT

b_IEND

public static final byte[] b_IEND

b_IHDR

public static final byte[] b_IHDR

b_PLTE

public static final byte[] b_PLTE

bKGD

public static final java.lang.String bKGD
See Also:
Constant Field Values

cHRM

public static final java.lang.String cHRM
See Also:
Constant Field Values

gAMA

public static final java.lang.String gAMA
See Also:
Constant Field Values

hIST

public static final java.lang.String hIST
See Also:
Constant Field Values

iCCP

public static final java.lang.String iCCP
See Also:
Constant Field Values

IDAT

public static final java.lang.String IDAT
See Also:
Constant Field Values

IEND

public static final java.lang.String IEND
See Also:
Constant Field Values

IHDR

public static final java.lang.String IHDR
See Also:
Constant Field Values

iTXt

public static final java.lang.String iTXt
See Also:
Constant Field Values

pHYs

public static final java.lang.String pHYs
See Also:
Constant Field Values

PLTE

public static final java.lang.String PLTE
See Also:
Constant Field Values

sBIT

public static final java.lang.String sBIT
See Also:
Constant Field Values

sPLT

public static final java.lang.String sPLT
See Also:
Constant Field Values

sRGB

public static final java.lang.String sRGB
See Also:
Constant Field Values

tEXt

public static final java.lang.String tEXt
See Also:
Constant Field Values

tIME

public static final java.lang.String tIME
See Also:
Constant Field Values

tRNS

public static final java.lang.String tRNS
See Also:
Constant Field Values

zTXt

public static final java.lang.String zTXt
See Also:
Constant Field Values
Constructor Detail

ChunkHelper

public ChunkHelper()
Method Detail

compressBytes

public static final byte[] compressBytes(byte[] ori,
                                         boolean compress)

compressBytes

public static byte[] compressBytes(byte[] ori,
                                   int offset,
                                   int len,
                                   boolean compress)

equivalent

public static final boolean equivalent(PngChunk c1,
                                       PngChunk c2)
MY adhoc criteria: two chunks are "equivalent" ("practically equal") if they have same id and (perhaps, if multiple are allowed) if the match also in some "internal key" (eg: key for string values, palette for sPLT, etc) Notice that the use of this is optional, and that the PNG standard allows Text chunks that have same key

Returns:
true if "equivalent"

filterList

public static java.util.List<PngChunk> filterList(java.util.List<PngChunk> target,
                                                  ChunkPredicate predicateKeep)
Returns only the chunks that "match" the predicate See also trimList()


isCritical

public static boolean isCritical(java.lang.String id)
critical chunk : first letter is uppercase

Parameters:
id -
Returns:
true/false

isPublic

public static boolean isPublic(java.lang.String id)
public chunk: second letter is uppercase

Parameters:
id -
Returns:
true/false

isSafeToCopy

public static boolean isSafeToCopy(java.lang.String id)
Safe to copy chunk: fourth letter is lower case

Parameters:
id -
Returns:

isUnknown

public static boolean isUnknown(PngChunk c)
"Unknown" just means that our chunk factory (even when it has been augmented by client code) did not recognize its id

Parameters:
c - chunk
Returns:
true/false

maskMatch

public static boolean maskMatch(int v,
                                int mask)

posNullByte

public static int posNullByte(byte[] b)
Finds position of null byte in array

Parameters:
b -
Returns:
-1 if not found

shouldLoad

public static boolean shouldLoad(java.lang.String id,
                                 ChunkLoadBehaviour behav)
Decides if a chunk should be loaded, according to a ChunkLoadBehaviour

Parameters:
id -
behav -
Returns:
true/false

toBytes

public static byte[] toBytes(java.lang.String x)
Converts to bytes using Latin1 (ISO-8859-1)

Parameters:
x -
Returns:

toBytesUTF8

public static byte[] toBytesUTF8(java.lang.String x)
Converts to bytes using UTF-8

Parameters:
x -
Returns:

toString

public static java.lang.String toString(byte[] x)
Converts to String using Latin1 (ISO-8859-1)

Parameters:
x -
Returns:

toString

public static java.lang.String toString(byte[] x,
                                        int offset,
                                        int len)
Converts to String using Latin1 (ISO-8859-1)

Parameters:
x -
offset -
len -
Returns:

toStringUTF8

public static java.lang.String toStringUTF8(byte[] x)
Converts to string using UTF-8

Parameters:
x -
Returns:

toStringUTF8

public static java.lang.String toStringUTF8(byte[] x,
                                            int offset,
                                            int len)
Converts to string using UTF-8

Parameters:
x -
offset -
len -
Returns:

trimList

public static int trimList(java.util.List<PngChunk> target,
                           ChunkPredicate predicateRemove)
Remove (in place) the chunks that "match" the predicate See also filterList