You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.9KB

  1. /*
  2. * Copyright (c) 2012 Konstantin Shishkov
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * Libav is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * Common header for Microsoft Screen 1 and 2
  23. */
  24. #ifndef AVCODEC_MSS12_H
  25. #define AVCODEC_MSS12_H
  26. #include "libavutil/intreadwrite.h"
  27. #include "avcodec.h"
  28. #include "get_bits.h"
  29. #include "bytestream.h"
  30. #define MODEL_MIN_SYMS 2
  31. #define MODEL_MAX_SYMS 256
  32. #define THRESH_ADAPTIVE -1
  33. #define THRESH_LOW 15
  34. #define THRESH_HIGH 50
  35. typedef struct Model {
  36. int16_t cum_prob[MODEL_MAX_SYMS + 1];
  37. int16_t weights[MODEL_MAX_SYMS + 1];
  38. uint8_t idx2sym[MODEL_MAX_SYMS + 1];
  39. int num_syms;
  40. int thr_weight, threshold;
  41. } Model;
  42. typedef struct ArithCoder {
  43. int low, high, value;
  44. union {
  45. GetBitContext *gb;
  46. GetByteContext *gB;
  47. } gbc;
  48. int (*get_model_sym)(struct ArithCoder *c, Model *m);
  49. int (*get_number) (struct ArithCoder *c, int n);
  50. } ArithCoder;
  51. typedef struct PixContext {
  52. int cache_size, num_syms;
  53. uint8_t cache[12];
  54. Model cache_model, full_model;
  55. Model sec_models[15][4];
  56. int special_initial_cache;
  57. } PixContext;
  58. struct MSS12Context;
  59. typedef struct SliceContext {
  60. struct MSS12Context *c;
  61. Model intra_region, inter_region;
  62. Model pivot, edge_mode, split_mode;
  63. PixContext intra_pix_ctx, inter_pix_ctx;
  64. } SliceContext;
  65. typedef struct MSS12Context {
  66. AVCodecContext *avctx;
  67. uint32_t pal[256];
  68. uint8_t *pal_pic;
  69. uint8_t *last_pal_pic;
  70. ptrdiff_t pal_stride;
  71. uint8_t *mask;
  72. ptrdiff_t mask_stride;
  73. uint8_t *rgb_pic;
  74. uint8_t *last_rgb_pic;
  75. ptrdiff_t rgb_stride;
  76. int free_colours;
  77. int keyframe;
  78. int mvX, mvY;
  79. int corrupted;
  80. int slice_split;
  81. int full_model_syms;
  82. } MSS12Context;
  83. int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
  84. int x, int y, int width, int height);
  85. void ff_mss12_model_update(Model *m, int val);
  86. void ff_mss12_slicecontext_reset(SliceContext *sc);
  87. int ff_mss12_decode_init(MSS12Context *c, int version,
  88. SliceContext *sc1, SliceContext *sc2);
  89. int ff_mss12_decode_end(MSS12Context *ctx);
  90. #define ARITH_GET_BIT(VERSION) \
  91. static int arith ## VERSION ## _get_bit(ArithCoder *c) \
  92. { \
  93. int range = c->high - c->low + 1; \
  94. int bit = 2 * c->value - c->low >= c->high; \
  95. \
  96. if (bit) \
  97. c->low += range >> 1; \
  98. else \
  99. c->high = c->low + (range >> 1) - 1; \
  100. \
  101. arith ## VERSION ## _normalise(c); \
  102. \
  103. return bit; \
  104. }
  105. #define ARITH_GET_MODEL_SYM(VERSION) \
  106. static int arith ## VERSION ## _get_model_sym(ArithCoder *c, Model *m) \
  107. { \
  108. int idx, val; \
  109. \
  110. idx = arith ## VERSION ## _get_prob(c, m->cum_prob); \
  111. \
  112. val = m->idx2sym[idx]; \
  113. ff_mss12_model_update(m, idx); \
  114. \
  115. arith ## VERSION ## _normalise(c); \
  116. \
  117. return val; \
  118. }
  119. #endif /* AVCODEC_MSS12_H */