format_constants.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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) ((uint32_t)(a) | (b) << 8 | (c) << 16 | (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 FRGM_CHUNK_SIZE 6 // Size of a FRGM chunk.
  65. #define VP8X_CHUNK_SIZE 10 // Size of a VP8X chunk.
  66. #define MAX_CANVAS_SIZE (1 << 24) // 24-bit max for VP8X width/height.
  67. #define MAX_IMAGE_AREA (1ULL << 32) // 32-bit max for width x height.
  68. #define MAX_LOOP_COUNT (1 << 16) // maximum value for loop-count
  69. #define MAX_DURATION (1 << 24) // maximum duration
  70. #define MAX_POSITION_OFFSET (1 << 24) // maximum frame/fragment x/y offset
  71. // Maximum chunk payload is such that adding the header and padding won't
  72. // overflow a uint32_t.
  73. #define MAX_CHUNK_PAYLOAD (~0U - CHUNK_HEADER_SIZE - 1)
  74. #endif /* WEBP_WEBP_FORMAT_CONSTANTS_H_ */