200
213
/** convert unsigned values into signed ones (the sign is in the LSB) */
201
214
#define IVI_TOSIGNED(val) (-(((val) >> 1) ^ -((val) & 1)))
203
/** scales motion vector */
216
/** scale motion vector */
204
217
static inline int ivi_scale_mv(int mv, int mv_scale)
206
219
return (mv + (mv > 0) + (mv_scale - 1)) >> mv_scale;
210
* Generates a huffman codebook from the given descriptor
211
* and converts it into the FFmpeg VLC table.
223
* Generate a huffman codebook from the given descriptor
224
* and convert it into the Libav VLC table.
213
* @param cb [in] pointer to codebook descriptor
214
* @param vlc [out] where to place the generated VLC table
215
* @param flag [in] flag: 1 - for static or 0 for dynamic tables
226
* @param[in] cb pointer to codebook descriptor
227
* @param[out] vlc where to place the generated VLC table
228
* @param[in] flag flag: 1 - for static or 0 for dynamic tables
216
229
* @return result code: 0 - OK, -1 = error (invalid codebook descriptor)
218
231
int ff_ivi_create_huff_from_desc(const IVIHuffDesc *cb, VLC *vlc, int flag);
221
* Initializes static codes used for macroblock and block decoding.
234
* Initialize static codes used for macroblock and block decoding.
223
236
void ff_ivi_init_static_vlc(void);
226
* Decodes a huffman codebook descriptor from the bitstream
227
* and selects specified huffman table.
239
* Decode a huffman codebook descriptor from the bitstream
240
* and select specified huffman table.
229
* @param gb [in,out] the GetBit context
230
* @param desc_coded [in] flag signalling if table descriptor was coded
231
* @param which_tab [in] codebook purpose (IVI_MB_HUFF or IVI_BLK_HUFF)
232
* @param huff_tab [out] pointer to the descriptor of the selected table
233
* @param avctx [in] AVCodecContext pointer
242
* @param[in,out] gb the GetBit context
243
* @param[in] desc_coded flag signalling if table descriptor was coded
244
* @param[in] which_tab codebook purpose (IVI_MB_HUFF or IVI_BLK_HUFF)
245
* @param[out] huff_tab pointer to the descriptor of the selected table
246
* @param[in] avctx AVCodecContext pointer
234
247
* @return zero on success, negative value otherwise
236
249
int ff_ivi_dec_huff_desc(GetBitContext *gb, int desc_coded, int which_tab,
237
250
IVIHuffTab *huff_tab, AVCodecContext *avctx);
240
* Compares two huffman codebook descriptors.
253
* Compare two huffman codebook descriptors.
242
* @param desc1 [in] ptr to the 1st descriptor to compare
243
* @param desc2 [in] ptr to the 2nd descriptor to compare
255
* @param[in] desc1 ptr to the 1st descriptor to compare
256
* @param[in] desc2 ptr to the 2nd descriptor to compare
244
257
* @return comparison result: 0 - equal, 1 - not equal
246
259
int ff_ivi_huff_desc_cmp(const IVIHuffDesc *desc1, const IVIHuffDesc *desc2);
249
* Copies huffman codebook descriptors.
262
* Copy huffman codebook descriptors.
251
* @param dst [out] ptr to the destination descriptor
252
* @param src [in] ptr to the source descriptor
264
* @param[out] dst ptr to the destination descriptor
265
* @param[in] src ptr to the source descriptor
254
267
void ff_ivi_huff_desc_copy(IVIHuffDesc *dst, const IVIHuffDesc *src);
257
* Initializes planes (prepares descriptors, allocates buffers etc).
270
* Initialize planes (prepares descriptors, allocates buffers etc).
259
* @param planes [in,out] pointer to the array of the plane descriptors
260
* @param cfg [in] pointer to the ivi_pic_config structure describing picture layout
272
* @param[in,out] planes pointer to the array of the plane descriptors
273
* @param[in] cfg pointer to the ivi_pic_config structure describing picture layout
261
274
* @return result code: 0 - OK
263
276
int ff_ivi_init_planes(IVIPlaneDesc *planes, const IVIPicConfig *cfg);
266
* Frees planes, bands and macroblocks buffers.
279
* Free planes, bands and macroblocks buffers.
268
* @param planes [in] pointer to the array of the plane descriptors
281
* @param[in] planes pointer to the array of the plane descriptors
270
283
void ff_ivi_free_buffers(IVIPlaneDesc *planes);
273
* Initializes tile and macroblock descriptors.
286
* Initialize tile and macroblock descriptors.
275
* @param planes [in,out] pointer to the array of the plane descriptors
276
* @param tile_width [in] tile width
277
* @param tile_height [in] tile height
288
* @param[in,out] planes pointer to the array of the plane descriptors
289
* @param[in] tile_width tile width
290
* @param[in] tile_height tile height
278
291
* @return result code: 0 - OK
280
293
int ff_ivi_init_tiles(IVIPlaneDesc *planes, int tile_width, int tile_height);
283
* Decodes size of the tile data.
296
* Decode size of the tile data.
284
297
* The size is stored as a variable-length field having the following format:
285
298
* if (tile_data_size < 255) than this field is only one byte long
286
299
* if (tile_data_size >= 255) than this field four is byte long: 0xFF X1 X2 X3
287
300
* where X1-X3 is size of the tile data
289
* @param gb [in,out] the GetBit context
302
* @param[in,out] gb the GetBit context
290
303
* @return size of the tile data in bytes
292
305
int ff_ivi_dec_tile_data_size(GetBitContext *gb);
295
* Decodes block data:
296
* extracts huffman-coded transform coefficients from the bitstream,
297
* dequantizes them, applies inverse transform and motion compensation
309
* extract huffman-coded transform coefficients from the bitstream,
310
* dequantize them, apply inverse transform and motion compensation
298
311
* in order to reconstruct the picture.
300
* @param gb [in,out] the GetBit context
301
* @param band [in] pointer to the band descriptor
302
* @param tile [in] pointer to the tile descriptor
313
* @param[in,out] gb the GetBit context
314
* @param[in] band pointer to the band descriptor
315
* @param[in] tile pointer to the tile descriptor
303
316
* @return result code: 0 - OK, -1 = error (corrupted blocks data)
305
318
int ff_ivi_decode_blocks(GetBitContext *gb, IVIBandDesc *band, IVITile *tile);
308
* Handles empty tiles by performing data copying and motion
321
* Handle empty tiles by performing data copying and motion
309
322
* compensation respectively.
311
* @param avctx [in] ptr to the AVCodecContext
312
* @param band [in] pointer to the band descriptor
313
* @param tile [in] pointer to the tile descriptor
314
* @param mv_scale [in] scaling factor for motion vectors
324
* @param[in] avctx ptr to the AVCodecContext
325
* @param[in] band pointer to the band descriptor
326
* @param[in] tile pointer to the tile descriptor
327
* @param[in] mv_scale scaling factor for motion vectors
316
329
void ff_ivi_process_empty_tile(AVCodecContext *avctx, IVIBandDesc *band,
317
330
IVITile *tile, int32_t mv_scale);
320
* Converts and outputs the current plane.
333
* Convert and output the current plane.
321
334
* This conversion is done by adding back the bias value of 128
322
335
* (subtracted in the encoder) and clipping the result.
324
* @param plane [in] pointer to the descriptor of the plane being processed
325
* @param dst [out] pointer to the buffer receiving converted pixels
326
* @param dst_pitch [in] pitch for moving to the next y line
337
* @param[in] plane pointer to the descriptor of the plane being processed
338
* @param[out] dst pointer to the buffer receiving converted pixels
339
* @param[in] dst_pitch pitch for moving to the next y line
328
341
void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch);
332
* Calculates band checksum from band data.
345
* Calculate band checksum from band data.
334
347
uint16_t ivi_calc_band_checksum (IVIBandDesc *band);
337
* Verifies that band data lies in range.
350
* Verify that band data lies in range.
339
352
int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch);