1 // Copyright 2012 Google Inc. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the COPYING file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 // ----------------------------------------------------------------------------- 9 // 10 // Internal header for constants related to WebP file format. 11 // 12 // Author: Urvang (urvang@google.com) 13 14 #ifndef WEBP_WEBP_FORMAT_CONSTANTS_H_ 15 #define WEBP_WEBP_FORMAT_CONSTANTS_H_ 16 17 // Create fourcc of the chunk from the chunk tag characters. 18 #define MKFOURCC(a, b, c, d) ((a) | (b) << 8 | (c) << 16 | (uint32_t)(d) << 24) 19 20 // VP8 related constants. 21 #define VP8_SIGNATURE 0x9d012a // Signature in VP8 data. 22 #define VP8_MAX_PARTITION0_SIZE (1 << 19) // max size of mode partition 23 #define VP8_MAX_PARTITION_SIZE (1 << 24) // max size for token partition 24 #define VP8_FRAME_HEADER_SIZE 10 // Size of the frame header within VP8 data. 25 26 // VP8L related constants. 27 #define VP8L_SIGNATURE_SIZE 1 // VP8L signature size. 28 #define VP8L_MAGIC_BYTE 0x2f // VP8L signature byte. 29 #define VP8L_IMAGE_SIZE_BITS 14 // Number of bits used to store 30 // width and height. 31 #define VP8L_VERSION_BITS 3 // 3 bits reserved for version. 32 #define VP8L_VERSION 0 // version 0 33 #define VP8L_FRAME_HEADER_SIZE 5 // Size of the VP8L frame header. 34 35 #define MAX_PALETTE_SIZE 256 36 #define MAX_CACHE_BITS 11 37 #define HUFFMAN_CODES_PER_META_CODE 5 38 #define ARGB_BLACK 0xff000000 39 40 #define DEFAULT_CODE_LENGTH 8 41 #define MAX_ALLOWED_CODE_LENGTH 15 42 43 #define NUM_LITERAL_CODES 256 44 #define NUM_LENGTH_CODES 24 45 #define NUM_DISTANCE_CODES 40 46 #define CODE_LENGTH_CODES 19 47 48 #define MIN_HUFFMAN_BITS 2 // min number of Huffman bits 49 #define MAX_HUFFMAN_BITS 9 // max number of Huffman bits 50 51 #define TRANSFORM_PRESENT 1 // The bit to be written when next data 52 // to be read is a transform. 53 #define NUM_TRANSFORMS 4 // Maximum number of allowed transform 54 // in a bitstream. 55 typedef enum { 56 PREDICTOR_TRANSFORM = 0, 57 CROSS_COLOR_TRANSFORM = 1, 58 SUBTRACT_GREEN_TRANSFORM = 2, 59 COLOR_INDEXING_TRANSFORM = 3 60 } VP8LImageTransformType; 61 62 // Alpha related constants. 63 #define ALPHA_HEADER_LEN 1 64 #define ALPHA_NO_COMPRESSION 0 65 #define ALPHA_LOSSLESS_COMPRESSION 1 66 #define ALPHA_PREPROCESSED_LEVELS 1 67 68 // Mux related constants. 69 #define TAG_SIZE 4 // Size of a chunk tag (e.g. "VP8L"). 70 #define CHUNK_SIZE_BYTES 4 // Size needed to store chunk's size. 71 #define CHUNK_HEADER_SIZE 8 // Size of a chunk header. 72 #define RIFF_HEADER_SIZE 12 // Size of the RIFF header ("RIFFnnnnWEBP"). 73 #define ANMF_CHUNK_SIZE 16 // Size of an ANMF chunk. 74 #define ANIM_CHUNK_SIZE 6 // Size of an ANIM chunk. 75 #define VP8X_CHUNK_SIZE 10 // Size of a VP8X chunk. 76 77 #define MAX_CANVAS_SIZE (1 << 24) // 24-bit max for VP8X width/height. 78 #define MAX_IMAGE_AREA (1ULL << 32) // 32-bit max for width x height. 79 #define MAX_LOOP_COUNT (1 << 16) // maximum value for loop-count 80 #define MAX_DURATION (1 << 24) // maximum duration 81 #define MAX_POSITION_OFFSET (1 << 24) // maximum frame x/y offset 82 83 // Maximum chunk payload is such that adding the header and padding won't 84 // overflow a uint32_t. 85 #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1) 86 87 #endif // WEBP_WEBP_FORMAT_CONSTANTS_H_ 88