Libav 0.7.1
|
00001 /* 00002 * common functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) 00003 * 00004 * Copyright (c) 2009 Maxim Poliakovski 00005 * 00006 * This file is part of Libav. 00007 * 00008 * Libav is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * Libav is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Libav; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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_VLC_BITS 13 ///< max number of bits of the ivi's huffman codes 00037 00041 typedef struct { 00042 int32_t num_rows; 00043 uint8_t xbits[16]; 00044 } IVIHuffDesc; 00045 00049 typedef struct { 00050 int32_t tab_sel; 00051 00052 VLC *tab; 00053 00055 IVIHuffDesc cust_desc; 00056 VLC cust_tab; 00057 } IVIHuffTab; 00058 00059 enum { 00060 IVI_MB_HUFF = 0, 00061 IVI_BLK_HUFF = 1 00062 }; 00063 00064 extern VLC ff_ivi_mb_vlc_tabs [8]; 00065 extern VLC ff_ivi_blk_vlc_tabs[8]; 00066 00067 00071 extern const uint8_t ff_ivi_vertical_scan_8x8[64]; 00072 extern const uint8_t ff_ivi_horizontal_scan_8x8[64]; 00073 extern const uint8_t ff_ivi_direct_scan_4x4[16]; 00074 00075 00079 typedef void (InvTransformPtr)(const int32_t *in, int16_t *out, uint32_t pitch, const uint8_t *flags); 00080 typedef void (DCTransformPtr) (const int32_t *in, int16_t *out, uint32_t pitch, int blk_size); 00081 00082 00086 typedef struct { 00087 uint8_t eob_sym; 00088 uint8_t esc_sym; 00089 uint8_t runtab[256]; 00090 int8_t valtab[256]; 00091 } RVMapDesc; 00092 00093 extern const RVMapDesc ff_ivi_rvmap_tabs[9]; 00094 00095 00099 typedef struct { 00100 int16_t xpos; 00101 int16_t ypos; 00102 uint32_t buf_offs; 00103 uint8_t type; 00104 uint8_t cbp; 00105 int8_t q_delta; 00106 int8_t mv_x; 00107 int8_t mv_y; 00108 } IVIMbInfo; 00109 00110 00114 typedef struct { 00115 int xpos; 00116 int ypos; 00117 int width; 00118 int height; 00119 int is_empty; 00120 int data_size; 00121 int num_MBs; 00122 IVIMbInfo *mbs; 00123 IVIMbInfo *ref_mbs; 00124 } IVITile; 00125 00126 00130 typedef struct { 00131 int plane; 00132 int band_num; 00133 int width; 00134 int height; 00135 const uint8_t *data_ptr; 00136 int data_size; 00137 int16_t *buf; 00138 int16_t *ref_buf; 00139 int16_t *bufs[3]; 00140 int pitch; 00141 int is_empty; 00142 int mb_size; 00143 int blk_size; 00144 int is_halfpel; 00145 int inherit_mv; 00146 int inherit_qdelta; 00147 int qdelta_present; 00148 int quant_mat; 00149 int glob_quant; 00150 const uint8_t *scan; 00151 00152 IVIHuffTab blk_vlc; 00153 00154 int num_corr; 00155 uint8_t corr[61*2]; 00156 int rvmap_sel; 00157 RVMapDesc *rv_map; 00158 int num_tiles; 00159 IVITile *tiles; 00160 InvTransformPtr *inv_transform; 00161 DCTransformPtr *dc_transform; 00162 int is_2d_trans; 00163 int32_t checksum; 00164 int checksum_present; 00165 int bufsize; 00166 const uint16_t *intra_base; 00167 const uint16_t *inter_base; 00168 const uint8_t *intra_scale; 00169 const uint8_t *inter_scale; 00170 } IVIBandDesc; 00171 00172 00176 typedef struct { 00177 uint16_t width; 00178 uint16_t height; 00179 uint8_t num_bands; 00180 IVIBandDesc *bands; 00181 } IVIPlaneDesc; 00182 00183 00184 typedef struct { 00185 uint16_t pic_width; 00186 uint16_t pic_height; 00187 uint16_t chroma_width; 00188 uint16_t chroma_height; 00189 uint16_t tile_width; 00190 uint16_t tile_height; 00191 uint8_t luma_bands; 00192 uint8_t chroma_bands; 00193 } IVIPicConfig; 00194 00196 static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2) 00197 { 00198 return (str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height || 00199 str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height || 00200 str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height || 00201 str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands); 00202 } 00203 00205 #define IVI_NUM_TILES(stride, tile_size) (((stride) + (tile_size) - 1) / (tile_size)) 00206 00208 #define IVI_MBs_PER_TILE(tile_width, tile_height, mb_size) \ 00209 ((((tile_width) + (mb_size) - 1) / (mb_size)) * (((tile_height) + (mb_size) - 1) / (mb_size))) 00210 00212 #define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1))) 00213 00215 static inline int ivi_scale_mv(int mv, int mv_scale) 00216 { 00217 return (mv + (mv > 0) + (mv_scale - 1)) >> mv_scale; 00218 } 00219 00229 int ff_ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag); 00230 00234 void ff_ivi_init_static_vlc(void); 00235 00247 int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab, 00248 IVIHuffTab *huff_tab, AVCodecContext *avctx); 00249 00257 int ff_ivi_huff_desc_cmp(const IVIHuffDesc *desc1, const IVIHuffDesc *desc2); 00258 00265 void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src); 00266 00274 int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg); 00275 00281 void ff_ivi_free_buffers(IVIPlaneDesc *planes); 00282 00291 int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height); 00292 00303 int ff_ivi_dec_tile_data_size(GetBitContext *gb); 00304 00316 int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile); 00317 00327 int ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band, 00328 IVITile *tile, int32_t mv_scale); 00329 00339 void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch); 00340 00344 uint16_t ivi_calc_band_checksum (IVIBandDesc *band); 00345 00349 int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch); 00350 00351 #endif /* AVCODEC_IVI_COMMON_H */