format_constants.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #ifndef WEBP_WEBP_FORMAT_CONSTANTS_H_
  14. #define WEBP_WEBP_FORMAT_CONSTANTS_H_
  15. // Create fourcc of the chunk from the chunk tag characters.
  16. #define MKFOURCC(a, b, c, d) ((a) | (b) << 8 | (c) << 16 | (uint32_t)(d) << 24)
  17. // VP8 related constants.
  18. #define VP8_SIGNATURE 0x9d012a // Signature in VP8 data.
  19. #define VP8_MAX_PARTITION0_SIZE (1 << 19) // max size of mode partition
  20. #define VP8_MAX_PARTITION_SIZE (1 << 24) // max size for token partition
  21. #define VP8_FRAME_HEADER_SIZE 10 // Size of the frame header within VP8 data.
  22. // VP8L related constants.
  23. #define VP8L_SIGNATURE_SIZE 1 // VP8L signature size.
  24. #define VP8L_MAGIC_BYTE 0x2f // VP8L signature byte.
  25. #define VP8L_IMAGE_SIZE_BITS 14 // Number of bits used to store
  26. // width and height.
  27. #define VP8L_VERSION_BITS 3 // 3 bits reserved for version.
  28. #define VP8L_VERSION 0 // version 0
  29. #define VP8L_FRAME_HEADER_SIZE 5 // Size of the VP8L frame header.
  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. #define DEFAULT_CODE_LENGTH 8
  35. #define MAX_ALLOWED_CODE_LENGTH 15
  36. #define NUM_LITERAL_CODES 256
  37. #define NUM_LENGTH_CODES 24
  38. #define NUM_DISTANCE_CODES 40
  39. #define CODE_LENGTH_CODES 19
  40. #define MIN_HUFFMAN_BITS 2 // min number of Huffman bits
  41. #define MAX_HUFFMAN_BITS 9 // max number of Huffman bits
  42. #define TRANSFORM_PRESENT 1 // The bit to be written when next data
  43. // to be read is a transform.
  44. #define NUM_TRANSFORMS 4 // Maximum number of allowed transform
  45. // in a bitstream.
  46. typedef enum {
  47. PREDICTOR_TRANSFORM = 0,
  48. CROSS_COLOR_TRANSFORM = 1,
  49. SUBTRACT_GREEN = 2,
  50. COLOR_INDEXING_TRANSFORM = 3
  51. } VP8LImageTransformType;
  52. // Alpha related constants.
  53. #define ALPHA_HEADER_LEN 1
  54. #define ALPHA_NO_COMPRESSION 0
  55. #define ALPHA_LOSSLESS_COMPRESSION 1
  56. #define ALPHA_PREPROCESSED_LEVELS 1
  57. // Mux related constants.
  58. #define TAG_SIZE 4 // Size of a chunk tag (e.g. "VP8L").
  59. #define CHUNK_SIZE_BYTES 4 // Size needed to store chunk's size.
  60. #define CHUNK_HEADER_SIZE 8 // Size of a chunk header.
  61. #define RIFF_HEADER_SIZE 12 // Size of the RIFF header ("RIFFnnnnWEBP").
  62. #define ANMF_CHUNK_SIZE 16 // Size of an ANMF chunk.
  63. #define ANIM_CHUNK_SIZE 6 // Size of an ANIM chunk.
  64. #define VP8X_CHUNK_SIZE 10 // Size of a VP8X chunk.
  65. #define MAX_CANVAS_SIZE (1 << 24) // 24-bit max for VP8X width/height.
  66. #define MAX_IMAGE_AREA (1ULL << 32) // 32-bit max for width x height.
  67. #define MAX_LOOP_COUNT (1 << 16) // maximum value for loop-count
  68. #define MAX_DURATION (1 << 24) // maximum duration
  69. #define MAX_POSITION_OFFSET (1 << 24) // maximum frame x/y offset
  70. // Maximum chunk payload is such that adding the header and padding won't
  71. // overflow a uint32_t.
  72. #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1)
  73. #endif // WEBP_WEBP_FORMAT_CONSTANTS_H_