hap.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Vidvox Hap
  3. * Copyright (C) 2015 Vittorio Giovara <vittorio.giovara@gmail.com>
  4. * Copyright (C) 2015 Tom Butterworth <bangnoise@gmail.com>
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef AVCODEC_HAP_H
  23. #define AVCODEC_HAP_H
  24. #include <stdint.h>
  25. #include "libavutil/opt.h"
  26. #include "bytestream.h"
  27. #include "texturedsp.h"
  28. enum HapTextureFormat {
  29. HAP_FMT_RGBDXT1 = 0x0B,
  30. HAP_FMT_RGBADXT5 = 0x0E,
  31. HAP_FMT_YCOCGDXT5 = 0x0F,
  32. HAP_FMT_RGTC1 = 0x01,
  33. };
  34. enum HapCompressor {
  35. HAP_COMP_NONE = 0xA0,
  36. HAP_COMP_SNAPPY = 0xB0,
  37. HAP_COMP_COMPLEX = 0xC0,
  38. };
  39. enum HapSectionType {
  40. HAP_ST_DECODE_INSTRUCTIONS = 0x01,
  41. HAP_ST_COMPRESSOR_TABLE = 0x02,
  42. HAP_ST_SIZE_TABLE = 0x03,
  43. HAP_ST_OFFSET_TABLE = 0x04,
  44. };
  45. typedef struct HapChunk {
  46. enum HapCompressor compressor;
  47. int compressed_offset;
  48. size_t compressed_size;
  49. int uncompressed_offset;
  50. size_t uncompressed_size;
  51. } HapChunk;
  52. typedef struct HapContext {
  53. AVClass *class;
  54. TextureDSPContext dxtc;
  55. GetByteContext gbc;
  56. enum HapTextureFormat opt_tex_fmt; /* Texture type (encoder only) */
  57. int opt_chunk_count; /* User-requested chunk count (encoder only) */
  58. int opt_compressor; /* User-requested compressor (encoder only) */
  59. int chunk_count;
  60. HapChunk *chunks;
  61. int *chunk_results; /* Results from threaded operations */
  62. int tex_rat; /* Compression ratio */
  63. int tex_rat2; /* Compression ratio of the second texture */
  64. const uint8_t *tex_data; /* Compressed texture */
  65. uint8_t *tex_buf; /* Buffer for compressed texture */
  66. size_t tex_size; /* Size of the compressed texture */
  67. size_t max_snappy; /* Maximum compressed size for snappy buffer */
  68. int slice_count; /* Number of slices for threaded operations */
  69. int texture_count; /* 2 for HAQA, 1 for other version */
  70. int texture_section_size; /* size of the part of the texture section (for HAPQA) */
  71. int uncompress_pix_size; /* nb of byte / pixel for the target picture */
  72. /* Pointer to the selected compress or decompress function */
  73. int (*tex_fun)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
  74. int (*tex_fun2)(uint8_t *dst, ptrdiff_t stride, const uint8_t *block);
  75. } HapContext;
  76. /*
  77. * Set the number of chunks in the frame. Returns 0 on success or an error if:
  78. * - first_in_frame is 0 and the number of chunks has changed
  79. * - any other error occurs
  80. */
  81. int ff_hap_set_chunk_count(HapContext *ctx, int count, int first_in_frame);
  82. /*
  83. * Free resources associated with the context
  84. */
  85. av_cold void ff_hap_free_context(HapContext *ctx);
  86. /* The first three bytes are the size of the section past the header, or zero
  87. * if the length is stored in the next long word. The fourth byte in the first
  88. * long word indicates the type of the current section. */
  89. int ff_hap_parse_section_header(GetByteContext *gbc, int *section_size,
  90. enum HapSectionType *section_type);
  91. #endif /* AVCODEC_HAP_H */