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.

138 lines
5.0KB

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