Home | History | Annotate | Download | only in webp
      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 (at) 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 ANMF_CHUNK_SIZE    16    // Size of an ANMF chunk.
     69 #define ANIM_CHUNK_SIZE    6     // Size of an ANIM chunk.
     70 #define FRGM_CHUNK_SIZE    6     // Size of a FRGM chunk.
     71 #define VP8X_CHUNK_SIZE    10    // Size of a VP8X chunk.
     72 
     73 // VP8X Feature Flags.
     74 #if !(defined(__cplusplus) || defined(c_plusplus))
     75 typedef enum WebPFeatureFlags WebPFeatureFlags;
     76 #endif
     77 enum WebPFeatureFlags {
     78   FRAGMENTS_FLAG  = 0x00000001,
     79   ANIMATION_FLAG  = 0x00000002,
     80   XMP_FLAG        = 0x00000004,
     81   EXIF_FLAG       = 0x00000008,
     82   ALPHA_FLAG      = 0x00000010,
     83   ICCP_FLAG       = 0x00000020
     84 };
     85 
     86 #define MAX_CANVAS_SIZE     (1 << 24)    // 24-bit max for VP8X width/height.
     87 #define MAX_IMAGE_AREA      (1ULL << 32) // 32-bit max for width x height.
     88 #define MAX_LOOP_COUNT      (1 << 16)    // maximum value for loop-count
     89 #define MAX_DURATION        (1 << 24)    // maximum duration
     90 #define MAX_POSITION_OFFSET (1 << 24)    // maximum frame/fragment x/y offset
     91 
     92 // Maximum chunk payload is such that adding the header and padding won't
     93 // overflow a uint32_t.
     94 #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1)
     95 
     96 #endif  /* WEBP_WEBP_FORMAT_CONSTANTS_H_ */
     97