1 /* chunkhash.h -- a perfect hash code for the chunk names in png.h
3 * Last changed in libpng 1.7.0 [(PENDING RELEASE)]
5 * THIS IS A MACHINE GENERATED FILE. See contrib/tools/chunkhash.c for
6 * copyright and other information.
8 * USAGE: To include the PNG_CHUNK_HASH macro and associated definitions:
10 * #define PNG_CHUNKHASH_DEFS
11 * #include "contrib/tools/chunkhash.h"
13 * To define the png_chunk_hash array used by the macro:
15 * #define PNG_CHUNKHASH_CODE
16 * #include "contrib/tools/chunkhash.h"
18 * One or both of the defines must be given except when building chunkhash
21 #ifdef PNG_CHUNKHASH_DEFS
22 #ifndef PNG_CHUNKHASH_H
23 #define PNG_CHUNKHASH_H
24 /* A perfect hash code - returns a value 0..(PNG_KNOWN_CHUNK_COUNT-1) and is
25 * generated by the ridiculously simple program in contrib/tools/chunkhash.c
27 * The hash code used here multiplies each byte by a different constant to
28 * return a single number:
30 * b0 * c[0] + b1 * [c1] + b2 * c[2] + b3 * c[3]
32 * The values of the constants are found by search using the a table of
33 * primes, including 0, and may be (in fact are at present) 0 for some of the
34 * bytes, the compiler is expected to optimize multiply by zero, or one!
36 * The lookup table reduces the sparse result of the hash calculation to the
37 * correct index values. The chunks are indexed in the string order of the
38 * png_uint_32 chunk names.
40 #define PNG_CHUNK_HASH_MASK 0x3fU
41 #define PNG_CHUNK_HASH_C0 103
42 #define PNG_CHUNK_HASH_C1 1
43 #define PNG_CHUNK_HASH_C2 0
44 #define PNG_CHUNK_HASH_C3 1
46 #define PNG_CHUNK_IDAT_TAG 0
47 #define PNG_CHUNK_IEND_TAG 1
48 #define PNG_CHUNK_IHDR_TAG 2
49 #define PNG_CHUNK_PLTE_TAG 3
50 #define PNG_CHUNK_bKGD_TAG 4
51 #define PNG_CHUNK_cHRM_TAG 5
52 #define PNG_CHUNK_fRAc_TAG 6
53 #define PNG_CHUNK_gAMA_TAG 7
54 #define PNG_CHUNK_gIFg_TAG 8
55 #define PNG_CHUNK_gIFt_TAG 9
56 #define PNG_CHUNK_gIFx_TAG 10
57 #define PNG_CHUNK_hIST_TAG 11
58 #define PNG_CHUNK_iCCP_TAG 12
59 #define PNG_CHUNK_iTXt_TAG 13
60 #define PNG_CHUNK_oFFs_TAG 14
61 #define PNG_CHUNK_pCAL_TAG 15
62 #define PNG_CHUNK_pHYs_TAG 16
63 #define PNG_CHUNK_sBIT_TAG 17
64 #define PNG_CHUNK_sCAL_TAG 18
65 #define PNG_CHUNK_sPLT_TAG 19
66 #define PNG_CHUNK_sRGB_TAG 20
67 #define PNG_CHUNK_sTER_TAG 21
68 #define PNG_CHUNK_tEXt_TAG 22
69 #define PNG_CHUNK_tIME_TAG 23
70 #define PNG_CHUNK_tRNS_TAG 24
71 #define PNG_CHUNK_zTXt_TAG 25
73 #define PNG_KNOWN_CHUNK_COUNT 26
75 extern const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1];
76 #endif /* !PNG_CHUNKHASH_H */
77 #endif /* PNG_CHUNKHASH_DEFS */
79 #ifndef PNG_CHUNK_HASH
80 #define PNG_CHUNK_HASH(chunk) (png_chunk_hash[PNG_CHUNK_HASH_MASK & (\
81 ((chunk) >> 24) * PNG_CHUNK_HASH_C0 +\
82 ((chunk) >> 16) * PNG_CHUNK_HASH_C1 +\
83 ((chunk) >> 8) * PNG_CHUNK_HASH_C2 +\
84 ((chunk) ) * PNG_CHUNK_HASH_C3)])
87 #ifdef PNG_CHUNKHASH_CODE
88 #ifndef PNG_CHUNKHASH_C
89 #define PNG_CHUNKHASH_C
90 const png_byte png_chunk_hash[PNG_CHUNK_HASH_MASK+1] = {
91 26, 3, 26, 26, 26, 26, 26, 13, 26, 26, 26, 16, 26, 26, 26, 26,
92 26, 24, 12, 26, 18, 26, 26, 26, 26, 20, 26, 17, 26, 26, 25, 15,
93 26, 8, 14, 26, 26, 22, 26, 26, 1, 19, 5, 21, 26, 26, 9, 26,
94 26, 26, 10, 7, 26, 11, 26, 0, 26, 2, 23, 26, 26, 4, 26, 6
96 #endif /* !PNG_CHUNKHASH_C */
97 #endif /* PNG_CHUNKHASH_CODE */