32 #define HEADER_SIZE 27
34 #define MODEL2_SCALE 13
35 #define MODEL_SCALE 15
36 #define MODEL256_SEC_SCALE 9
44 typedef struct Model {
59 #define RAC_BOTTOM 0x01000000
181 m->
freqs[i] = sum * scale >> 16;
196 for (i = 0; i < m->
num_syms - 1; i++)
229 for (i = 0; i < 256; i++) {
236 for (i = 0; i < 256; i++) {
237 m->
freqs[i] = sum * scale >> 16;
243 while (sidx < m->sec_size)
256 for (i = 0; i < 255; i++)
283 for (i = 0; i <
FFMIN(size, 4); i++)
285 c->
range = 0xFFFFFFFF;
296 }
else if (!c->
low) {
340 bit = (c->
low >= helper);
358 int prob, prob2, helper, val;
369 if (helper <= c->low) {
376 end = (end2 + val) >> 1;
377 }
while (end != val);
379 c->
range = prob2 - prob;
390 int prob, prob2, helper, val;
401 end = start = m->
secondary[ssym + 1] + 1;
402 while (end > val + 1) {
403 ssym = (end + val) >> 1;
404 if (m->
freqs[ssym] <= helper) {
408 end = (end + val) >> 1;
417 c->
range = prob2 - prob;
458 for (i = 0; i < block_size; i++, dst +=
stride)
459 memset(dst, fc->
fill_val, block_size);
472 for (i = 0; i < vec_size; i++)
476 memset(prev_line, 0,
sizeof(prev_line));
478 for (j = 0; j < block_size; j++) {
481 for (i = 0; i < block_size; i++) {
499 int skip, val, sign, pos = 1, zz_pos, dc;
502 memset(block, 0,
sizeof(*block) * 64);
524 block[0] = dc * bc->
qmat[0];
551 block[zz_pos] = val * bc->
qmat[zz_pos];
555 return pos == 64 ? 0 : -1;
560 int *
block,
int mb_x,
int mb_y)
564 int nblocks = block_size >> 3;
569 for (j = 0; j < nblocks; j++) {
570 for (i = 0; i < nblocks; i++) {
571 if (
decode_dct(c, bc, block, bx + i, by + j)) {
585 const int hsize = block_size >> 1;
589 for (j = 0; j < block_size; j++) {
590 for (i = 0; i < block_size; i++) {
591 if (i < hsize && j < hsize)
595 block[i] *= hc->
scale;
599 block -= block_size * block_size;
601 for (j = 0; j < hsize; j++) {
602 for (i = 0; i < hsize; i++) {
604 B = block[i + hsize];
605 C = block[i + hsize * block_size];
606 D = block[i + hsize * block_size + hsize];
612 dst[i * 2] = av_clip_uint8(t1 - t2);
613 dst[i * 2 +
stride] = av_clip_uint8(t1 + t2);
614 dst[i * 2 + 1] = av_clip_uint8(t3 - t4);
615 dst[i * 2 + 1 +
stride] = av_clip_uint8(t3 + t4);
626 for (i = 0; i < 3; i++) {
628 for (j = 0; j < 5; j++)
635 for (j = 0; j < 125; j++)
661 for (i = 0; i < 3; i++) {
662 for (j = 0; j < 5; j++)
668 for (j = 0; j < 125; j++)
681 int buf_size = avpkt->
size;
686 int dec_width, dec_height, dec_x, dec_y, quality, keyframe;
687 int x, y, i, mb_width, mb_height, blk_size, btype;
692 "Frame should have at least %d bytes, got %d instead\n",
698 keyframe = bytestream2_get_be32(&gb);
699 if (keyframe & ~0x301) {
703 keyframe = !(keyframe & 1);
705 dec_x = bytestream2_get_be16(&gb);
706 dec_y = bytestream2_get_be16(&gb);
707 dec_width = bytestream2_get_be16(&gb);
708 dec_height = bytestream2_get_be16(&gb);
710 if (dec_x + dec_width > avctx->
width ||
711 dec_y + dec_height > avctx->
height ||
712 (dec_width | dec_height) & 0xF) {
714 dec_width, dec_height, dec_x, dec_y);
718 quality = bytestream2_get_byte(&gb);
719 if (quality < 1 || quality > 100) {
753 mb_width = dec_width >> 4;
754 mb_height = dec_height >> 4;
758 for (y = 0; y < mb_height; y++) {
759 for (x = 0; x < mb_width; x++) {
760 for (i = 0; i < 3; i++) {
767 dst[i] + x * blk_size,
772 dst[i] + x * blk_size,
777 dst[i] + x * blk_size,
783 dst[i] + x * blk_size,
814 if ((avctx->
width & 0xF) || (avctx->
height & 0xF)) {
816 "Image dimensions should be a multiple of 16.\n");
821 for (i = 0; i < 3; i++) {
822 int b_width = avctx->
width >> (2 + !!i);
823 int b_height = avctx->
height >> (2 + !!i);
853 for (i = 0; i < 3; i++)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
Generate quantisation matrix for given quality.
const uint8_t ff_zigzag_direct[64]
static int decode_block_type(RangeCoder *c, BlockTypeContext *bt)
This structure describes decoded (raw) audio or video data.
struct BlockTypeContext BlockTypeContext
struct MSS3Context MSS3Context
#define MODEL256_SEC_SCALE
static void decode_haar_block(RangeCoder *c, HaarBlockCoder *hc, uint8_t *dst, int stride, int block_size, int *block)
static void model2_reset(Model2 *m)
int buffer_hints
codec suggestion on buffer type if != 0
struct RangeCoder RangeCoder
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
AVFrame * coded_frame
the picture in the bitstream
void ff_mss34_dct_put(uint8_t *dst, int stride, int *block)
Transform and output DCT block.
ImageBlockCoder image_coder[3]
struct FillBlockCoder FillBlockCoder
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
int16_t weights[MODEL_MAX_SYMS+1]
static int mss3_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int(* reget_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of a frame to get cr buffer for it.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
static void decode_fill_block(RangeCoder *c, FillBlockCoder *fc, uint8_t *dst, int stride, int block_size)
static void rac_normalise(RangeCoder *c)
static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block, int bx, int by)
static void reset_coders(MSS3Context *ctx, int quality)
static void rac_init(RangeCoder *c, const uint8_t *src, int size)
static void model256_update(Model256 *m, int val)
static int init(AVCodecParserContext *s)
static av_cold void model_init(Model *m, int num_syms)
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
DCTBlockCoder dct_coder[3]
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
struct HaarBlockCoder HaarBlockCoder
static av_cold void model256_init(Model256 *m)
HaarBlockCoder haar_coder[3]
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
static av_cold int mss3_decode_init(AVCodecContext *avctx)
int width
picture width / height.
static int rac_get_bits(RangeCoder *c, int nbits)
struct DCTBlockCoder DCTBlockCoder
static void model_reset(Model *m)
static int rac_get_model256_sym(RangeCoder *c, Model256 *m)
static int rac_get_model_sym(RangeCoder *c, Model *m)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
static void model_update(Model *m, int val)
static av_cold void init_coders(MSS3Context *ctx)
static int rac_get_bit(RangeCoder *c)
static void model256_reset(Model256 *m)
static void decode_image_block(RangeCoder *c, ImageBlockCoder *ic, uint8_t *dst, int stride, int block_size)
#define FF_BUFFER_HINTS_REUSABLE
FillBlockCoder fill_coder[3]
static av_cold int mss3_decode_end(AVCodecContext *avctx)
struct ImageBlockCoder ImageBlockCoder
static const uint16_t scale[4]
#define FF_BUFFER_HINTS_PRESERVE
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void model2_update(Model2 *m, int bit)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
static int decode_coeff(RangeCoder *c, Model *m)
#define AVERROR_INVALIDDATA
int key_frame
1 -> keyframe, 0-> not
#define FF_BUFFER_HINTS_VALID
BlockTypeContext btype[3]
static int rac_get_model2_sym(RangeCoder *c, Model2 *m)
This structure stores compressed data.
static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc, uint8_t *dst, int stride, int block_size, int *block, int mb_x, int mb_y)