godot/thirdparty/libtheora/state.h

/********************************************************************
 *                                                                  *
 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
 *                                                                  *
 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009                *
 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
 *                                                                  *
 ********************************************************************

  function:
    last mod: $Id: internal.h 17337 2010-07-19 16:08:54Z tterribe $

 ********************************************************************/
#if !defined(_state_H)
#define _state_H
# include "internal.h"
# include "huffman.h"
# include "quant.h"



/*A single quadrant of the map from a super block to fragment numbers.*/
oc_sb_map_quad;
/*A map from a super block to fragment numbers.*/
oc_sb_map;
/*A single plane of the map from a macro block to fragment numbers.*/
oc_mb_map_plane;
/*A map from a macro block to fragment numbers.*/
oc_mb_map;
/*A motion vector.*/
oc_mv;

oc_sb_flags;
oc_border_info;
oc_fragment;
oc_fragment_plane;
oc_base_opt_vtable;
oc_base_opt_data;
oc_state_dispatch_vtable;
oc_theora_state;



/*Shared accelerated functions.*/
# if defined(OC_X86_ASM)
#  if defined(_MSC_VER)
#   include "x86_vc/x86int.h"
#  else
#   include "x86/x86int.h"
#  endif
# endif
# if defined(OC_ARM_ASM)
#  include "arm/armint.h"
# endif
# if defined(OC_C64X_ASM)
#  include "c64x/c64xint.h"
# endif

# if !defined(oc_state_accel_init)
#define oc_state_accel_init
# endif
# if defined(OC_STATE_USE_VTABLE)
#  if !defined(oc_frag_copy)
#define oc_frag_copy(_state,_dst,_src,_ystride)
#  endif
#  if !defined(oc_frag_copy_list)
#define oc_frag_copy_list(_state,_dst_frame,_src_frame,_ystride, \
 _fragis,_nfragis,_frag_buf_offs)
#  endif
#  if !defined(oc_frag_recon_intra)
#define oc_frag_recon_intra(_state,_dst,_dst_ystride,_residue)
#  endif
#  if !defined(oc_frag_recon_inter)
#define oc_frag_recon_inter(_state,_dst,_src,_ystride,_residue)
#  endif
#  if !defined(oc_frag_recon_inter2)
#define oc_frag_recon_inter2(_state,_dst,_src1,_src2,_ystride,_residue)
#  endif
# if !defined(oc_idct8x8)
#define oc_idct8x8(_state,_y,_x,_last_zzi)
#  endif
#  if !defined(oc_state_frag_recon)
#define oc_state_frag_recon(_state,_fragi, \
 _pli,_dct_coeffs,_last_zzi,_dc_quant)
#  endif
#  if !defined(oc_loop_filter_init)
#define oc_loop_filter_init(_state,_bv,_flimit)
#  endif
#  if !defined(oc_state_loop_filter_frag_rows)
#define oc_state_loop_filter_frag_rows(_state, \
 _bv,_refi,_pli,_fragy0,_fragy_end)
#  endif
#  if !defined(oc_restore_fpu)
#define oc_restore_fpu(_state)
#  endif
# else
#  if !defined(oc_frag_copy)
#define oc_frag_copy
#  endif
#  if !defined(oc_frag_copy_list)
#define oc_frag_copy_list
#  endif
#  if !defined(oc_frag_recon_intra)
#define oc_frag_recon_intra
#  endif
#  if !defined(oc_frag_recon_inter)
#define oc_frag_recon_inter
#  endif
#  if !defined(oc_frag_recon_inter2)
#define oc_frag_recon_inter2
#  endif
#  if !defined(oc_idct8x8)
#define oc_idct8x8
#  endif
#  if !defined(oc_state_frag_recon)
#define oc_state_frag_recon
#  endif
#  if !defined(oc_loop_filter_init)
#define oc_loop_filter_init
#  endif
#  if !defined(oc_state_loop_filter_frag_rows)
#define oc_state_loop_filter_frag_rows
#  endif
#  if !defined(oc_restore_fpu)
#define oc_restore_fpu
#  endif
# endif



/*A keyframe.*/
#define OC_INTRA_FRAME
/*A predicted frame.*/
#define OC_INTER_FRAME
/*A frame of unknown type (frame type decision has not yet been made).*/
#define OC_UNKWN_FRAME

/*The amount of padding to add to the reconstructed frame buffers on all
   sides.
  This is used to allow unrestricted motion vectors without special casing.
  This must be a multiple of 2.*/
#define OC_UMV_PADDING

/*Frame classification indices.*/
/*The previous golden frame.*/
#define OC_FRAME_GOLD
/*The previous frame.*/
#define OC_FRAME_PREV
/*The current frame.*/
#define OC_FRAME_SELF
/*Used to mark uncoded fragments (for DC prediction).*/
#define OC_FRAME_NONE

/*The input or output buffer.*/
#define OC_FRAME_IO
/*Uncompressed prev golden frame.*/
#define OC_FRAME_GOLD_ORIG
/*Uncompressed previous frame. */
#define OC_FRAME_PREV_ORIG

/*Macroblock modes.*/
/*Macro block is invalid: It is never coded.*/
#define OC_MODE_INVALID
/*Encoded difference from the same macro block in the previous frame.*/
#define OC_MODE_INTER_NOMV
/*Encoded with no motion compensated prediction.*/
#define OC_MODE_INTRA
/*Encoded difference from the previous frame offset by the given motion
   vector.*/
#define OC_MODE_INTER_MV
/*Encoded difference from the previous frame offset by the last coded motion
   vector.*/
#define OC_MODE_INTER_MV_LAST
/*Encoded difference from the previous frame offset by the second to last
   coded motion vector.*/
#define OC_MODE_INTER_MV_LAST2
/*Encoded difference from the same macro block in the previous golden
   frame.*/
#define OC_MODE_GOLDEN_NOMV
/*Encoded difference from the previous golden frame offset by the given motion
   vector.*/
#define OC_MODE_GOLDEN_MV
/*Encoded difference from the previous frame offset by the individual motion
   vectors given for each block.*/
#define OC_MODE_INTER_MV_FOUR
/*The number of (coded) modes.*/
#define OC_NMODES

/*Determines the reference frame used for a given MB mode.*/
#define OC_FRAME_FOR_MODE(_x)

/*Constants for the packet state machine common between encoder and decoder.*/

/*Next packet to emit/read: Codec info header.*/
#define OC_PACKET_INFO_HDR
/*Next packet to emit/read: Comment header.*/
#define OC_PACKET_COMMENT_HDR
/*Next packet to emit/read: Codec setup header.*/
#define OC_PACKET_SETUP_HDR
/*No more packets to emit/read.*/
#define OC_PACKET_DONE



#define OC_MV(_x,_y)
#define OC_MV_X(_mv)
#define OC_MV_Y(_mv)
#define OC_MV_ADD(_mv1,_mv2)
#define OC_MV_SUB(_mv1,_mv2)



/*Super blocks are 32x32 segments of pixels in a single color plane indexed
   in image order.
  Internally, super blocks are broken up into four quadrants, each of which
   contains a 2x2 pattern of blocks, each of which is an 8x8 block of pixels.
  Quadrants, and the blocks within them, are indexed in a special order called
   a "Hilbert curve" within the super block.

  In order to differentiate between the Hilbert-curve indexing strategy and
   the regular image order indexing strategy, blocks indexed in image order
   are called "fragments".
  Fragments are indexed in image order, left to right, then bottom to top,
   from Y' plane to Cb plane to Cr plane.

  The co-located fragments in all image planes corresponding to the location
   of a single quadrant of a luma plane super block form a macro block.
  Thus there is only a single set of macro blocks for all planes, each of which
   contains between 6 and 12 fragments, depending on the pixel format.
  Therefore macro block information is kept in a separate set of arrays from
   super blocks to avoid unused space in the other planes.
  The lists are indexed in super block order.
  That is, the macro block corresponding to the macro block mbi in (luma plane)
   super block sbi is at index (sbi<<2|mbi).
  Thus the number of macro blocks in each dimension is always twice the number
   of super blocks, even when only an odd number fall inside the coded frame.
  These "extra" macro blocks are just an artifact of our internal data layout,
   and not part of the coded stream; they are flagged with a negative MB mode.*/



/*Super block information.*/
struct oc_sb_flags{};



/*Information about a fragment which intersects the border of the displayable
   region.
  This marks which pixels belong to the displayable region.*/
struct oc_border_info{};



/*Fragment information.*/
struct oc_fragment{};



/*A description of each fragment plane.*/
struct oc_fragment_plane{};


oc_state_loop_filter_frag_rows_func;

/*The shared (encoder and decoder) functions that have accelerated variants.*/
struct oc_base_opt_vtable{};

/*The shared (encoder and decoder) tables that vary according to which variants
   of the above functions are used.*/
struct oc_base_opt_data{};


/*State information common to both the encoder and decoder.*/
struct oc_theora_state{};



/*The function type used to fill in the chroma plane motion vectors for a
   macro block when 4 different motion vectors are specified in the luma
   plane.
  _cbmvs: The chroma block-level motion vectors to fill in.
  _lmbmv: The luma macro-block level motion vector to fill in for use in
           prediction.
  _lbmvs: The luma block-level motion vectors.*/
oc_set_chroma_mvs_func;



/*A table of functions used to fill in the Cb,Cr plane motion vectors for a
   macro block when 4 different motion vectors are specified in the luma
   plane.*/
extern const oc_set_chroma_mvs_func OC_SET_CHROMA_MVS_TABLE[TH_PF_NFORMATS];



int oc_state_init(oc_theora_state *_state,const th_info *_info,int _nrefs);
void oc_state_clear(oc_theora_state *_state);
void oc_state_accel_init_c(oc_theora_state *_state);
void oc_state_borders_fill_rows(oc_theora_state *_state,int _refi,int _pli,
 int _y0,int _yend);
void oc_state_borders_fill_caps(oc_theora_state *_state,int _refi,int _pli);
void oc_state_borders_fill(oc_theora_state *_state,int _refi);
void oc_state_fill_buffer_ptrs(oc_theora_state *_state,int _buf_idx,
 th_ycbcr_buffer _img);
int oc_state_mbi_for_pos(oc_theora_state *_state,int _mbx,int _mby);
int oc_state_get_mv_offsets(const oc_theora_state *_state,int _offsets[2],
 int _pli,oc_mv _mv);

void oc_loop_filter_init_c(signed char _bv[256],int _flimit);
void oc_state_loop_filter(oc_theora_state *_state,int _frame);
# if defined(OC_DUMP_IMAGES)
int oc_state_dump_frame(const oc_theora_state *_state,int _frame,
 const char *_suf);
# endif

/*Default pure-C implementations of shared accelerated functions.*/
void oc_frag_copy_c(unsigned char *_dst,
 const unsigned char *_src,int _src_ystride);
void oc_frag_copy_list_c(unsigned char *_dst_frame,
 const unsigned char *_src_frame,int _ystride,
 const ptrdiff_t *_fragis,ptrdiff_t _nfragis,const ptrdiff_t *_frag_buf_offs);
void oc_frag_recon_intra_c(unsigned char *_dst,int _dst_ystride,
 const ogg_int16_t _residue[64]);
void oc_frag_recon_inter_c(unsigned char *_dst,
 const unsigned char *_src,int _ystride,const ogg_int16_t _residue[64]);
void oc_frag_recon_inter2_c(unsigned char *_dst,const unsigned char *_src1,
 const unsigned char *_src2,int _ystride,const ogg_int16_t _residue[64]);
void oc_idct8x8_c(ogg_int16_t _y[64],ogg_int16_t _x[64],int _last_zzi);
void oc_state_frag_recon_c(const oc_theora_state *_state,ptrdiff_t _fragi,
 int _pli,ogg_int16_t _dct_coeffs[128],int _last_zzi,ogg_uint16_t _dc_quant);
void oc_state_loop_filter_frag_rows_c(const oc_theora_state *_state,
 signed char _bv[256],int _refi,int _pli,int _fragy0,int _fragy_end);
void oc_restore_fpu_c(void);

/*We need a way to call a few encoder functions without introducing a link-time
   dependency into the decoder, while still allowing the old alpha API which
   does not distinguish between encoder and decoder objects to be used.
  We do this by placing a function table at the start of the encoder object
   which can dispatch into the encoder library.
  We do a similar thing for the decoder in case we ever decide to split off a
   common base library.*/
oc_state_clear_func;
oc_state_control_func;
oc_state_granule_frame_func;
oc_state_granule_time_func;


struct oc_state_dispatch_vtable{};

#endif