ar.com.hjg.pngj.chunks
Class ChunkHelper

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

public class ChunkHelper
extends Object


Field Summary
static byte[] b_IDAT
           
static byte[] b_IEND
           
static byte[] b_IHDR
           
static byte[] b_PLTE
           
static String bKGD
           
static String cHRM
           
static String gAMA
           
static String hIST
           
static String iCCP
           
static String IDAT
           
static String IEND
           
static String IHDR
           
static String iTXt
           
static String pHYs
           
static String PLTE
           
static String sBIT
           
static String sPLT
           
static String sRGB
           
static String tEXt
           
static String tIME
           
static String tRNS
           
static 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 List<PngChunk> filterList(List<PngChunk> target, ChunkPredicate predicateKeep)
          Returns only the chunks that "match" the predicate See also trimList()
static boolean isCritical(String id)
          critical chunk : first letter is uppercase
static boolean isPublic(String id)
          public chunk: second letter is uppercase
static boolean isSafeToCopy(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(String id, ChunkLoadBehaviour behav)
          Decides if a chunk should be loaded, according to a ChunkLoadBehaviour
static byte[] toBytes(String x)
          Converts to bytes using Latin1 (ISO-8859-1)
static byte[] toBytesUTF8(String x)
          Converts to bytes using UTF-8
static String toString(byte[] x)
          Converts to String using Latin1 (ISO-8859-1)
static String toString(byte[] x, int offset, int len)
          Converts to String using Latin1 (ISO-8859-1)
static String toStringUTF8(byte[] x)
          Converts to string using UTF-8
static String toStringUTF8(byte[] x, int offset, int len)
          Converts to string using UTF-8
static int trimList(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 String bKGD
See Also:
Constant Field Values

cHRM

public static final String cHRM
See Also:
Constant Field Values

gAMA

public static final String gAMA
See Also:
Constant Field Values

hIST

public static final String hIST
See Also:
Constant Field Values

iCCP

public static final String iCCP
See Also:
Constant Field Values

IDAT

public static final String IDAT
See Also:
Constant Field Values

IEND

public static final String IEND
See Also:
Constant Field Values

IHDR

public static final String IHDR
See Also:
Constant Field Values

iTXt

public static final String iTXt
See Also:
Constant Field Values

pHYs

public static final String pHYs
See Also:
Constant Field Values

PLTE

public static final String PLTE
See Also:
Constant Field Values

sBIT

public static final String sBIT
See Also:
Constant Field Values

sPLT

public static final String sPLT
See Also:
Constant Field Values

sRGB

public static final String sRGB
See Also:
Constant Field Values

tEXt

public static final String tEXt
See Also:
Constant Field Values

tIME

public static final String tIME
See Also:
Constant Field Values

tRNS

public static final String tRNS
See Also:
Constant Field Values

zTXt

public static final 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 List<PngChunk> filterList(List<PngChunk> target,
                                        ChunkPredicate predicateKeep)
Returns only the chunks that "match" the predicate See also trimList()


isCritical

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

Parameters:
id -
Returns:
true/false

isPublic

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

Parameters:
id -
Returns:
true/false

isSafeToCopy

public static boolean isSafeToCopy(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(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(String x)
Converts to bytes using Latin1 (ISO-8859-1)

Parameters:
x -
Returns:

toBytesUTF8

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

Parameters:
x -
Returns:

toString

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

Parameters:
x -
Returns:

toString

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

Parameters:
x -
offset -
len -
Returns:

toStringUTF8

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

Parameters:
x -
Returns:

toStringUTF8

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

Parameters:
x -
offset -
len -
Returns:

trimList

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