mss12.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2012 Konstantin Shishkov
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; 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. int overread;
  45. #define MAX_OVERREAD 16
  46. union {
  47. GetBitContext *gb;
  48. GetByteContext *gB;
  49. } gbc;
  50. int (*get_model_sym)(struct ArithCoder *c, Model *m);
  51. int (*get_number) (struct ArithCoder *c, int n);
  52. } ArithCoder;
  53. typedef struct PixContext {
  54. int cache_size, num_syms;
  55. uint8_t cache[12];
  56. Model cache_model, full_model;
  57. Model sec_models[15][4];
  58. int special_initial_cache;
  59. } PixContext;
  60. struct MSS12Context;
  61. typedef struct SliceContext {
  62. struct MSS12Context *c;
  63. Model intra_region, inter_region;
  64. Model pivot, edge_mode, split_mode;
  65. PixContext intra_pix_ctx, inter_pix_ctx;
  66. } SliceContext;
  67. typedef struct MSS12Context {
  68. AVCodecContext *avctx;
  69. uint32_t pal[256];
  70. uint8_t *pal_pic;
  71. uint8_t *last_pal_pic;
  72. ptrdiff_t pal_stride;
  73. uint8_t *mask;
  74. ptrdiff_t mask_stride;
  75. uint8_t *rgb_pic;
  76. uint8_t *last_rgb_pic;
  77. ptrdiff_t rgb_stride;
  78. int free_colours;
  79. int keyframe;
  80. int mvX, mvY;
  81. int corrupted;
  82. int slice_split;
  83. int full_model_syms;
  84. } MSS12Context;
  85. int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
  86. int x, int y, int width, int height);
  87. void ff_mss12_model_update(Model *m, int val);
  88. void ff_mss12_slicecontext_reset(SliceContext *sc);
  89. int ff_mss12_decode_init(MSS12Context *c, int version,
  90. SliceContext *sc1, SliceContext *sc2);
  91. int ff_mss12_decode_end(MSS12Context *ctx);
  92. #define ARITH_GET_BIT(prefix) \
  93. static int prefix ## _get_bit(ArithCoder *c) \
  94. { \
  95. int range = c->high - c->low + 1; \
  96. int bit = 2 * c->value - c->low >= c->high; \
  97. \
  98. if (bit) \
  99. c->low += range >> 1; \
  100. else \
  101. c->high = c->low + (range >> 1) - 1; \
  102. \
  103. prefix ## _normalise(c); \
  104. \
  105. return bit; \
  106. }
  107. #define ARITH_GET_MODEL_SYM(prefix) \
  108. static int prefix ## _get_model_sym(ArithCoder *c, Model *m) \
  109. { \
  110. int idx, val; \
  111. \
  112. idx = prefix ## _get_prob(c, m->cum_prob); \
  113. \
  114. val = m->idx2sym[idx]; \
  115. ff_mss12_model_update(m, idx); \
  116. \
  117. prefix ## _normalise(c); \
  118. \
  119. return val; \
  120. }
  121. #endif /* AVCODEC_MSS12_H */