37#define MODEL2_SCALE 13
39#define MODEL256_SEC_SCALE 9
62#define RAC_BOTTOM 0x01000000
232 for (
i = 0;
i < 256;
i++) {
239 for (
i = 0;
i < 256;
i++) {
246 while (sidx < m->sec_size)
259 for (
i = 0;
i < 255;
i++)
287 c->low = (
c->low << 8) | *
c->src++;
288 c->range = 0xFFFFFFFF;
297 if (
c->src <
c->src_end) {
299 }
else if (!
c->low) {
303 if (
c->low >
c->range) {
318 bit = (
c->range <=
c->low);
333 val =
c->low /
c->range;
334 c->low -=
c->range *
val;
347 bit = (
c->low >= helper);
367 unsigned prob, prob2, helper;
376 helper = m->
freqs[end] *
c->range;
377 if (helper <= c->low) {
384 end = (end2 +
val) >> 1;
385 }
while (end !=
val);
387 c->range = prob2 -
prob;
401 unsigned prob, prob2, helper;
406 helper =
c->low /
c->range;
410 end = start = m->
secondary[ssym + 1] + 1;
411 while (end >
val + 1) {
412 ssym = (end +
val) >> 1;
413 if (m->
freqs[ssym] <= helper) {
417 end = (end +
val) >> 1;
426 c->range = prob2 -
prob;
461 uint8_t *
dst, ptrdiff_t
stride,
int block_size)
468 memset(
dst,
fc->fill_val, block_size);
472 uint8_t *
dst, ptrdiff_t
stride,
int block_size)
481 for (
i = 0;
i < vec_size;
i++)
485 memset(prev_line, 0,
sizeof(prev_line));
487 for (j = 0; j < block_size; j++) {
490 for (
i = 0;
i < block_size;
i++) {
564 return pos == 64 ? 0 : -1;
568 uint8_t *
dst, ptrdiff_t
stride,
int block_size,
569 int *
block,
int mb_x,
int mb_y)
573 int nblocks = block_size >> 3;
578 for (j = 0; j < nblocks; j++) {
579 for (
i = 0;
i < nblocks;
i++) {
592 int block_size,
int *
block)
594 const int hsize = block_size >> 1;
595 int A,
B,
C,
D, t1, t2, t3, t4;
598 for (j = 0; j < block_size; j++) {
599 for (
i = 0;
i < block_size;
i++) {
600 if (
i < hsize && j < hsize)
608 block -= block_size * block_size;
610 for (j = 0; j < hsize; j++) {
611 for (
i = 0;
i < hsize;
i++) {
614 C =
block[
i + hsize * block_size];
615 D =
block[
i + hsize * block_size + hsize];
635 for (
i = 0;
i < 3;
i++) {
637 for (j = 0; j < 5; j++)
639 ctx->fill_coder[
i].fill_val = 0;
644 for (j = 0; j < 125; j++)
650 memset(
ctx->dct_coder[
i].prev_dc, 0,
651 sizeof(*
ctx->dct_coder[
i].prev_dc) *
652 ctx->dct_coder[
i].prev_dc_stride *
653 ctx->dct_coder[
i].prev_dc_height);
670 for (
i = 0;
i < 3;
i++) {
671 for (j = 0; j < 5; j++)
677 for (j = 0; j < 125; j++)
689 const uint8_t *buf = avpkt->
data;
690 int buf_size = avpkt->
size;
695 int dec_width, dec_height, dec_x, dec_y,
quality, keyframe;
696 int x, y,
i, mb_width, mb_height, blk_size, btype;
701 "Frame should have at least %d bytes, got %d instead\n",
707 keyframe = bytestream2_get_be32(&gb);
708 if (keyframe & ~0x301) {
712 keyframe = !(keyframe & 1);
714 dec_x = bytestream2_get_be16(&gb);
715 dec_y = bytestream2_get_be16(&gb);
716 dec_width = bytestream2_get_be16(&gb);
717 dec_height = bytestream2_get_be16(&gb);
719 if (dec_x + dec_width > avctx->
width ||
720 dec_y + dec_height > avctx->
height ||
721 (dec_width | dec_height) & 0xF) {
723 dec_width, dec_height, dec_x, dec_y);
727 quality = bytestream2_get_byte(&gb);
738 if (!keyframe &&
c->got_error)
761 mb_width = dec_width >> 4;
762 mb_height = dec_height >> 4;
763 dst[0] =
c->pic->data[0] + dec_x + dec_y *
c->pic->linesize[0];
764 dst[1] =
c->pic->data[1] + dec_x / 2 + (dec_y / 2) *
c->pic->linesize[1];
765 dst[2] =
c->pic->data[2] + dec_x / 2 + (dec_y / 2) *
c->pic->linesize[2];
766 for (y = 0; y < mb_height; y++) {
767 for (x = 0; x < mb_width; x++) {
768 for (
i = 0;
i < 3;
i++) {
775 dst[
i] + x * blk_size,
776 c->pic->linesize[
i], blk_size);
780 dst[
i] + x * blk_size,
781 c->pic->linesize[
i], blk_size);
785 dst[
i] + x * blk_size,
786 c->pic->linesize[
i], blk_size,
791 dst[
i] + x * blk_size,
792 c->pic->linesize[
i], blk_size,
804 dst[0] +=
c->pic->linesize[0] * 16;
805 dst[1] +=
c->pic->linesize[1] * 8;
806 dst[2] +=
c->pic->linesize[2] * 8;
823 for (
i = 0;
i < 3;
i++)
836 if ((avctx->
width & 0xF) || (avctx->
height & 0xF)) {
838 "Image dimensions should be a multiple of 16.\n");
843 for (
i = 0;
i < 3;
i++) {
844 int b_width = avctx->
width >> (2 + !!
i);
845 int b_height = avctx->
height >> (2 + !!
i);
846 c->dct_coder[
i].prev_dc_stride = b_width;
847 c->dct_coder[
i].prev_dc_height = b_height;
848 c->dct_coder[
i].prev_dc =
av_malloc(
sizeof(*
c->dct_coder[
i].prev_dc) *
850 if (!
c->dct_coder[
i].prev_dc) {
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_msa1_decoder
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define i(width, name, range_min, range_max)
#define bit(string, value)
#define prob(name, subs,...)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static const uint16_t fc[]
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Identical in function to ff_get_buffer(), except it reuses the existing buffer if available.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
@ AV_PICTURE_TYPE_I
Intra.
@ AV_PICTURE_TYPE_P
Predicted.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
@ SKIP_BLOCK
skipped block
@ FILL_BLOCK
block is filled with single colour
const uint8_t ff_zigzag_direct[64]
Memory handling functions.
void ff_mss34_dct_put(uint8_t *dst, ptrdiff_t stride, int *block)
Transform and output DCT block.
void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
Generate quantisation matrix for given quality.
static void model_reset(Model *m)
static void model256_reset(Model256 *m)
static int mss3_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
static void decode_image_block(RangeCoder *c, ImageBlockCoder *ic, uint8_t *dst, ptrdiff_t stride, int block_size)
#define MODEL256_SEC_SCALE
static void model2_reset(Model2 *m)
static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block, int bx, int by)
static int rac_get_bits(RangeCoder *c, int nbits)
static void decode_haar_block(RangeCoder *c, HaarBlockCoder *hc, uint8_t *dst, ptrdiff_t stride, int block_size, int *block)
static void decode_fill_block(RangeCoder *c, FillBlockCoder *fc, uint8_t *dst, ptrdiff_t stride, int block_size)
static int rac_get_model256_sym(RangeCoder *c, Model256 *m)
static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc, uint8_t *dst, ptrdiff_t stride, int block_size, int *block, int mb_x, int mb_y)
static void model256_update(Model256 *m, int val)
static int rac_get_bit(RangeCoder *c)
static int rac_get_model_sym(RangeCoder *c, Model *m)
static av_cold int mss3_decode_end(AVCodecContext *avctx)
static void rac_normalise(RangeCoder *c)
static av_cold void init_coders(MSS3Context *ctx)
static int rac_get_model2_sym(RangeCoder *c, Model2 *m)
static void model2_update(Model2 *m, int bit)
static av_cold void model_init(Model *m, int num_syms)
static void model_update(Model *m, int val)
static av_cold void model256_init(Model256 *m)
static av_cold int mss3_decode_init(AVCodecContext *avctx)
static void rac_init(RangeCoder *c, const uint8_t *src, int size)
static int decode_coeff(RangeCoder *c, Model *m)
static int decode_block_type(RangeCoder *c, BlockTypeContext *bt)
static void reset_coders(MSS3Context *ctx, int quality)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
DCTBlockCoder dct_coder[3]
FillBlockCoder fill_coder[3]
HaarBlockCoder haar_coder[3]
ImageBlockCoder image_coder[3]
BlockTypeContext btype[3]
int16_t weights[MODEL_MAX_SYMS+1]
static const uint8_t quality[]