FFmpeg
Data Structures | Macros | Functions | Variables
4xm.c File Reference
#include <inttypes.h>
#include "libavutil/avassert.h"
#include "libavutil/frame.h"
#include "libavutil/imgutils.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "avcodec.h"
#include "blockdsp.h"
#include "bswapdsp.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"

Go to the source code of this file.

Data Structures

struct  CFrameBuffer
 
struct  FourXContext
 

Macros

#define BLOCK_TYPE_VLC_BITS   5
 
#define ACDC_VLC_BITS   9
 
#define CFRAME_BUFFER_COUNT   100
 
#define FIX_1_082392200   70936
 
#define FIX_1_414213562   92682
 
#define FIX_1_847759065   121095
 
#define FIX_2_613125930   171254
 
#define MULTIPLY(var, const)   ((int)((var) * (unsigned)(const)) >> 16)
 
#define LE_CENTRIC_MUL(dst, src, scale, dc)
 

Functions

static void idct (int16_t block[64])
 
static av_cold void init_vlcs (void)
 
static void init_mv (FourXContext *f, int linesize)
 
static void mcdc (uint16_t *dst, const uint16_t *src, int log2w, int h, int stride, int scale, unsigned dc)
 
static int decode_p_block (FourXContext *f, uint16_t *dst, const uint16_t *src, int log2w, int log2h, int stride)
 
static int decode_p_frame (FourXContext *f, const uint8_t *buf, int length)
 
static int decode_i_block (FourXContext *f, int16_t *block)
 decode block and dequantize. More...
 
static void idct_put (FourXContext *f, int x, int y)
 
static int decode_i_mb (FourXContext *f)
 
static const uint8_t * read_huffman_tables (FourXContext *f, const uint8_t *const buf, int buf_size)
 
static int mix (int c0, int c1)
 
static int decode_i2_frame (FourXContext *f, const uint8_t *buf, int length)
 
static int decode_i_frame (FourXContext *f, const uint8_t *buf, int length)
 
static int decode_frame (AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
 
static av_cold int decode_end (AVCodecContext *avctx)
 
static av_cold int decode_init (AVCodecContext *avctx)
 

Variables

static const uint8_t block_type_tab [2][4][8][2]
 
static const uint8_t size2index [4][4]
 
static const int8_t mv [256][2]
 
static const uint8_t dequant_table [64]
 
static VLC block_type_vlc [2][4]
 
const FFCodec ff_fourxm_decoder
 

Detailed Description

4XM codec.

Definition in file 4xm.c.

Macro Definition Documentation

◆ BLOCK_TYPE_VLC_BITS

#define BLOCK_TYPE_VLC_BITS   5

Definition at line 44 of file 4xm.c.

◆ ACDC_VLC_BITS

#define ACDC_VLC_BITS   9

Definition at line 45 of file 4xm.c.

◆ CFRAME_BUFFER_COUNT

#define CFRAME_BUFFER_COUNT   100

Definition at line 47 of file 4xm.c.

◆ FIX_1_082392200

#define FIX_1_082392200   70936

Definition at line 159 of file 4xm.c.

◆ FIX_1_414213562

#define FIX_1_414213562   92682

Definition at line 160 of file 4xm.c.

◆ FIX_1_847759065

#define FIX_1_847759065   121095

Definition at line 161 of file 4xm.c.

◆ FIX_2_613125930

#define FIX_2_613125930   171254

Definition at line 162 of file 4xm.c.

◆ MULTIPLY

#define MULTIPLY (   var,
  const 
)    ((int)((var) * (unsigned)(const)) >> 16)

Definition at line 164 of file 4xm.c.

◆ LE_CENTRIC_MUL

#define LE_CENTRIC_MUL (   dst,
  src,
  scale,
  dc 
)
Value:
{ \
unsigned tmpval = AV_RN32(src) * (scale) + (dc); \
AV_WN32A(dst, tmpval); \
}

Definition at line 290 of file 4xm.c.

Function Documentation

◆ idct()

static void idct ( int16_t  block[64])
static

◆ init_vlcs()

static av_cold void init_vlcs ( void  )
static

Definition at line 251 of file 4xm.c.

Referenced by decode_init().

◆ init_mv()

static void init_mv ( FourXContext f,
int  linesize 
)
static

Definition at line 268 of file 4xm.c.

Referenced by decode_p_frame().

◆ mcdc()

static void mcdc ( uint16_t *  dst,
const uint16_t *  src,
int  log2w,
int  h,
int  stride,
int  scale,
unsigned  dc 
)
inlinestatic

Definition at line 297 of file 4xm.c.

Referenced by decode_p_block().

◆ decode_p_block()

static int decode_p_block ( FourXContext f,
uint16_t *  dst,
const uint16_t *  src,
int  log2w,
int  log2h,
int  stride 
)
static

Definition at line 345 of file 4xm.c.

Referenced by decode_p_frame().

◆ decode_p_frame()

static int decode_p_frame ( FourXContext f,
const uint8_t *  buf,
int  length 
)
static

Definition at line 432 of file 4xm.c.

Referenced by decode_frame().

◆ decode_i_block()

static int decode_i_block ( FourXContext f,
int16_t *  block 
)
static

decode block and dequantize.

Note this is almost identical to MJPEG.

Definition at line 500 of file 4xm.c.

Referenced by decode_i_mb().

◆ idct_put()

static void idct_put ( FourXContext f,
int  x,
int  y 
)
inlinestatic

Definition at line 559 of file 4xm.c.

Referenced by decode_i_frame(), and dv_decode_video_segment().

◆ decode_i_mb()

static int decode_i_mb ( FourXContext f)
static

Definition at line 605 of file 4xm.c.

Referenced by decode_i_frame().

◆ read_huffman_tables()

static const uint8_t* read_huffman_tables ( FourXContext f,
const uint8_t *const  buf,
int  buf_size 
)
static

Definition at line 619 of file 4xm.c.

Referenced by decode_i_frame().

◆ mix()

static int mix ( int  c0,
int  c1 
)
static

◆ decode_i2_frame()

static int decode_i2_frame ( FourXContext f,
const uint8_t *  buf,
int  length 
)
static

Definition at line 725 of file 4xm.c.

Referenced by decode_frame().

◆ decode_i_frame()

static int decode_i_frame ( FourXContext f,
const uint8_t *  buf,
int  length 
)
static

Definition at line 773 of file 4xm.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
AVFrame picture,
int got_frame,
AVPacket avpkt 
)
static

Definition at line 837 of file 4xm.c.

◆ decode_end()

static av_cold int decode_end ( AVCodecContext avctx)
static

Definition at line 972 of file 4xm.c.

◆ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Definition at line 990 of file 4xm.c.

Variable Documentation

◆ block_type_tab

const uint8_t block_type_tab[2][4][8][2]
static
Initial value:
= {
{
{
{ 0, 1 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 30, 5 }, { 31, 5 }, { 0, 0 }
}, {
{ 0, 1 }, { 0, 0 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 15, 4 }, { 0, 0 }
}, {
{ 0, 1 }, { 2, 2 }, { 0, 0 }, { 6, 3 }, { 14, 4 }, { 15, 4 }, { 0, 0 }
}, {
{ 0, 1 }, { 0, 0 }, { 0, 0 }, { 2, 2 }, { 6, 3 }, { 14, 4 }, { 15, 4 }
}
}, {
{
{ 1, 2 }, { 4, 3 }, { 5, 3 }, { 0, 2 }, { 6, 3 }, { 7, 3 }, { 0, 0 }
}, {
{ 1, 2 }, { 0, 0 }, { 2, 2 }, { 0, 2 }, { 6, 3 }, { 7, 3 }, { 0, 0 }
}, {
{ 1, 2 }, { 2, 2 }, { 0, 0 }, { 0, 2 }, { 6, 3 }, { 7, 3 }, { 0, 0 }
}, {
{ 1, 2 }, { 0, 0 }, { 0, 0 }, { 0, 2 }, { 2, 2 }, { 6, 3 }, { 7, 3 }
}
}
}

Definition at line 49 of file 4xm.c.

Referenced by init_vlcs().

◆ size2index

const uint8_t size2index[4][4]
static
Initial value:
= {
{ -1, 3, 1, 1 },
{ 3, 0, 0, 0 },
{ 2, 0, 0, 0 },
{ 2, 0, 0, 0 },
}

Definition at line 73 of file 4xm.c.

Referenced by decode_p_block().

◆ mv

const int8_t mv[256][2]
static
Examples
extract_mvs.c.

Definition at line 80 of file 4xm.c.

Referenced by add_mv_data(), apply_obmc(), chroma_mc_uni(), clv_decode_frame(), compare_mv_ref_idx(), decode_13(), decode_inter(), decode_mode(), decode_packet(), decode_tile(), derive_spatial_merge_candidates(), dist_scale(), dwt_decode53(), dwt_decode97_float(), dwt_decode97_int(), dwt_encode53(), dwt_encode97_float(), dwt_encode97_int(), encode_frame(), fetch_diagonal_mv(), ff_hevc_luma_mv_merge_mode(), ff_hevc_luma_mv_mvp_mode(), ff_me_search_ds(), ff_me_search_epzs(), ff_me_search_fss(), ff_me_search_hexbs(), ff_me_search_ntss(), ff_me_search_tdls(), ff_me_search_tss(), ff_me_search_umh(), ff_msmpeg4_decode_motion(), ff_msmpeg4_encode_motion(), ff_vp9_fill_mv(), fill_decode_caches(), filter_frame(), find_block_motion(), find_motion(), find_ref_mvs(), h263_get_modb(), h264_er_decode_mb(), hevc_await_progress(), hevc_luma_mv_mvp_mode(), init_mv(), init_mv_penalty_and_fcode(), ivi_scale_mv(), luma_mc_uni(), mc_chroma_scaled(), mc_chroma_unscaled(), mc_dir_part(), mc_luma_scaled(), mc_luma_unscaled(), mc_part_std(), mpeg_er_decode_mb(), msmpeg4_decode_init_static(), mv_mp_mode_mx(), mv_mp_mode_mx_lt(), mv_read_header(), mv_read_packet(), mv_read_seek(), mvi_update_prediction(), obmc_motion(), parse_audio_var(), parse_global_var(), pred_pskip_motion(), pred_spatial_direct_motion(), predict_motion(), search_mv(), set_mvs(), svq1_decode_motion_vector(), svq1_motion_inter_4v_block(), svq1_motion_inter_block(), svq3_mc_dir(), var_size_bme(), vc1_p_h_loop_filter(), vc1_p_v_loop_filter(), vp56_conceal_mv(), vp56_decode_4mv(), vp56_decode_mv(), vp6_filter(), vp7_decode_mvs(), vp8_mc_chroma(), vp8_mc_luma(), and vp8_mc_part().

◆ dequant_table

const uint8_t dequant_table[64]
static
Initial value:
= {
16, 15, 13, 19, 24, 31, 28, 17,
17, 23, 25, 31, 36, 63, 45, 21,
18, 24, 27, 37, 52, 59, 49, 20,
16, 28, 34, 40, 60, 80, 51, 20,
18, 31, 48, 66, 68, 86, 56, 21,
19, 38, 56, 59, 64, 64, 48, 20,
27, 48, 55, 55, 56, 51, 35, 15,
20, 35, 34, 32, 31, 22, 15, 8,
}

Definition at line 117 of file 4xm.c.

Referenced by decode_i_block(), and fill_tone_level_array().

◆ block_type_vlc

VLC block_type_vlc[2][4]
static

Definition at line 128 of file 4xm.c.

Referenced by decode_p_block(), and init_vlcs().

◆ ff_fourxm_decoder

const FFCodec ff_fourxm_decoder
Initial value:
= {
.p.name = "4xm",
CODEC_LONG_NAME("4X Movie"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_4XM,
.priv_data_size = sizeof(FourXContext),
.close = decode_end,
.p.capabilities = AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 1029 of file 4xm.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition: 4xm.c:837
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
AV_CODEC_ID_4XM
@ AV_CODEC_ID_4XM
Definition: codec_id.h:86
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_RN32
#define AV_RN32(p)
Definition: intreadwrite.h:364
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
dc
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff) *mv_scale Intra DC Prediction block[y][x] dc[1]
Definition: snow.txt:400
FourXContext
Definition: 4xm.c:138
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: 4xm.c:990
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
decode_end
static av_cold int decode_end(AVCodecContext *avctx)
Definition: 4xm.c:972
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418