00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00029 #ifndef AVCODEC_IVI_COMMON_H
00030 #define AVCODEC_IVI_COMMON_H
00031
00032 #include "avcodec.h"
00033 #include "get_bits.h"
00034 #include <stdint.h>
00035
00036 #define IVI_DEBUG 0
00037
00038 #define IVI_VLC_BITS 13
00039
00040
00043 typedef struct {
00044 int32_t num_rows;
00045 uint8_t xbits[16];
00046 } IVIHuffDesc;
00047
00051 typedef struct {
00052 int32_t tab_sel;
00053
00054 VLC *tab;
00055
00057 IVIHuffDesc cust_desc;
00058 VLC cust_tab;
00059 } IVIHuffTab;
00060
00061 enum {
00062 IVI_MB_HUFF = 0,
00063 IVI_BLK_HUFF = 1
00064 };
00065
00066 extern VLC ff_ivi_mb_vlc_tabs [8];
00067 extern VLC ff_ivi_blk_vlc_tabs[8];
00068
00069
00073 extern const uint8_t ff_ivi_vertical_scan_8x8[64];
00074 extern const uint8_t ff_ivi_horizontal_scan_8x8[64];
00075 extern const uint8_t ff_ivi_direct_scan_4x4[16];
00076
00077
00081 typedef void (InvTransformPtr)(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags);
00082 typedef void (DCTransformPtr) (const int32_t *in, int16_t *out, uint32_t pitch, int blk_size);
00083
00084
00088 typedef struct {
00089 uint8_t eob_sym;
00090 uint8_t esc_sym;
00091 uint8_t runtab[256];
00092 int8_t valtab[256];
00093 } RVMapDesc;
00094
00095 extern const RVMapDesc ff_ivi_rvmap_tabs[9];
00096
00097
00101 typedef struct {
00102 int16_t xpos;
00103 int16_t ypos;
00104 uint32_t buf_offs;
00105 uint8_t type;
00106 uint8_t cbp;
00107 int8_t q_delta;
00108 int8_t mv_x;
00109 int8_t mv_y;
00110 } IVIMbInfo;
00111
00112
00116 typedef struct {
00117 int xpos;
00118 int ypos;
00119 int width;
00120 int height;
00121 int is_empty;
00122 int data_size;
00123 int num_MBs;
00124 IVIMbInfo *mbs;
00125 IVIMbInfo *ref_mbs;
00126 } IVITile;
00127
00128
00132 typedef struct {
00133 int plane;
00134 int band_num;
00135 int width;
00136 int height;
00137 const uint8_t *data_ptr;
00138 int data_size;
00139 int16_t *buf;
00140 int16_t *ref_buf;
00141 int16_t *bufs[3];
00142 int pitch;
00143 int is_empty;
00144 int mb_size;
00145 int blk_size;
00146 int is_halfpel;
00147 int inherit_mv;
00148 int inherit_qdelta;
00149 int qdelta_present;
00150 int quant_mat;
00151 int glob_quant;
00152 const uint8_t *scan;
00153
00154 IVIHuffTab blk_vlc;
00155
00156 int num_corr;
00157 uint8_t corr[61*2];
00158 int rvmap_sel;
00159 RVMapDesc *rv_map;
00160 int num_tiles;
00161 IVITile *tiles;
00162 InvTransformPtr *inv_transform;
00163 DCTransformPtr *dc_transform;
00164 int is_2d_trans;
00165 int32_t checksum;
00166 int checksum_present;
00167 int bufsize;
00168 const uint16_t *intra_base;
00169 const uint16_t *inter_base;
00170 const uint8_t *intra_scale;
00171 const uint8_t *inter_scale;
00172 } IVIBandDesc;
00173
00174
00178 typedef struct {
00179 uint16_t width;
00180 uint16_t height;
00181 uint8_t num_bands;
00182 IVIBandDesc *bands;
00183 } IVIPlaneDesc;
00184
00185
00186 typedef struct {
00187 uint16_t pic_width;
00188 uint16_t pic_height;
00189 uint16_t chroma_width;
00190 uint16_t chroma_height;
00191 uint16_t tile_width;
00192 uint16_t tile_height;
00193 uint8_t luma_bands;
00194 uint8_t chroma_bands;
00195 } IVIPicConfig;
00196
00198 static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2)
00199 {
00200 return (str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height ||
00201 str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height ||
00202 str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height ||
00203 str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands);
00204 }
00205
00207 #define IVI_NUM_TILES(stride, tile_size) (((stride) + (tile_size) - 1) / (tile_size))
00208
00210 #define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size) \
00211 ((((tile_width) + (mb_size) - 1) / (mb_size)) * (((tile_height) + (mb_size) - 1) / (mb_size)))
00212
00214 #define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1)))
00215
00217 static inline int ivi_scale_mv(int mv, int mv_scale)
00218 {
00219 return (mv + (mv > 0) + (mv_scale - 1)) >> mv_scale;
00220 }
00221
00231 int ff_ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag);
00232
00236 void ff_ivi_init_static_vlc(void);
00237
00249 int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
00250 IVIHuffTab *huff_tab, AVCodecContext *avctx);
00251
00259 int ff_ivi_huff_desc_cmp(const IVIHuffDesc *desc1, const IVIHuffDesc *desc2);
00260
00267 void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src);
00268
00276 int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg);
00277
00283 void ff_ivi_free_buffers(IVIPlaneDesc *planes);
00284
00293 int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height);
00294
00305 int ff_ivi_dec_tile_data_size(GetBitContext *gb);
00306
00318 int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile);
00319
00329 void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band,
00330 IVITile *tile, int32_t mv_scale);
00331
00341 void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch);
00342
00343 #if IVI_DEBUG
00344
00347 uint16_t ivi_calc_band_checksum (IVIBandDesc *band);
00348
00352 int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch);
00353 #endif
00354
00355 #endif