• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2012 Google Inc. All Rights Reserved.
2 //
3 // This code is licensed under the same terms as WebM:
4 //  Software License Agreement:  http://www.webmproject.org/license/software/
5 //  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 //  Internal header for constants related to WebP file format.
9 //
10 // Author: Urvang (urvang@google.com)
11 
12 #ifndef WEBP_WEBP_FORMAT_CONSTANTS_H_
13 #define WEBP_WEBP_FORMAT_CONSTANTS_H_
14 
15 // VP8 related constants.
16 #define VP8_SIGNATURE 0x9d012a              // Signature in VP8 data.
17 #define VP8_MAX_PARTITION0_SIZE (1 << 19)   // max size of mode partition
18 #define VP8_MAX_PARTITION_SIZE  (1 << 24)   // max size for token partition
19 #define VP8_FRAME_HEADER_SIZE 10  // Size of the frame header within VP8 data.
20 
21 // VP8L related constants.
22 #define VP8L_SIGNATURE_SIZE          1      // VP8L signature size.
23 #define VP8L_MAGIC_BYTE              0x2f   // VP8L signature byte.
24 #define VP8L_IMAGE_SIZE_BITS         14     // Number of bits used to store
25                                             // width and height.
26 #define VP8L_VERSION_BITS            3      // 3 bits reserved for version.
27 #define VP8L_VERSION                 0      // version 0
28 #define VP8L_FRAME_HEADER_SIZE       5      // Size of the VP8L frame header.
29 
30 #define MAX_PALETTE_SIZE             256
31 #define MAX_CACHE_BITS               11
32 #define HUFFMAN_CODES_PER_META_CODE  5
33 #define ARGB_BLACK                   0xff000000
34 
35 #define DEFAULT_CODE_LENGTH          8
36 #define MAX_ALLOWED_CODE_LENGTH      15
37 
38 #define NUM_LITERAL_CODES            256
39 #define NUM_LENGTH_CODES             24
40 #define NUM_DISTANCE_CODES           40
41 #define CODE_LENGTH_CODES            19
42 
43 #define MIN_HUFFMAN_BITS             2  // min number of Huffman bits
44 #define MAX_HUFFMAN_BITS             9  // max number of Huffman bits
45 
46 #define TRANSFORM_PRESENT            1  // The bit to be written when next data
47                                         // to be read is a transform.
48 #define NUM_TRANSFORMS               4  // Maximum number of allowed transform
49                                         // in a bitstream.
50 typedef enum {
51   PREDICTOR_TRANSFORM      = 0,
52   CROSS_COLOR_TRANSFORM    = 1,
53   SUBTRACT_GREEN           = 2,
54   COLOR_INDEXING_TRANSFORM = 3
55 } VP8LImageTransformType;
56 
57 // Alpha related constants.
58 #define ALPHA_HEADER_LEN            1
59 #define ALPHA_NO_COMPRESSION        0
60 #define ALPHA_LOSSLESS_COMPRESSION  1
61 #define ALPHA_PREPROCESSED_LEVELS   1
62 
63 // Mux related constants.
64 #define TAG_SIZE           4     // Size of a chunk tag (e.g. "VP8L").
65 #define CHUNK_SIZE_BYTES   4     // Size needed to store chunk's size.
66 #define CHUNK_HEADER_SIZE  8     // Size of a chunk header.
67 #define RIFF_HEADER_SIZE   12    // Size of the RIFF header ("RIFFnnnnWEBP").
68 #define FRAME_CHUNK_SIZE   15    // Size of a FRM chunk.
69 #define LOOP_CHUNK_SIZE    2     // Size of a LOOP chunk.
70 #define TILE_CHUNK_SIZE    6     // Size of a TILE chunk.
71 #define VP8X_CHUNK_SIZE    10    // Size of a VP8X chunk.
72 
73 #define TILING_FLAG_BIT    0x01  // Set if tiles are possibly used.
74 #define ANIMATION_FLAG_BIT 0x02  // Set if some animation is expected
75 #define ICC_FLAG_BIT       0x04  // Whether ICC is present or not.
76 #define METADATA_FLAG_BIT  0x08  // Set if some META chunk is possibly present.
77 #define ALPHA_FLAG_BIT     0x10  // Should be same as the ALPHA_FLAG in mux.h
78 #define ROTATION_FLAG_BITS 0xe0  // all 3 bits for rotation + symmetry
79 
80 #define MAX_CANVAS_SIZE     (1 << 24)    // 24-bit max for VP8X width/height.
81 #define MAX_IMAGE_AREA      (1ULL << 32) // 32-bit max for width x height.
82 #define MAX_LOOP_COUNT      (1 << 16)    // maximum value for loop-count
83 #define MAX_DURATION        (1 << 24)    // maximum duration
84 #define MAX_POSITION_OFFSET (1 << 24)    // maximum frame/tile x/y offset
85 
86 // Maximum chunk payload is such that adding the header and padding won't
87 // overflow a uint32_t.
88 #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1)
89 
90 #endif  /* WEBP_WEBP_FORMAT_CONSTANTS_H_ */
91